| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283 |
- /**
- * Copyright (c) 2006-2020, JGraph Ltd
- * Copyright (c) 2006-2020, draw.io AG
- */
- var StorageDialog = function(editorUi, fn, rowLimit)
- {
- rowLimit = (rowLimit != null) ? rowLimit : 2;
-
- var div = document.createElement('div');
- div.style.textAlign = 'center';
- div.style.whiteSpace = 'nowrap';
- div.style.paddingTop = '0px';
- div.style.paddingBottom = '20px';
-
- var buttons = document.createElement('div');
- buttons.style.border = '1px solid #d3d3d3';
- buttons.style.borderWidth = '1px 0px 1px 0px';
- buttons.style.padding = '10px 0px 20px 0px';
-
- var count = 0, totalBtns = 0;
- var container = document.createElement('div');
- container.style.paddingTop = '2px';
- buttons.appendChild(container);
-
- var p3 = document.createElement('p');
-
- function addLogo(img, title, mode, clientName, labels, clientFn)
- {
- totalBtns++;
-
- if (++count > rowLimit)
- {
- mxUtils.br(container);
- count = 1;
- }
-
- var button = document.createElement('a');
- button.style.overflow = 'hidden';
- button.style.display = 'inline-block';
- button.className = 'geBaseButton';
- button.style.boxSizing = 'border-box';
- button.style.fontSize = '11px';
- button.style.position = 'relative';
- button.style.margin = '4px';
- button.style.marginTop = '8px';
- button.style.marginBottom = '0px';
- button.style.padding = '8px 10px 8px 10px';
- button.style.width = '88px';
- button.style.height = '100px';
- button.style.whiteSpace = 'nowrap';
- button.setAttribute('title', title);
-
- var label = document.createElement('div');
- label.style.textOverflow = 'ellipsis';
- label.style.overflow = 'hidden';
- label.style.position = 'absolute';
- label.style.bottom = '8px';
- label.style.left = '0px';
- label.style.right = '0px';
- mxUtils.write(label, title);
- button.appendChild(label);
-
- if (img != null)
- {
- var logo = document.createElement('img');
- logo.setAttribute('src', img);
- logo.setAttribute('border', '0');
- logo.setAttribute('align', 'absmiddle');
- logo.style.width = '60px';
- logo.style.height = '60px';
- logo.style.paddingBottom = '6px';
- button.appendChild(logo);
- }
- else
- {
- label.style.paddingTop = '5px';
- label.style.whiteSpace = 'normal';
-
- // Handles special case
- if (mxClient.IS_IOS)
- {
- button.style.padding = '0px 10px 20px 10px';
- button.style.top = '6px';
- }
- else if (mxClient.IS_FF)
- {
- label.style.paddingTop = '0px';
- label.style.marginTop = '-2px';
- }
- }
-
- if (labels != null)
- {
- for (var i = 0; i < labels.length; i++)
- {
- mxUtils.br(label);
- mxUtils.write(label, labels[i]);
- }
- }
-
- function initButton()
- {
- mxEvent.addListener(button, 'click', (clientFn != null) ? clientFn : function()
- {
- if (mode == App.MODE_GOOGLE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
- {
- // Tries immediate authentication
- editorUi.drive.checkToken(mxUtils.bind(this, function()
- {
- editorUi.spinner.stop();
- editorUi.setMode(mode, true);
- fn();
- }));
- }
- else if (mode == App.MODE_ONEDRIVE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
- {
- // Tries immediate authentication
- editorUi.oneDrive.checkToken(mxUtils.bind(this, function()
- {
- editorUi.spinner.stop();
- editorUi.setMode(mode, true);
- fn();
- }), function(err)
- {
- editorUi.spinner.stop();
- editorUi.handleError(err);
- });
- }
- else
- {
- editorUi.setMode(mode, true);
- fn();
- }
- });
- };
-
- // Supports lazy loading
- if (clientName != null && editorUi[clientName] == null)
- {
- logo.style.visibility = 'hidden';
- mxUtils.setOpacity(label, 10);
- var size = 12;
-
- var spinner = new Spinner({
- lines: 12, // The number of lines to draw
- length: size, // The length of each line
- width: 5, // The line thickness
- radius: 10, // The radius of the inner circle
- rotate: 0, // The rotation offset
- color: Editor.isDarkMode() ? '#c0c0c0' : '#000', // #rgb or #rrggbb
- speed: 1.5, // Rounds per second
- trail: 60, // Afterglow percentage
- shadow: false, // Whether to render a shadow
- hwaccel: false, // Whether to use hardware acceleration
- top: '40%',
- zIndex: 2e9 // The z-index (defaults to 2000000000)
- });
- spinner.spin(button);
-
- // Timeout after 30 secs
- var timeout = window.setTimeout(function()
- {
- if (editorUi[clientName] == null)
- {
- spinner.stop();
- button.style.display = 'none';
- }
- }, 30000);
-
- editorUi.addListener('clientLoaded', mxUtils.bind(this, function(sender, evt)
- {
- if (editorUi[clientName] != null && evt.getProperty('client') == editorUi[clientName])
- {
- window.clearTimeout(timeout);
- mxUtils.setOpacity(label, 100);
- logo.style.visibility = '';
- spinner.stop();
- initButton();
-
- if (clientName == 'drive' && p3.parentNode != null)
- {
- p3.parentNode.removeChild(p3);
- }
- }
- }));
- }
- else
- {
- initButton();
- }
- container.appendChild(button);
- };
- var hd = document.createElement('p');
- hd.style.cssText = 'font-size:22px;padding:4px 0 16px 0;margin:0;color:gray;';
- mxUtils.write(hd, mxResources.get('saveDiagramsTo') + ':');
- div.appendChild(hd);
-
- var addButtons = function()
- {
- count = 0;
-
- if (typeof window.DriveClient === 'function')
- {
- addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
- }
-
- if (typeof window.OneDriveClient === 'function')
- {
- addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
- }
-
- if (urlParams['noDevice'] != '1')
- {
- addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
- }
-
- if (isLocalStorage && (urlParams['browser'] == '1' || urlParams['offline'] == '1'))
- {
- addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
- }
-
- if (typeof window.DropboxClient === 'function')
- {
- addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
- }
- if (editorUi.gitHub != null)
- {
- addLogo(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), App.MODE_GITHUB, 'gitHub');
- }
-
- if (editorUi.gitLab != null)
- {
- addLogo(IMAGE_PATH + '/gitlab-logo.svg', mxResources.get('gitlab'), App.MODE_GITLAB, 'gitLab');
- }
- };
-
- div.appendChild(buttons);
- addButtons();
- var later = document.createElement('span');
- later.style.position = 'absolute';
- later.style.cursor = 'pointer';
- later.style.bottom = '27px';
- later.style.color = 'gray';
- later.style.userSelect = 'none';
- later.style.textAlign = 'center';
- later.style.left = '50%';
- mxUtils.setPrefixedStyle(later.style, 'transform', 'translate(-50%,0)');
- mxUtils.write(later, mxResources.get('decideLater'));
- div.appendChild(later);
- mxEvent.addListener(later, 'click', function()
- {
- editorUi.hideDialog();
- var prev = Editor.useLocalStorage;
- editorUi.createFile(editorUi.defaultFilename,
- null, null, null, null, null, null, true);
- Editor.useLocalStorage = prev;
- });
-
- // Checks if Google Drive is missing after a 5 sec delay
- if (mxClient.IS_SVG && isLocalStorage && urlParams['gapi'] != '0' &&
- (document.documentMode == null || document.documentMode >= 10))
- {
- window.setTimeout(function()
- {
- if (editorUi.drive == null)
- {
- // To check for Disconnect plugin in chrome use mxClient.IS_GC and check for URL:
- // chrome-extension://jeoacafpbcihiomhlakheieifhpjdfeo/scripts/vendor/jquery/jquery-2.0.3.min.map
- p3.style.padding = '7px';
- p3.style.fontSize = '9pt';
- p3.style.marginTop = '-14px';
- p3.innerHTML = '<a style="background-color:#dcdcdc;padding:6px;color:black;text-decoration:none;" ' +
- 'href="https://www.drawio.com/doc/faq/google-drive-connection-problems" target="_blank">' +
- '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="absmiddle" ' +
- 'style="margin-top:-4px"> ' + mxResources.get('googleDriveMissingClickHere') + '</a>';
- div.appendChild(p3);
- }
- }, 5000);
- }
-
- this.container = div;
- };
- /**
- * Constructs a dialog for creating new files from templates.
- */
- var SplashDialog = function(editorUi)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'center';
-
- if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
- {
- var elt = editorUi.addLanguageMenu(div, false, '28px');
-
- if (elt != null)
- {
- elt.style.bottom = '24px';
- }
- }
-
- var logo = document.createElement('img');
- logo.setAttribute('border', '0');
- logo.setAttribute('align', 'absmiddle');
- logo.style.width = '32px';
- logo.style.height = '32px';
- logo.style.marginRight = '8px';
- logo.style.marginTop = '-4px';
-
- var buttons = document.createElement('div');
- buttons.style.margin = '8px 0px 0px 0px';
- buttons.style.padding = '18px 0px 24px 0px';
-
- var service = '';
-
- if (editorUi.mode == App.MODE_GOOGLE)
- {
- logo.src = IMAGE_PATH + '/google-drive-logo.svg';
- service = mxResources.get('googleDrive');
- }
- else if (editorUi.mode == App.MODE_DROPBOX)
- {
- logo.src = IMAGE_PATH + '/dropbox-logo.svg';
- service = mxResources.get('dropbox');
- }
- else if (editorUi.mode == App.MODE_ONEDRIVE)
- {
- logo.src = IMAGE_PATH + '/onedrive-logo.svg';
- service = mxResources.get('oneDrive');
- }
- else if (editorUi.mode == App.MODE_GITHUB)
- {
- logo.src = IMAGE_PATH + '/github-logo.svg';
- service = mxResources.get('github');
- }
- else if (editorUi.mode == App.MODE_GITLAB)
- {
- logo.src = IMAGE_PATH + '/gitlab-logo.svg';
- service = mxResources.get('gitlab');
- }
- else if (editorUi.mode == App.MODE_BROWSER)
- {
- logo.src = IMAGE_PATH + '/osa_database.png';
- service = mxResources.get('browser');
- }
- else if (editorUi.mode == App.MODE_TRELLO)
- {
- logo.src = IMAGE_PATH + '/trello-logo.svg';
- service = mxResources.get('trello');
- }
- else
- {
- logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
- buttons.style.paddingBottom = '10px';
- buttons.style.paddingTop = '30px';
- service = mxResources.get('device');
- }
- var btn = document.createElement('button');
- btn.className = 'geBigButton';
- btn.style.marginBottom = '8px';
- btn.style.fontSize = '18px';
- btn.style.padding = '10px';
- btn.style.width = '340px';
-
- if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
- {
- buttons.style.border = '1px solid #d3d3d3';
- buttons.style.borderWidth = '1px 0px 1px 0px';
-
- var table = document.createElement('table');
- var tbody = document.createElement('tbody');
- var row = document.createElement('tr');
- var left = document.createElement('td');
- var right = document.createElement('td');
- table.setAttribute('align', 'center');
- left.appendChild(logo);
-
- var title = document.createElement('div');
- title.style.fontSize = '22px';
- title.style.paddingBottom = '6px';
- title.style.color = 'gray';
- mxUtils.write(title, service);
-
- right.style.textAlign = 'left';
- right.appendChild(title);
-
- row.appendChild(left);
- row.appendChild(right);
- tbody.appendChild(row);
- table.appendChild(tbody);
- div.appendChild(table);
-
- var change = document.createElement('span');
- change.style.cssText = 'position:absolute;cursor:pointer;bottom:27px;color:gray;userSelect:none;text-align:center;left:50%;';
- mxUtils.setPrefixedStyle(change.style, 'transform', 'translate(-50%,0)');
- mxUtils.write(change, mxResources.get('changeStorage'));
-
- mxEvent.addListener(change, 'click', function()
- {
- editorUi.hideDialog(false);
- editorUi.setMode(null);
- editorUi.clearMode();
- editorUi.showSplash(true);
- });
-
- div.appendChild(change);
- }
- else
- {
- buttons.style.padding = '42px 0px 10px 0px';
- btn.style.marginBottom = '12px';
- }
- mxUtils.write(btn, mxResources.get('createNewDiagram'));
-
- mxEvent.addListener(btn, 'click', function()
- {
- editorUi.hideDialog();
- editorUi.actions.get('new').funct();
- });
-
- buttons.appendChild(btn);
- mxUtils.br(buttons);
-
- var btn = document.createElement('button');
- btn.className = 'geBigButton';
- btn.style.marginBottom = '22px';
- btn.style.fontSize = '18px';
- btn.style.padding = '10px';
- btn.style.width = '340px';
-
- mxUtils.write(btn, mxResources.get('openExistingDiagram'));
-
- mxEvent.addListener(btn, 'click', function()
- {
- editorUi.actions.get('open').funct();
- });
-
- buttons.appendChild(btn);
- var storage = 'undefined';
-
- if (editorUi.mode == App.MODE_GOOGLE)
- {
- storage = mxResources.get('googleDrive');
- }
- else if (editorUi.mode == App.MODE_DROPBOX)
- {
- storage = mxResources.get('dropbox');
- }
- else if (editorUi.mode == App.MODE_ONEDRIVE)
- {
- storage = mxResources.get('oneDrive');
- }
- else if (editorUi.mode == App.MODE_GITHUB)
- {
- storage = mxResources.get('github');
- }
- else if (editorUi.mode == App.MODE_GITLAB)
- {
- storage = mxResources.get('gitlab');
- }
- else if (editorUi.mode == App.MODE_TRELLO)
- {
- storage = mxResources.get('trello');
- }
- else if (editorUi.mode == App.MODE_DEVICE)
- {
- storage = mxResources.get('device');
- }
- else if (editorUi.mode == App.MODE_BROWSER)
- {
- storage = mxResources.get('browser');
- }
-
- if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
- {
- function addLogout(logout)
- {
- btn.style.marginBottom = '24px';
-
- var link = document.createElement('a');
- link.style.display = 'inline-block';
- link.style.color = 'gray';
- link.style.cursor = 'pointer';
- link.style.marginTop = '6px';
- mxUtils.write(link, mxResources.get('signOut'));
- // Makes room after last big buttons
- btn.style.marginBottom = '16px';
- buttons.style.paddingBottom = '18px';
-
- mxEvent.addListener(link, 'click', function()
- {
- editorUi.confirm(mxResources.get('areYouSure'), function()
- {
- logout();
- });
- });
-
- buttons.appendChild(link);
- };
-
- if (editorUi.mode == App.MODE_GOOGLE && editorUi.drive != null)
- {
- var driveUsers = editorUi.drive.getUsersList();
-
- if (driveUsers.length > 0)
- {
- var title = document.createElement('span');
- title.style.marginTop = '6px';
- mxUtils.write(title, mxResources.get('changeUser') + ':');
-
- // Makes room after last big buttons
- btn.style.marginBottom = '16px';
- buttons.style.paddingBottom = '18px';
- buttons.appendChild(title);
-
- var usersSelect = document.createElement('select');
- usersSelect.style.marginLeft = '4px';
- usersSelect.style.width = '140px';
-
- for (var i = 0; i < driveUsers.length; i++)
- {
- var option = document.createElement('option');
- mxUtils.write(option, driveUsers[i].displayName);
- option.value = i;
- usersSelect.appendChild(option);
- //More info (email) about the user in a disabled option
- option = document.createElement('option');
- option.innerHTML = ' ';
- mxUtils.write(option, '<' + driveUsers[i].email + '>');
- option.setAttribute('disabled', 'disabled');
- usersSelect.appendChild(option);
- }
-
- //Add account option
- var option = document.createElement('option');
- mxUtils.write(option, mxResources.get('addAccount'));
- option.value = driveUsers.length;
- usersSelect.appendChild(option);
-
- mxEvent.addListener(usersSelect, 'change', function()
- {
- var userIndex = usersSelect.value;
- var existingAccount = driveUsers.length != userIndex;
-
- if (existingAccount)
- {
- editorUi.drive.setUser(driveUsers[userIndex]);
- }
-
- editorUi.drive.authorize(existingAccount, function()
- {
- editorUi.setMode(App.MODE_GOOGLE);
- editorUi.hideDialog();
- editorUi.showSplash();
- }, function(resp)
- {
- editorUi.handleError(resp, null, function()
- {
- editorUi.hideDialog();
- editorUi.showSplash();
- });
- }, true);
- });
-
- buttons.appendChild(usersSelect);
- }
- else
- {
- addLogout(function()
- {
- editorUi.drive.logout();
- });
- }
- }
- else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null && !editorUi.oneDrive.noLogout)
- {
- addLogout(function()
- {
- editorUi.oneDrive.logout();
- });
- }
- else if (editorUi.mode == App.MODE_GITHUB && editorUi.gitHub != null)
- {
- addLogout(function()
- {
- editorUi.gitHub.logout();
- editorUi.openLink('https://www.github.com/logout');
- });
- }
- else if (editorUi.mode == App.MODE_GITLAB && editorUi.gitLab != null)
- {
- addLogout(function()
- {
- editorUi.gitLab.logout();
- // Must use POST request to sign out of GitLab
- // see https://gitlab.com/gitlab-org/gitlab/-/issues/202291
- var form = document.createElement('form');
- form.setAttribute('method', 'post');
- form.setAttribute('action', DRAWIO_GITLAB_URL + '/users/sign_out');
- form.setAttribute('target', '_blank');
- document.body.appendChild(form);
- form.submit();
- form.parentNode.removeChild(form);
- });
- }
- else if (editorUi.mode == App.MODE_TRELLO && editorUi.trello != null)
- {
- if (editorUi.trello.isAuthorized())
- {
- addLogout(function()
- {
- editorUi.trello.logout();
- });
- }
- }
- else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
- {
- // NOTE: Dropbox has a logout option in the picker
- addLogout(function()
- {
- editorUi.dropbox.logout();
- editorUi.openLink('https://www.dropbox.com/logout');
- });
- }
- }
- div.appendChild(buttons);
- this.container = div;
- };
- /**
- * Constructs a new embed dialog
- */
- var EmbedDialog = function(editorUi, result, timeout, ignoreSize, previewFn, title, tweet, previewTitle, filename)
- {
- tweet = (tweet != null) ? tweet : 'Check out the diagram I made using @drawio';
- var div = document.createElement('div');
- var maxSize = 500000;
- var maxFbSize = 51200;
- var maxTwitterSize = 7168;
- // Checks if result is a link
- var validUrl = /^https?:\/\//.test(result) || /^mailto:\/\//.test(result);
- if (title != null)
- {
- mxUtils.write(div, title);
- }
- else
- {
- mxUtils.write(div, mxResources.get((result.length < maxSize) ?
- ((validUrl) ? 'link' : 'mainEmbedNotice') : 'preview') + ':');
- }
- mxUtils.br(div);
-
- var size = document.createElement('div');
- size.style.position = 'absolute';
- size.style.top = '30px';
- size.style.right = '30px';
- size.style.color = 'gray';
- mxUtils.write(size, editorUi.formatFileSize(result.length));
- div.appendChild(size);
-
- // Using DIV for faster rendering
- var text = document.createElement('textarea');
- text.setAttribute('autocomplete', 'off');
- text.setAttribute('autocorrect', 'off');
- text.setAttribute('autocapitalize', 'off');
- text.setAttribute('spellcheck', 'false');
- text.style.fontFamily = 'monospace';
- text.style.wordBreak = 'break-all';
- text.style.marginTop = '10px';
- text.style.resize = 'none';
- text.style.height = '150px';
- text.style.width = '440px';
- text.style.border = '1px solid gray';
- text.value = mxResources.get('updatingDocument');
- div.appendChild(text);
- mxUtils.br(div);
- this.init = function()
- {
- window.setTimeout(function()
- {
- if (result.length < maxSize)
- {
- text.value = result;
- text.focus();
-
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- text.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- }
- else
- {
- text.setAttribute('readonly', 'true');
- text.value = mxResources.get('tooLargeUseDownload');
- }
- }, 0);
- };
-
- var buttons = document.createElement('div');
- buttons.style.position = 'absolute';
- buttons.style.bottom = '36px';
- buttons.style.right = '32px';
-
- var previewBtn = null;
-
- // Loads forever in IE9
- if (EmbedDialog.showPreviewOption && !mxIsElectron &&
- (!mxClient.IS_CHROMEAPP || validUrl) && !navigator.standalone && (validUrl ||
- (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))))
- {
- previewBtn = mxUtils.button((previewTitle != null) ? previewTitle :
- mxResources.get((result.length < maxSize) ? 'preview' : 'openInNewWindow'), function()
- {
- var value = (result.length < maxSize) ? text.value : result;
-
- if (previewFn != null)
- {
- previewFn(value);
- }
- else
- {
- if (validUrl)
- {
- try
- {
- var win = editorUi.openLink(value);
-
- if (win != null && (timeout == null || timeout > 0))
- {
- window.setTimeout(mxUtils.bind(this, function()
- {
- try
- {
- if (win != null && win.location.href != null &&
- win.location.href.substring(0, 8) != value.substring(0, 8))
- {
- win.close();
- editorUi.handleError({message: mxResources.get('drawingTooLarge')});
- }
- }
- catch (e)
- {
- // ignore
- }
- }), timeout || 500);
- }
- }
- catch (e)
- {
- editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
- }
- }
- else
- {
- var wnd = window.open();
- var doc = (wnd != null) ? wnd.document : null;
-
- if (doc != null)
- {
- doc.writeln('<html><head><title>' +
- mxUtils.htmlEntities(mxResources.get('preview')) +
- '</title><meta charset="utf-8"></head><body>' +
- (result.substring(0, 7) == '<iframe' ? result :
- mxUtils.htmlEntities(result)) + '</body></html>');
- doc.close();
- }
- else
- {
- editorUi.handleError({message: mxResources.get('errorUpdatingPreview')});
- }
- }
- }
- });
-
- previewBtn.className = 'geBtn';
- buttons.appendChild(previewBtn);
- }
-
- if (!validUrl || result.length > 7500)
- {
- var downloadBtn = mxUtils.button(mxResources.get(mxIsElectron ? 'save' : 'download'), function()
- {
- editorUi.hideDialog();
- editorUi.saveData((filename != null) ? filename : 'embed.txt', 'txt', result, 'text/plain');
- });
-
- downloadBtn.className = 'geBtn';
- buttons.appendChild(downloadBtn);
- }
- // Twitter-intent does not allow more characters, must be pasted manually
- if (validUrl && (!editorUi.isOffline() || mxClient.IS_CHROMEAPP))
- {
- if (result.length < maxFbSize)
- {
- var fbBtn = mxUtils.button('', function()
- {
- try
- {
- var url = 'https://www.facebook.com/sharer.php?p[url]=' +
- encodeURIComponent(text.value);
- editorUi.openLink(url);
- }
- catch (e)
- {
- editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
- }
- });
-
- var img = document.createElement('img');
- img.setAttribute('src', Editor.facebookImage);
- img.setAttribute('width', '18');
- img.setAttribute('height', '18');
- img.setAttribute('border', '0');
-
- fbBtn.appendChild(img);
- fbBtn.setAttribute('title', mxResources.get('facebook') + ' (' +
- editorUi.formatFileSize(maxFbSize) + ' max)');
- fbBtn.style.verticalAlign = 'bottom';
- fbBtn.style.paddingTop = '4px';
- fbBtn.style.minWidth = '46px'
- fbBtn.className = 'geBtn';
- buttons.appendChild(fbBtn);
- }
-
- if (result.length < maxTwitterSize)
- {
- var tweetBtn = mxUtils.button('', function()
- {
- try
- {
- var url = 'https://twitter.com/intent/tweet?text=' +
- encodeURIComponent(tweet) + '&url=' +
- encodeURIComponent(text.value);
- editorUi.openLink(url);
- }
- catch (e)
- {
- editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
- }
- });
-
- var img = document.createElement('img');
- img.setAttribute('src', Editor.tweetImage);
- img.setAttribute('width', '18');
- img.setAttribute('height', '18');
- img.setAttribute('border', '0');
- img.style.marginBottom = '5px'
-
- tweetBtn.appendChild(img);
- tweetBtn.setAttribute('title', mxResources.get('twitter') + ' (' +
- editorUi.formatFileSize(maxTwitterSize) + ' max)');
- tweetBtn.style.verticalAlign = 'bottom';
- tweetBtn.style.paddingTop = '4px';
- tweetBtn.style.minWidth = '46px'
- tweetBtn.className = 'geBtn';
- buttons.appendChild(tweetBtn);
- }
- }
-
- if (!editorUi.isOffline() && result.length < maxSize)
- {
- var emailBtn = mxUtils.button('', function()
- {
- try
- {
- var url = 'mailto:?subject=' +
- encodeURIComponent(filename || editorUi.defaultFilename) + '&body=' +
- encodeURIComponent(text.value);
- editorUi.openLink(url);
- }
- catch (e)
- {
- editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
- }
- });
-
- var img = document.createElement('img');
- img.className = 'geAdaptiveAsset';
- img.setAttribute('src', Editor.mailImage);
- img.setAttribute('width', '18');
- img.setAttribute('height', '18');
- img.setAttribute('border', '0');
- img.style.marginBottom = '5px'
- emailBtn.appendChild(img);
- emailBtn.style.verticalAlign = 'bottom';
- emailBtn.style.paddingTop = '4px';
- emailBtn.style.minWidth = '46px'
- emailBtn.className = 'geBtn';
- buttons.appendChild(emailBtn);
- }
- var closeBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.hideDialog();
- });
- buttons.appendChild(closeBtn);
- var copyBtn = mxUtils.button(mxResources.get('copy'), function()
- {
- text.focus();
-
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- text.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
-
- document.execCommand('copy');
- editorUi.alert(mxResources.get('copiedToClipboard'));
- });
- if (result.length < maxSize)
- {
- // Does not work in Safari and shows annoying dialog for IE11-
- if (!mxClient.IS_SF && document.documentMode == null)
- {
- buttons.appendChild(copyBtn);
- copyBtn.className = 'geBtn gePrimaryBtn';
- closeBtn.className = 'geBtn';
- }
- else
- {
- closeBtn.className = 'geBtn gePrimaryBtn';
- }
- }
- else if (previewBtn != null)
- {
- buttons.appendChild(previewBtn);
- closeBtn.className = 'geBtn';
- previewBtn.className = 'geBtn gePrimaryBtn';
- }
-
- div.appendChild(buttons);
- this.container = div;
- };
- /**
- * Add embed dialog option.
- */
- EmbedDialog.showPreviewOption = true;
- /**
- * Constructs a dialog for embedding the diagram in Google Sites.
- */
- var GoogleSitesDialog = function(editorUi, publicUrl)
- {
- var div = document.createElement('div');
- var graph = editorUi.editor.graph;
- var bounds = graph.getGraphBounds();
- var scale = graph.view.scale;
- var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
- var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
- mxUtils.write(div, mxResources.get('googleGadget') + ':');
- mxUtils.br(div);
-
- var gadgetInput = document.createElement('input');
- gadgetInput.setAttribute('type', 'text');
- gadgetInput.style.marginBottom = '8px';
- gadgetInput.style.marginTop = '2px';
- gadgetInput.style.width = '410px';
- div.appendChild(gadgetInput);
- mxUtils.br(div);
-
- this.init = function()
- {
- gadgetInput.focus();
-
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- gadgetInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- };
-
- mxUtils.write(div, mxResources.get('top') + ':');
- var topInput = document.createElement('input');
- topInput.setAttribute('type', 'text');
- topInput.setAttribute('size', '4');
- topInput.style.marginRight = '16px';
- topInput.style.marginLeft = '4px';
- topInput.value = x0;
- div.appendChild(topInput);
-
- mxUtils.write(div, mxResources.get('height') + ':');
- var heightInput = document.createElement('input');
- heightInput.setAttribute('type', 'text');
- heightInput.setAttribute('size', '4');
- heightInput.style.marginLeft = '4px';
- heightInput.value = Math.ceil(bounds.height / scale);
- div.appendChild(heightInput);
- mxUtils.br(div);
-
- var hr = document.createElement('hr');
- hr.setAttribute('size', '1');
- hr.style.marginBottom = '16px';
- hr.style.marginTop = '16px';
- div.appendChild(hr);
-
- mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
- mxUtils.br(div);
-
- var urlInput = document.createElement('input');
- urlInput.setAttribute('type', 'text');
- urlInput.setAttribute('size', '28');
- urlInput.style.marginBottom = '8px';
- urlInput.style.marginTop = '2px';
- urlInput.style.width = '410px';
- urlInput.value = publicUrl || '';
- div.appendChild(urlInput);
- mxUtils.br(div);
- mxUtils.write(div, mxResources.get('borderWidth') + ':');
- var borderInput = document.createElement('input');
- borderInput.setAttribute('type', 'text');
- borderInput.setAttribute('size', '3');
- borderInput.style.marginBottom = '8px';
- borderInput.style.marginLeft = '4px';
- borderInput.value = '0';
- div.appendChild(borderInput);
- mxUtils.br(div);
- var panCheckBox = document.createElement('input');
- panCheckBox.setAttribute('type', 'checkbox');
- panCheckBox.setAttribute('checked', 'checked');
- panCheckBox.defaultChecked = true;
- panCheckBox.style.marginLeft = '16px';
- div.appendChild(panCheckBox);
- mxUtils.write(div, mxResources.get('pan') + ' ');
- var zoomCheckBox = document.createElement('input');
- zoomCheckBox.setAttribute('type', 'checkbox');
- zoomCheckBox.setAttribute('checked', 'checked');
- zoomCheckBox.defaultChecked = true;
- zoomCheckBox.style.marginLeft = '8px';
- div.appendChild(zoomCheckBox);
- mxUtils.write(div, mxResources.get('zoom') + ' ');
-
- var editCheckBox = document.createElement('input');
- editCheckBox.setAttribute('type', 'checkbox');
- editCheckBox.style.marginLeft = '8px';
- editCheckBox.setAttribute('title', window.location.href);
- div.appendChild(editCheckBox);
- mxUtils.write(div, mxResources.get('edit') + ' ');
-
- var editBlankCheckBox = document.createElement('input');
- editBlankCheckBox.setAttribute('type', 'checkbox');
- editBlankCheckBox.style.marginLeft = '8px';
- div.appendChild(editBlankCheckBox);
- mxUtils.write(div, mxResources.get('asNew') + ' ');
- mxUtils.br(div);
- var resizeCheckBox = document.createElement('input');
- resizeCheckBox.setAttribute('type', 'checkbox');
- resizeCheckBox.setAttribute('checked', 'checked');
- resizeCheckBox.defaultChecked = true;
- resizeCheckBox.style.marginLeft = '16px';
- div.appendChild(resizeCheckBox);
- mxUtils.write(div, mxResources.get('resize') + ' ');
-
- var fitCheckBox = document.createElement('input');
- fitCheckBox.setAttribute('type', 'checkbox');
- fitCheckBox.style.marginLeft = '8px';
- div.appendChild(fitCheckBox);
- mxUtils.write(div, mxResources.get('fit') + ' ');
-
- var embedCheckBox = document.createElement('input');
- embedCheckBox.setAttribute('type', 'checkbox');
- embedCheckBox.style.marginLeft = '8px';
- div.appendChild(embedCheckBox);
- mxUtils.write(div, mxResources.get('embed') + ' ');
- var node = null;
- var s = editorUi.getBasenames().join(';');
- var file = editorUi.getCurrentFile();
- function update()
- {
- var title = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
-
- if (embedCheckBox.checked && urlInput.value != '')
- {
- var encUrl = encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
- var gurl = 'https://www.draw.io/gadget.xml?type=4&diagram=' + encUrl;
-
- if (title != null)
- {
- gurl += '&title=' + encodeURIComponent(title);
- }
-
- if (s.length > 0)
- {
- gurl += '&s=' + s;
- }
-
- if (borderInput.value != '' && borderInput.value != '0')
- {
- gurl += '&border=' + borderInput.value;
- }
-
- if (heightInput.value != '')
- {
- gurl += '&height=' + heightInput.value;
- }
-
- gurl += '&pan=' + ((panCheckBox.checked) ? '1': '0');
- gurl += '&zoom=' + ((zoomCheckBox.checked) ? '1': '0');
- gurl += '&fit=' + ((fitCheckBox.checked) ? '1': '0');
- gurl += '&resize=' + ((resizeCheckBox.checked) ? '1': '0');
- gurl += '&x0=' + Number(topInput.value);
- gurl += '&y0=' + y0;
-
- if (graph.mathEnabled)
- {
- gurl += '&math=1';
- }
-
- if (editBlankCheckBox.checked)
- {
- gurl += '&edit=_blank';
- }
- else if (editCheckBox.checked)
- {
- gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities(window.location.href));
- }
-
- gadgetInput.value = gurl;
- }
- else if (file.constructor == DriveFile || file.constructor == DropboxFile)
- {
- var gurl = 'https://www.draw.io/gadget.xml?embed=0&diagram=';
-
- if (urlInput.value != '')
- {
- gurl += encodeURIComponent(mxUtils.htmlEntities(urlInput.value)) + '&type=3';
- }
- else
- {
- gurl += file.getHash().substring(1);
-
- if (file.constructor == DropboxFile)
- {
- gurl += '&type=2';
- }
- else
- {
- gurl += '&type=1';
- }
- }
-
- if (title != null)
- {
- gurl += '&title=' + encodeURIComponent(title);
- }
-
- if (heightInput.value != '')
- {
- var h = parseInt(heightInput.value) + parseInt(topInput.value);
- gurl += '&height=' + h;
- }
- gadgetInput.value = gurl;
- }
- else
- {
- gadgetInput.value = '';
- }
- };
-
- mxEvent.addListener(panCheckBox, 'change', update);
- mxEvent.addListener(zoomCheckBox, 'change', update);
- mxEvent.addListener(resizeCheckBox, 'change', update);
- mxEvent.addListener(fitCheckBox, 'change', update);
- mxEvent.addListener(editCheckBox, 'change', update);
- mxEvent.addListener(editBlankCheckBox, 'change', update);
- mxEvent.addListener(embedCheckBox, 'change', update);
- mxEvent.addListener(heightInput, 'change', update);
- mxEvent.addListener(topInput, 'change', update);
- mxEvent.addListener(borderInput, 'change', update);
- mxEvent.addListener(urlInput, 'change', update);
- update();
-
- mxEvent.addListener(gadgetInput, 'click', function()
- {
- gadgetInput.focus();
-
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- gadgetInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- });
-
- var buttons = document.createElement('div');
- buttons.style.paddingTop = '12px';
- buttons.style.textAlign = 'right';
- var closeBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.hideDialog();
- });
- closeBtn.className = 'geBtn gePrimaryBtn';
- buttons.appendChild(closeBtn);
-
- div.appendChild(buttons);
-
- this.container = div;
- };
- /**
- * Constructs a new parse dialog.
- */
- var CreateGraphDialog = function(editorUi, title, type)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'right';
-
- this.init = function()
- {
- var container = document.createElement('div');
- container.style.position = 'relative';
- container.style.border = '1px solid gray';
- container.style.boxSizing = 'border-box';
- container.style.width = '100%';
- container.style.height = '360px';
- container.style.overflow = 'hidden';
- container.style.marginBottom = '16px';
- mxEvent.disableContextMenu(container);
- div.appendChild(container);
-
- var graph = new Graph(container);
-
- graph.setCellsCloneable(true);
- graph.setPanning(true);
- graph.setAllowDanglingEdges(false);
- graph.connectionHandler.select = false;
- graph.view.setTranslate(20, 20);
- graph.border = 20;
- graph.panningHandler.useLeftButtonForPanning = true;
- // Fixes in-place editor position
- if (mxClient.IS_SVG && graph.view.getDrawPane() != null)
- {
- var root = graph.view.getDrawPane().ownerSVGElement;
-
- if (root != null)
- {
- root.style.position = 'absolute';
- }
- }
-
- var vertexStyle = 'rounded=1;';
- var edgeStyle = 'curved=1;';
- var startStyle = 'ellipse';
-
- // FIXME: Does not work in iPad
- graph.cellRenderer.installCellOverlayListeners = function(state, overlay, shape)
- {
- mxCellRenderer.prototype.installCellOverlayListeners.apply(this, arguments);
-
- mxEvent.addListener(shape.node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', function (evt)
- {
- overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
- });
-
- if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
- {
- mxEvent.addListener(shape.node, 'touchstart', function (evt)
- {
- overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
- });
- }
- };
- graph.getAllConnectionConstraints = function()
- {
- return null;
- };
- // Keeps highlight behind overlays
- graph.connectionHandler.marker.highlight.keepOnTop = false;
-
- graph.connectionHandler.createEdgeState = function(me)
- {
- var edge = graph.createEdge(null, null, null, null, null, edgeStyle);
- return new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
- };
-
- // Gets the default parent for inserting new cells. This
- // is normally the first child of the root (ie. layer 0).
- var parent = graph.getDefaultParent();
-
- var addOverlay = mxUtils.bind(this, function(cell)
- {
- // Creates a new overlay with an image and a tooltip
- var overlay = new mxCellOverlay(this.connectImage, 'Add outgoing');
- overlay.cursor = 'hand';
-
- // Installs a handler for clicks on the overlay
- overlay.addListener(mxEvent.CLICK, function(sender, evt2)
- {
- // TODO: Add menu for picking next shape
- graph.connectionHandler.reset();
- graph.clearSelection();
- var geo = graph.getCellGeometry(cell);
-
- var v2;
-
- executeLayout(function()
- {
- v2 = graph.insertVertex(parent, null, 'Entry', geo.x, geo.y, 80, 30, vertexStyle);
- addOverlay(v2);
- graph.view.refresh(v2);
- graph.insertEdge(parent, null, '', cell, v2, edgeStyle);
- }, function()
- {
- graph.scrollCellToVisible(v2);
- });
- });
-
- // FIXME: Does not work in iPad (inserts loop)
- overlay.addListener('pointerdown', function(sender, eo)
- {
- var evt2 = eo.getProperty('event');
- var state = eo.getProperty('state');
-
- graph.popupMenuHandler.hideMenu();
- graph.stopEditing(false);
-
- var pt = mxUtils.convertPoint(graph.container,
- mxEvent.getClientX(evt2), mxEvent.getClientY(evt2));
- graph.connectionHandler.start(state, pt.x, pt.y);
- graph.isMouseDown = true;
- graph.isMouseTrigger = mxEvent.isMouseEvent(evt2);
- mxEvent.consume(evt2);
- });
-
- // Sets the overlay for the cell in the graph
- graph.addCellOverlay(cell, overlay);
- });
-
- // Adds cells to the model in a single step
- graph.getModel().beginUpdate();
- var v1;
- try
- {
- v1 = graph.insertVertex(parent, null, 'Start', 0, 0, 80, 30, startStyle);
- addOverlay(v1);
- }
- finally
- {
- // Updates the display
- graph.getModel().endUpdate();
- }
-
- var layout;
-
- if (type == 'horizontalTree')
- {
- layout = new mxCompactTreeLayout(graph);
- layout.edgeRouting = false;
- layout.levelDistance = 30;
- layout.sortEdges = true;
- edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=horizontal;';
- }
- else if (type == 'verticalTree')
- {
- layout = new mxCompactTreeLayout(graph, false);
- layout.edgeRouting = false;
- layout.levelDistance = 30;
- layout.sortEdges = true;
- edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=vertical;';
- }
- else if (type == 'radialTree')
- {
- layout = new mxRadialTreeLayout(graph, false);
- layout.edgeRouting = false;
- layout.levelDistance = 80;
- }
- else if (type == 'verticalFlow')
- {
- layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_NORTH);
- }
- else if (type == 'horizontalFlow')
- {
- layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_WEST);
- }
- else if (type == 'circle')
- {
- layout = new mxCircleLayout(graph);
- }
- else
- {
- layout = new mxFastOrganicLayout(graph, false);
- layout.forceConstant = 80;
- }
-
- if (layout != null)
- {
- var executeLayout = function(change, post)
- {
- graph.getModel().beginUpdate();
- try
- {
- if (change != null)
- {
- change();
- }
-
- layout.execute(graph.getDefaultParent(), v1);
- }
- catch (e)
- {
- throw e;
- }
- finally
- {
- // New API for animating graph layout results asynchronously
- var morph = new mxMorphing(graph);
- morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
- {
- graph.getModel().endUpdate();
-
- if (post != null)
- {
- post();
- }
- }));
-
- morph.startAnimation();
- }
- };
-
- var edgeHandleConnect = mxEdgeHandler.prototype.connect;
- mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me)
- {
- edgeHandleConnect.apply(this, arguments);
- executeLayout();
- };
-
- graph.resizeCell = function()
- {
- mxGraph.prototype.resizeCell.apply(this, arguments);
-
- executeLayout();
- };
-
- graph.connectionHandler.addListener(mxEvent.CONNECT, function()
- {
- executeLayout();
- });
- }
- var cancelBtn = mxUtils.button(mxResources.get('close'), function()
- {
- editorUi.confirm(mxResources.get('areYouSure'), function()
- {
- editorUi.hideDialog();
- });
- })
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- div.appendChild(cancelBtn);
- }
-
- var okBtn = mxUtils.button(mxResources.get('insert'), function(evt)
- {
- graph.clearCellOverlays();
-
- var cells = graph.getModel().getChildren(graph.getDefaultParent());
- var pt = (mxEvent.isAltDown(evt)) ?
- editorUi.editor.graph.getFreeInsertPoint() :
- editorUi.editor.graph.getCenterInsertPoint(
- graph.getBoundingBoxFromGeometry(cells, true));
- cells = editorUi.editor.graph.importCells(cells, pt.x, pt.y);
- var view = editorUi.editor.graph.view;
- var temp = view.getBounds(cells);
- if (temp != null)
- {
- temp.x -= view.translate.x;
- temp.y -= view.translate.y;
- editorUi.editor.graph.scrollRectToVisible(temp);
- editorUi.editor.graph.setSelectionCells(cells);
- }
-
- editorUi.hideDialog();
- });
-
- div.appendChild(okBtn);
- okBtn.className = 'geBtn gePrimaryBtn';
-
- if (!editorUi.editor.cancelFirst)
- {
- div.appendChild(cancelBtn);
- }
- this.graph = graph;
- };
- this.container = div;
- };
- /**
- *
- */
- 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==' :
- IMAGE_PATH + '/handle-connect.png', 26, 26);
- /**
- * Constructs a new parse dialog.
- */
- var BackgroundImageDialog = function(editorUi, applyFn, img, color, showColor)
- {
- var graph = editorUi.editor.graph;
- var div = document.createElement('div');
- div.style.whiteSpace = 'nowrap';
- var h3 = document.createElement('h2');
- mxUtils.write(h3, mxResources.get('background'));
- h3.style.marginTop = '0px';
- div.appendChild(h3);
- var isPageLink = img != null && img.originalSrc != null;
- var pageFound = false;
- var urlRadio = document.createElement('input');
- urlRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
- urlRadio.setAttribute('value', 'url');
- urlRadio.setAttribute('type', 'radio');
- urlRadio.setAttribute('name', 'geBackgroundImageDialogOption');
- var pageRadio = document.createElement('input');
- pageRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
- pageRadio.setAttribute('value', 'url');
- pageRadio.setAttribute('type', 'radio');
- pageRadio.setAttribute('name', 'geBackgroundImageDialogOption');
- var urlInput = document.createElement('input');
- urlInput.setAttribute('type', 'text');
- urlInput.style.marginBottom = '8px';
- urlInput.style.width = '360px';
- urlInput.value = (isPageLink || img == null) ? '' : img.src;
-
- var pageSelect = document.createElement('select');
- pageSelect.style.width = '360px';
- if (editorUi.pages != null)
- {
- for (var i = 0; i < editorUi.pages.length; i++)
- {
- var pageOption = document.createElement('option');
- mxUtils.write(pageOption, editorUi.pages[i].getName() ||
- mxResources.get('pageWithNumber', [i + 1]));
- pageOption.setAttribute('value', 'data:page/id,' +
- editorUi.pages[i].getId());
- if (editorUi.pages[i] == editorUi.currentPage)
- {
- pageOption.setAttribute('disabled', 'disabled');
- }
-
- if (img != null && img.originalSrc == pageOption.getAttribute('value'))
- {
- pageOption.setAttribute('selected', 'selected');
- pageFound = true;
- }
- pageSelect.appendChild(pageOption);
- }
- }
- if (!isPageLink && (editorUi.pages == null || editorUi.pages.length == 1))
- {
- urlRadio.style.display = 'none';
- pageRadio.style.display = 'none';
- pageSelect.style.display = 'none';
- }
- var notFoundOption = document.createElement('option');
- var resetting = false;
- var ignoreEvt = false;
-
- var urlChanged = function(evt, done)
- {
- // Skips blur event if called from apply button
- if (!resetting && (evt == null || !ignoreEvt))
- {
- if (pageRadio.checked)
- {
- if (done != null)
- {
- done((notFoundOption.selected) ? null : pageSelect.value);
- }
- }
- else if (urlInput.value != '' && !editorUi.isOffline())
- {
- urlInput.value = mxUtils.trim(urlInput.value);
- editorUi.loadImage(urlInput.value, function(img)
- {
- widthInput.value = img.width;
- heightInput.value = img.height;
-
- if (done != null)
- {
- done(urlInput.value);
- }
- }, function()
- {
- editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
- widthInput.value = '';
- heightInput.value = '';
-
- if (done != null)
- {
- done(null);
- }
- });
- }
- else
- {
- widthInput.value = '';
- heightInput.value = '';
-
- if (done != null)
- {
- done('');
- }
- }
- }
- };
- var openFiles = mxUtils.bind(this, function(files)
- {
- editorUi.importFiles(files, 0, 0, editorUi.maxBackgroundSize, function(data, mimeType, x, y, w, h)
- {
- urlInput.value = data;
- urlChanged();
- urlInput.focus();
- }, function()
- {
- // No post processing
- }, function(file)
- {
- // Handles only images
- return file.type.substring(0, 6) == 'image/';
- }, function(queue)
- {
- // Invokes elements of queue in order
- for (var i = 0; i < queue.length; i++)
- {
- queue[i]();
- }
- }, true, editorUi.maxBackgroundBytes, editorUi.maxBackgroundBytes, true);
- });
- this.init = function()
- {
- if (isPageLink)
- {
- pageSelect.focus();
- }
- else
- {
- urlInput.focus();
- }
- mxEvent.addListener(pageSelect, 'focus', function()
- {
- urlRadio.removeAttribute('checked');
- pageRadio.setAttribute('checked', 'checked');
- pageRadio.checked = true;
- });
-
- mxEvent.addListener(urlInput, 'focus', function()
- {
- pageRadio.removeAttribute('checked');
- urlRadio.setAttribute('checked', 'checked');
- urlRadio.checked = true;
- });
- // Installs drag and drop handler for local images and links
- if (Graph.fileSupport)
- {
- urlInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
-
- // Setup the dnd listeners
- var dlg = div.parentNode;
- var dropElt = null;
-
- mxEvent.addListener(dlg, 'dragleave', function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- });
-
- mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
- {
- // IE 10 does not implement pointer-events so it can't have a drop highlight
- if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
- {
- dropElt = editorUi.highlightElement(dlg);
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- }));
-
- mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
- if (evt.dataTransfer.files.length > 0)
- {
- openFiles(evt.dataTransfer.files);
- }
- else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
- {
- var uri = evt.dataTransfer.getData('text/uri-list');
-
- if ((/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
- {
- urlInput.value = decodeURIComponent(uri);
- urlChanged();
- }
- }
- evt.stopPropagation();
- evt.preventDefault();
- }), false);
- }
- };
- div.appendChild(urlRadio);
- div.appendChild(urlInput);
- mxUtils.br(div);
- var span = document.createElement('span');
- span.style.marginLeft = '30px';
- mxUtils.write(span, mxResources.get('width') + ':');
- div.appendChild(span);
-
- var widthInput = document.createElement('input');
- widthInput.setAttribute('type', 'text');
- widthInput.style.width = '60px';
- widthInput.style.marginLeft = '8px';
- widthInput.style.marginRight = '16px';
- widthInput.value = (img != null && !isPageLink) ? img.width : '';
-
- div.appendChild(widthInput);
-
- mxUtils.write(div, mxResources.get('height') + ':');
-
- var heightInput = document.createElement('input');
- heightInput.setAttribute('type', 'text');
- heightInput.style.width = '60px';
- heightInput.style.marginLeft = '8px';
- heightInput.style.marginRight = '16px';
- heightInput.value = (img != null && !isPageLink) ? img.height : '';
-
- div.appendChild(heightInput);
- mxUtils.br(div);
- mxUtils.br(div);
- mxEvent.addListener(urlInput, 'change', urlChanged);
- ImageDialog.filePicked = function(data)
- {
- if (data.action == google.picker.Action.PICKED)
- {
- if (data.docs[0].thumbnails != null)
- {
- var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
-
- if (thumb != null)
- {
- urlInput.value = thumb.url;
- urlChanged();
- }
- }
- }
-
- urlInput.focus();
- };
- div.appendChild(pageRadio);
- div.appendChild(pageSelect);
- mxUtils.br(div);
- mxUtils.br(div);
- if (isPageLink)
- {
- pageRadio.setAttribute('checked', 'checked');
- pageRadio.checked = true;
- }
- else
- {
- urlRadio.setAttribute('checked', 'checked');
- urlRadio.checked = true;
- }
- if (!pageFound && pageRadio.checked)
- {
- mxUtils.write(notFoundOption, mxResources.get('pageNotFound'));
- notFoundOption.setAttribute('disabled', 'disabled');
- notFoundOption.setAttribute('selected', 'selected');
- notFoundOption.setAttribute('value', 'pageNotFound');
- pageSelect.appendChild(notFoundOption);
-
- mxEvent.addListener(pageSelect, 'change', function()
- {
- if (notFoundOption.parentNode != null && !notFoundOption.selected)
- {
- notFoundOption.parentNode.removeChild(notFoundOption);
- }
- });
- }
- var bgDiv = document.createElement('div');
- bgDiv.style.display = (showColor) ? 'inline-flex' : 'none';
- bgDiv.style.alignItems = 'center';
- bgDiv.style.cursor = 'default';
- bgDiv.style.minWidth = '40%';
- bgDiv.style.height = '20px';
- var cb = document.createElement('input');
- cb.setAttribute('type', 'checkbox');
- cb.style.margin = '0px 10px 0px 4px';
- cb.style.verticalAlign = 'bottom';
- cb.defaultChecked = color != mxConstants.NONE && color != null;
- cb.checked = cb.defaultChecked;
- bgDiv.appendChild(cb);
- mxUtils.write(bgDiv, mxResources.get('fillColor'));
- var shadowDiv = bgDiv.cloneNode(false);
- var shadow = document.createElement('input');
- shadow.setAttribute('type', 'checkbox');
- shadow.style.margin = '0px 10px 0px 30px';
- shadow.style.verticalAlign = 'bottom';
- shadow.defaultChecked = graph.shadowVisible;
- shadow.checked = shadow.defaultChecked;
- shadowDiv.appendChild(shadow);
- mxUtils.write(shadowDiv, mxResources.get('shadow'));
- if (!mxClient.IS_SVG || mxClient.IS_SF)
- {
- shadow.setAttribute('disabled', 'disabled');
- }
- mxEvent.addListener(shadowDiv, 'click', function(evt)
- {
- if (mxEvent.getSource(evt) != shadow)
- {
- shadow.checked = !shadow.checked;
- }
- });
- // TODO: Move createColorButton to editorUi
- var backgroundButton = document.createElement('button');
- backgroundButton.style.width = '36px';
- backgroundButton.style.height = '18px';
- backgroundButton.style.cursor = 'pointer';
- backgroundButton.style.marginLeft = '10px';
- backgroundButton.style.backgroundPosition = 'center center';
- backgroundButton.style.backgroundRepeat = 'no-repeat';
- backgroundButton.style.verticalAlign = 'bottom';
- backgroundButton.className = 'geColorBtn';
-
- var newBackgroundColor = color;
-
- function updateBackgroundColor()
- {
- if (newBackgroundColor == null || newBackgroundColor == mxConstants.NONE)
- {
- backgroundButton.style.display = 'none';
- cb.checked = false;
- }
- else
- {
- backgroundButton.style.backgroundColor = newBackgroundColor;
- backgroundButton.style.display = '';
- cb.checked = true;
- }
- };
-
- updateBackgroundColor();
- mxEvent.addListener(bgDiv, 'click', function(evt)
- {
- if (mxEvent.getSource(evt) != cb)
- {
- cb.checked = !cb.checked;
- }
- if (cb.checked)
- {
- newBackgroundColor = '#ffffff';
- }
- else
- {
- newBackgroundColor = null;
- }
- updateBackgroundColor();
- });
-
- mxEvent.addListener(backgroundButton, 'click', function(evt)
- {
- editorUi.pickColor(newBackgroundColor || 'none', function(color)
- {
- newBackgroundColor = color;
- updateBackgroundColor();
- });
- mxEvent.consume(evt);
- });
-
- bgDiv.appendChild(backgroundButton);
- div.appendChild(bgDiv);
- div.appendChild(shadowDiv);
- mxUtils.br(div);
- var btns = document.createElement('div');
- btns.style.marginTop = '30px';
- btns.style.textAlign = 'right';
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- resetting = true;
- editorUi.hideDialog();
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- var resetBtn = mxUtils.button(mxResources.get('reset'), function()
- {
- urlInput.value = '';
- widthInput.value = '';
- heightInput.value = '';
- urlRadio.checked = true;
- newBackgroundColor = mxConstants.NONE;
- updateBackgroundColor();
- resetting = false;
- });
- mxEvent.addGestureListeners(resetBtn, function()
- {
- // Blocks processing a image URL while clicking reset
- resetting = true;
- });
- resetBtn.className = 'geBtn';
- resetBtn.width = '100';
- btns.appendChild(resetBtn);
- if (Graph.fileSupport)
- {
- var fileInput = document.createElement('input');
- fileInput.setAttribute('multiple', 'multiple');
- fileInput.setAttribute('type', 'file');
-
- mxEvent.addListener(fileInput, 'change', function(evt)
- {
- if (fileInput.files != null)
- {
- openFiles(fileInput.files);
-
- // Resets input to force change event for same file (type reset required for IE)
- fileInput.type = '';
- fileInput.type = 'file';
- fileInput.value = '';
- }
- });
-
- fileInput.style.display = 'none';
- div.appendChild(fileInput);
-
- var btn = mxUtils.button(mxResources.get('open'), function()
- {
- fileInput.click();
- });
- btn.className = 'geBtn';
- btns.appendChild(btn);
- }
- applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- editorUi.hideDialog();
-
- urlChanged(null, function(url)
- {
- applyFn((url != '' && url != null) ? new mxImage(url, widthInput.value,
- heightInput.value) : null, url == null, newBackgroundColor,
- (!mxClient.IS_SVG || mxClient.IS_SF) ? null : shadow.checked);
- });
- });
-
- mxEvent.addGestureListeners(applyBtn, function()
- {
- ignoreEvt = true;
- });
-
- applyBtn.className = 'geBtn gePrimaryBtn';
- btns.appendChild(applyBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- div.appendChild(btns);
- this.container = div;
- };
- /**
- * Constructs a new parse dialog.
- */
- var ParseDialog = function(editorUi, title, defaultType)
- {
- var plantUmlExample = '@startuml\nskinparam shadowing false\nAlice -> Bob: Authentication Request\nBob --> Alice: Authentication Response\n\n' +
- 'Alice -> Bob: Another authentication Request\nAlice <-- Bob: Another authentication Response\n@enduml';
- var insertPoint = editorUi.editor.graph.getFreeInsertPoint();
- function parse(text, type, evt)
- {
- var lines = text.split('\n');
-
- if (type == 'plantUmlPng' || type == 'plantUmlSvg' || type == 'plantUmlTxt')
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('inserting')))
- {
- var graph = editorUi.editor.graph;
- var format = (type == 'plantUmlTxt') ? 'txt' :
- ((type == 'plantUmlPng') ? 'png' : 'svg');
-
- function insertPlantUmlImage(text, format, data, w, h)
- {
- insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint : graph.getCenterInsertPoint(new mxRectangle(0, 0, w, h));
- var cell = null;
-
- graph.getModel().beginUpdate();
- try
- {
- cell = (format == 'txt') ?
- editorUi.insertAsPreText(data, insertPoint.x, insertPoint.y) :
- graph.insertVertex(null, null, null, insertPoint.x, insertPoint.y,
- w, h, 'shape=image;noLabel=1;verticalAlign=top;aspect=fixed;imageAspect=0;' +
- 'image=' + editorUi.convertDataUri(data) + ';')
- graph.setAttributeForCell(cell, 'plantUmlData',
- JSON.stringify({data: text, format: format},
- null, 2));
- }
- finally
- {
- graph.getModel().endUpdate();
- }
-
- if (cell != null)
- {
- graph.setSelectionCell(cell);
- graph.scrollCellToVisible(cell);
- }
- };
-
- // Hardcoded response for default settings
- if (text == plantUmlExample && format == 'svg')
- {
- window.setTimeout(function()
- {
- editorUi.spinner.stop();
- insertPlantUmlImage(text, format, 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBjb250ZW50U2NyaXB0VHlwZT0iYXBwbGljYXRpb24vZWNtYXNjcmlwdCIgY29udGVudFN0eWxlVHlwZT0idGV4dC9jc3MiIGhlaWdodD0iMjEycHgiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiIHN0eWxlPSJ3aWR0aDoyOTVweDtoZWlnaHQ6MjEycHg7IiB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCAyOTUgMjEyIiB3aWR0aD0iMjk1cHgiIHpvb21BbmRQYW49Im1hZ25pZnkiPjxkZWZzLz48Zz48bGluZSBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsgc3Ryb2tlLWRhc2hhcnJheTogNS4wLDUuMDsiIHgxPSIzMSIgeDI9IjMxIiB5MT0iMzQuNDg4MyIgeTI9IjE3MS43MzA1Ii8+PGxpbmUgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjA7IHN0cm9rZS1kYXNoYXJyYXk6IDUuMCw1LjA7IiB4MT0iMjY0LjUiIHgyPSIyNjQuNSIgeTE9IjM0LjQ4ODMiIHkyPSIxNzEuNzMwNSIvPjxyZWN0IGZpbGw9IiNGRUZFQ0UiIGhlaWdodD0iMzAuNDg4MyIgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjU7IiB3aWR0aD0iNDciIHg9IjgiIHk9IjMiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNCIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIzMyIgeD0iMTUiIHk9IjIzLjUzNTIiPkFsaWNlPC90ZXh0PjxyZWN0IGZpbGw9IiNGRUZFQ0UiIGhlaWdodD0iMzAuNDg4MyIgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjU7IiB3aWR0aD0iNDciIHg9IjgiIHk9IjE3MC43MzA1Ii8+PHRleHQgZmlsbD0iIzAwMDAwMCIgZm9udC1mYW1pbHk9InNhbnMtc2VyaWYiIGZvbnQtc2l6ZT0iMTQiIGxlbmd0aEFkanVzdD0ic3BhY2luZ0FuZEdseXBocyIgdGV4dExlbmd0aD0iMzMiIHg9IjE1IiB5PSIxOTEuMjY1NiI+QWxpY2U8L3RleHQ+PHJlY3QgZmlsbD0iI0ZFRkVDRSIgaGVpZ2h0PSIzMC40ODgzIiBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuNTsiIHdpZHRoPSI0MCIgeD0iMjQ0LjUiIHk9IjMiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNCIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIyNiIgeD0iMjUxLjUiIHk9IjIzLjUzNTIiPkJvYjwvdGV4dD48cmVjdCBmaWxsPSIjRkVGRUNFIiBoZWlnaHQ9IjMwLjQ4ODMiIHN0eWxlPSJzdHJva2U6ICNBODAwMzY7IHN0cm9rZS13aWR0aDogMS41OyIgd2lkdGg9IjQwIiB4PSIyNDQuNSIgeT0iMTcwLjczMDUiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNCIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIyNiIgeD0iMjUxLjUiIHk9IjE5MS4yNjU2Ij5Cb2I8L3RleHQ+PHBvbHlnb24gZmlsbD0iI0E4MDAzNiIgcG9pbnRzPSIyNTIuNSw2MS43OTg4LDI2Mi41LDY1Ljc5ODgsMjUyLjUsNjkuNzk4OCwyNTYuNSw2NS43OTg4IiBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsiLz48bGluZSBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsiIHgxPSIzMS41IiB4Mj0iMjU4LjUiIHkxPSI2NS43OTg4IiB5Mj0iNjUuNzk4OCIvPjx0ZXh0IGZpbGw9IiMwMDAwMDAiIGZvbnQtZmFtaWx5PSJzYW5zLXNlcmlmIiBmb250LXNpemU9IjEzIiBsZW5ndGhBZGp1c3Q9InNwYWNpbmdBbmRHbHlwaHMiIHRleHRMZW5ndGg9IjE0NyIgeD0iMzguNSIgeT0iNjEuMDU2NiI+QXV0aGVudGljYXRpb24gUmVxdWVzdDwvdGV4dD48cG9seWdvbiBmaWxsPSIjQTgwMDM2IiBwb2ludHM9IjQyLjUsOTEuMTA5NCwzMi41LDk1LjEwOTQsNDIuNSw5OS4xMDk0LDM4LjUsOTUuMTA5NCIgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjA7Ii8+PGxpbmUgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjA7IHN0cm9rZS1kYXNoYXJyYXk6IDIuMCwyLjA7IiB4MT0iMzYuNSIgeDI9IjI2My41IiB5MT0iOTUuMTA5NCIgeTI9Ijk1LjEwOTQiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxMyIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIxNTciIHg9IjQ4LjUiIHk9IjkwLjM2NzIiPkF1dGhlbnRpY2F0aW9uIFJlc3BvbnNlPC90ZXh0Pjxwb2x5Z29uIGZpbGw9IiNBODAwMzYiIHBvaW50cz0iMjUyLjUsMTIwLjQxOTksMjYyLjUsMTI0LjQxOTksMjUyLjUsMTI4LjQxOTksMjU2LjUsMTI0LjQxOTkiIHN0eWxlPSJzdHJva2U6ICNBODAwMzY7IHN0cm9rZS13aWR0aDogMS4wOyIvPjxsaW5lIHN0eWxlPSJzdHJva2U6ICNBODAwMzY7IHN0cm9rZS13aWR0aDogMS4wOyIgeDE9IjMxLjUiIHgyPSIyNTguNSIgeTE9IjEyNC40MTk5IiB5Mj0iMTI0LjQxOTkiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxMyIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIxOTkiIHg9IjM4LjUiIHk9IjExOS42Nzc3Ij5Bbm90aGVyIGF1dGhlbnRpY2F0aW9uIFJlcXVlc3Q8L3RleHQ+PHBvbHlnb24gZmlsbD0iI0E4MDAzNiIgcG9pbnRzPSI0Mi41LDE0OS43MzA1LDMyLjUsMTUzLjczMDUsNDIuNSwxNTcuNzMwNSwzOC41LDE1My43MzA1IiBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsiLz48bGluZSBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsgc3Ryb2tlLWRhc2hhcnJheTogMi4wLDIuMDsiIHgxPSIzNi41IiB4Mj0iMjYzLjUiIHkxPSIxNTMuNzMwNSIgeTI9IjE1My43MzA1Ii8+PHRleHQgZmlsbD0iIzAwMDAwMCIgZm9udC1mYW1pbHk9InNhbnMtc2VyaWYiIGZvbnQtc2l6ZT0iMTMiIGxlbmd0aEFkanVzdD0ic3BhY2luZ0FuZEdseXBocyIgdGV4dExlbmd0aD0iMjA5IiB4PSI0OC41IiB5PSIxNDguOTg4MyI+QW5vdGhlciBhdXRoZW50aWNhdGlvbiBSZXNwb25zZTwvdGV4dD48IS0tTUQ1PVs3ZjNlNGQwYzkwMWVmZGJjNTdlYjQ0MjQ5YTNiODE5N10KQHN0YXJ0dW1sDQpza2lucGFyYW0gc2hhZG93aW5nIGZhbHNlDQpBbGljZSAtPiBCb2I6IEF1dGhlbnRpY2F0aW9uIFJlcXVlc3QNCkJvYiAtIC0+IEFsaWNlOiBBdXRoZW50aWNhdGlvbiBSZXNwb25zZQ0KDQpBbGljZSAtPiBCb2I6IEFub3RoZXIgYXV0aGVudGljYXRpb24gUmVxdWVzdA0KQWxpY2UgPC0gLSBCb2I6IEFub3RoZXIgYXV0aGVudGljYXRpb24gUmVzcG9uc2UNCkBlbmR1bWwNCgpQbGFudFVNTCB2ZXJzaW9uIDEuMjAyMC4wMihTdW4gTWFyIDAxIDA0OjIyOjA3IENTVCAyMDIwKQooTUlUIHNvdXJjZSBkaXN0cmlidXRpb24pCkphdmEgUnVudGltZTogT3BlbkpESyBSdW50aW1lIEVudmlyb25tZW50CkpWTTogT3BlbkpESyA2NC1CaXQgU2VydmVyIFZNCkphdmEgVmVyc2lvbjogMTIrMzMKT3BlcmF0aW5nIFN5c3RlbTogTWFjIE9TIFgKRGVmYXVsdCBFbmNvZGluZzogVVRGLTgKTGFuZ3VhZ2U6IGVuCkNvdW50cnk6IFVTCi0tPjwvZz48L3N2Zz4=',
- 295, 212);
- }, 200);
-
- }
- else
- {
- editorUi.generatePlantUmlImage(text, format, function(data, w, h)
- {
- editorUi.spinner.stop();
- insertPlantUmlImage(text, format, data, w, h);
-
- }, function(e)
- {
- editorUi.handleError(e);
- });
- }
- }
- }
- else if (type == 'mermaid' || type == 'mermaid2drawio')
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('inserting')))
- {
- var k = 0;
- while (k < lines.length && (lines[k].trim().length == 0 ||
- lines[k].substring(0, 2) == '%%'))
- {
- k++;
- }
- if (lines[k].trim() == '---')
- {
- do
- {
- k++;
- }
- while (k < lines.length && lines[k].trim() != '---');
-
- k++;
- }
- var diagramType = lines[k].trim().toLowerCase();
- var sp = diagramType.indexOf(' ');
- diagramType = diagramType.substring(0, sp > 0 ? sp : diagramType.length);
- // TODO Better to add only what we support?
- var inDrawioFormat = typeof mxMermaidToDrawio !== 'undefined' &&
- type == 'mermaid2drawio' && diagramType != 'gantt' &&
- diagramType != 'pie' && diagramType != 'timeline' &&
- diagramType != 'quadrantchart' && diagramType != 'c4context' &&
- diagramType != 'block-beta' && diagramType != 'zenuml' &&
- diagramType != 'xychart-beta' && diagramType != 'sankey-beta';
- var graph = editorUi.editor.graph;
-
- if (inDrawioFormat)
- {
- mxMermaidToDrawio.addListener(mxUtils.bind(this, function(modelXml)
- {
- editorUi.spinner.stop();
- graph.setSelectionCells(editorUi.importXml(modelXml,
- Math.max(insertPoint.x, 20),
- Math.max(insertPoint.y, 20),
- true, null, null, true));
- graph.scrollCellToVisible(graph.getSelectionCell());
- }));
- }
- editorUi.generateMermaidImage(text, null, function(data, w, h)
- {
- if (inDrawioFormat) return;
- insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint : graph.getCenterInsertPoint(new mxRectangle(0, 0, w, h));
- editorUi.spinner.stop();
- var cell = null;
-
- graph.getModel().beginUpdate();
- try
- {
- cell = graph.insertVertex(null, null, null, insertPoint.x, insertPoint.y,
- w, h, 'shape=image;noLabel=1;verticalAlign=top;imageAspect=1;' +
- 'image=' + data + ';')
- graph.setAttributeForCell(cell, 'mermaidData',
- JSON.stringify({data: text}, null, 2));
- }
- finally
- {
- graph.getModel().endUpdate();
- }
-
- if (cell != null)
- {
- graph.setSelectionCell(cell);
- graph.scrollCellToVisible(cell);
- }
- }, function(e)
- {
- if (typeof mxMermaidToDrawio !== 'undefined')
- {
- mxMermaidToDrawio.resetListeners();
- }
-
- editorUi.handleError(e);
- });
- }
- }
- else if (type == 'table')
- {
- var tableCell = null;
- var cells = [];
- var dx = 0;
- var pkMap = {};
- //First pass to find primary keys
- for (var i = 0; i < lines.length; i++)
- {
- var line = mxUtils.trim(lines[i]);
-
- if (line.substring(0, 11).toLowerCase() == 'primary key')
- {
- var pk = line.match(/\((.+)\)/);
-
- if (pk && pk[1])
- {
- pkMap[pk[1]] = true;
- }
-
- lines.splice(i, 1);
- }
- else if (line.toLowerCase().indexOf('primary key') > 0)
- {
- pkMap[line.split(' ')[0]] = true;
- lines[i] = mxUtils.trim(line.replace(/primary key/i, ''));
- }
- }
-
- for (var i = 0; i < lines.length; i++)
- {
- var tmp = mxUtils.trim(lines[i]);
-
- if (tmp.substring(0, 12).toLowerCase() == 'create table')
- {
- var name = mxUtils.trim(tmp.substring(12));
-
- if (name.charAt(name.length - 1) == '(')
- {
- name = mxUtils.trim(name.substring(0, name.length - 1));
- }
-
- tableCell = new mxCell(name, new mxGeometry(dx, 0, 160, 30),
- 'shape=table;startSize=30;container=1;collapsible=1;childLayout=tableLayout;' +
- 'fixedRows=1;rowLines=0;fontStyle=1;align=center;resizeLast=1;');
- tableCell.vertex = true;
- cells.push(tableCell);
-
- var size = editorUi.editor.graph.getPreferredSizeForCell(rowCell);
-
- if (size != null)
- {
- tableCell.geometry.width = size.width + 10;
- }
- }
- else if (tableCell != null && tmp.charAt(0) == ')')
- {
- dx += tableCell.geometry.width + 40;
- tableCell = null;
- }
- else if (tmp != '(' && tableCell != null)
- {
- var name = tmp.substring(0, (tmp.charAt(tmp.length - 1) == ',') ? tmp.length - 1 : tmp.length);
-
- var pk = pkMap[name.split(' ')[0]];
- var rowCell = new mxCell('', new mxGeometry(0, 0, 160, 30),
- 'shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;fillColor=none;' +
- 'collapsible=0;dropTarget=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;' +
- 'strokeColor=inherit;top=0;left=0;right=0;bottom=' + (pk ? '1' : '0') + ';');
- rowCell.vertex = true;
-
- var left = new mxCell(pk ? 'PK' : '', new mxGeometry(0, 0, 30, 30),
- 'shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;' +
- 'strokeColor=inherit;top=0;left=0;bottom=0;right=0;' +
- (pk ? 'fontStyle=1;' : ''));
- left.vertex = true;
- rowCell.insert(left);
-
- var right = new mxCell(name, new mxGeometry(30, 0, 130, 30),
- 'shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;align=left;' +
- 'strokeColor=inherit;top=0;left=0;bottom=0;right=0;spacingLeft=6;' +
- (pk ? 'fontStyle=5;' : ''));
- right.vertex = true;
- rowCell.insert(right);
-
- var size = editorUi.editor.graph.getPreferredSizeForCell(right);
-
- if (size != null && tableCell.geometry.width < size.width + 30)
- {
- tableCell.geometry.width = Math.min(320, Math.max(tableCell.geometry.width, size.width + 30));
- }
-
- tableCell.insert(rowCell, pk? 0 : null);
- tableCell.geometry.height += 30;
- }
- }
-
- if (cells.length > 0)
- {
- var graph = editorUi.editor.graph;
- insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint :
- graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry(cells, true));
- graph.setSelectionCells(graph.importCells(cells, insertPoint.x, insertPoint.y));
- graph.scrollCellToVisible(graph.getSelectionCell());
- }
- }
- else if (type == 'list')
- {
- if (lines.length > 0)
- {
- var graph = editorUi.editor.graph;
- var listCell = null;
- var cells = [];
- var x0 = 0;
- for (var i = 0; i < lines.length; i++)
- {
- if (lines[i].charAt(0) != ';')
- {
- if (lines[i].length == 0)
- {
- listCell = null;
- }
- else
- {
- if (listCell == null)
- {
- listCell = new mxCell(lines[i], new mxGeometry(x0, 0, 160, 26 + 4),
- 'swimlane;fontStyle=1;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;');
- listCell.vertex = true;
- cells.push(listCell);
- var size = graph.getPreferredSizeForCell(listCell);
-
- if (size != null && listCell.geometry.width < size.width + 10)
- {
- listCell.geometry.width = size.width + 10;
- }
-
- x0 += listCell.geometry.width + 40;
- }
- else if (lines[i] == '--')
- {
- 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;');
- divider.vertex = true;
- listCell.geometry.height += divider.geometry.height;
- listCell.insert(divider);
- }
- else if (lines[i].length > 0)
- {
- 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;');
- field.vertex = true;
-
- var size = graph.getPreferredSizeForCell(field);
-
- if (size != null && field.geometry.width < size.width)
- {
- field.geometry.width = size.width;
- }
-
- listCell.geometry.width = Math.max(listCell.geometry.width, field.geometry.width);
- listCell.geometry.height += field.geometry.height;
- listCell.insert(field);
- }
- }
- }
- }
-
- if (cells.length > 0)
- {
- insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint :
- graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry(cells, true));
-
- graph.getModel().beginUpdate();
- try
- {
- cells = graph.importCells(cells, insertPoint.x, insertPoint.y);
- var inserted = [];
-
- for (var i = 0; i < cells.length; i++)
- {
- inserted.push(cells[i]);
- inserted = inserted.concat(cells[i].children);
- }
-
- graph.fireEvent(new mxEventObject('cellsInserted', 'cells', inserted));
- }
- finally
- {
- graph.getModel().endUpdate();
- }
-
- graph.setSelectionCells(cells);
- graph.scrollCellToVisible(graph.getSelectionCell());
- }
- }
- }
- else
- {
- var vertices = new Object();
- var cells = [];
-
- function getOrCreateVertex(id)
- {
- var vertex = vertices[id];
-
- if (vertex == null)
- {
- vertex = new mxCell(id, new mxGeometry(0, 0, 80, 30), 'whiteSpace=wrap;html=1;');
- vertex.vertex = true;
- vertices[id] = vertex;
- cells.push(vertex);
- }
-
- return vertex;
- };
-
- for (var i = 0; i < lines.length; i++)
- {
- if (lines[i].charAt(0) != ';')
- {
- var values = lines[i].split('->');
-
- if (values.length >= 2)
- {
- var source = getOrCreateVertex(values[0]);
- var target = getOrCreateVertex(values[values.length - 1]);
-
- var edge = new mxCell((values.length > 2) ? values[1] : '', new mxGeometry());
- edge.edge = true;
- edge.geometry.relative = true;
- source.insertEdge(edge, true);
- target.insertEdge(edge, false);
- cells.push(edge);
- }
- }
- }
-
- if (cells.length > 0)
- {
- var container = document.createElement('div');
- container.style.visibility = 'hidden';
- document.body.appendChild(container);
-
- // Temporary graph for running the layout
- var graph = new Graph(container);
-
- graph.getModel().beginUpdate();
- try
- {
- cells = graph.importCells(cells);
-
- for (var i = 0; i < cells.length; i++)
- {
- if (graph.getModel().isVertex(cells[i]))
- {
- var size = graph.getPreferredSizeForCell(cells[i]);
- cells[i].geometry.width = Math.max(cells[i].geometry.width, size.width);
- cells[i].geometry.height = Math.max(cells[i].geometry.height, size.height);
- }
- }
- var runEdgeLayout = true;
- if (type == 'horizontalFlow' || type == 'verticalFlow')
- {
- var flowLayout = new mxHierarchicalLayout(graph,
- (type == 'horizontalFlow') ?
- mxConstants.DIRECTION_WEST :
- mxConstants.DIRECTION_NORTH);
- flowLayout.execute(graph.getDefaultParent(), cells);
- runEdgeLayout = false;
- }
- else if (type == 'circle')
- {
- var circleLayout = new mxCircleLayout(graph);
- circleLayout.execute(graph.getDefaultParent());
- }
- else
- {
- var layout = new mxFastOrganicLayout(graph);
- layout.disableEdgeStyle = false;
- layout.forceConstant = 180;
- layout.execute(graph.getDefaultParent());
- }
-
- if (runEdgeLayout)
- {
- var edgeLayout = new mxParallelEdgeLayout(graph);
- edgeLayout.spacing = 30;
- edgeLayout.execute(graph.getDefaultParent());
- }
- }
- finally
- {
- graph.getModel().endUpdate();
- }
-
- graph.clearCellOverlays();
-
- // Copy to actual graph
- var inserted = [];
-
- editorUi.editor.graph.getModel().beginUpdate();
- try
- {
- cells = graph.getModel().getChildren(graph.getDefaultParent());
- insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint :
- editorUi.editor.graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry(cells, true));
- inserted = editorUi.editor.graph.importCells(cells, insertPoint.x, insertPoint.y)
- editorUi.editor.graph.fireEvent(new mxEventObject('cellsInserted', 'cells', inserted));
- }
- finally
- {
- editorUi.editor.graph.getModel().endUpdate();
- }
- editorUi.editor.graph.setSelectionCells(inserted);
- editorUi.editor.graph.scrollCellToVisible(editorUi.editor.graph.getSelectionCell());
- graph.destroy();
- container.parentNode.removeChild(container);
- }
- }
- };
-
- var div = document.createElement('div');
- div.style.textAlign = 'right';
-
- var textarea = document.createElement('textarea');
- textarea.style.boxSizing = 'border-box';
- textarea.style.resize = 'none';
- textarea.style.width = '100%';
- textarea.style.height = '354px';
- textarea.style.marginBottom = '16px';
-
- var typeSelect = document.createElement('select');
- typeSelect.className = 'geBtn';
-
- if (defaultType == 'formatSql' || (defaultType == 'mermaid' &&
- editorUi.getServiceName() != 'draw.io' && editorUi.getServiceName() != 'atlassian'))
- {
- typeSelect.style.display = 'none';
- }
- var listOption = document.createElement('option');
- listOption.setAttribute('value', 'list');
- mxUtils.write(listOption, mxResources.get('list'));
-
- if (defaultType != 'plantUml' && defaultType != 'mermaid')
- {
- typeSelect.appendChild(listOption);
- }
- if (defaultType == null || defaultType == 'fromText')
- {
- listOption.setAttribute('selected', 'selected');
- }
-
- var tableOption = document.createElement('option');
- tableOption.setAttribute('value', 'table');
- mxUtils.write(tableOption, mxResources.get('formatSql'));
-
- if (defaultType == 'formatSql')
- {
- typeSelect.appendChild(tableOption);
- tableOption.setAttribute('selected', 'selected');
- }
- var mermaidOption = document.createElement('option');
- mermaidOption.setAttribute('value', 'mermaid');
- mxUtils.write(mermaidOption, mxResources.get('image'));
- if (defaultType == 'mermaid')
- {
- if (typeof mxMermaidToDrawio !== 'undefined')
- {
- var mermaid2drawioOption = document.createElement('option');
- mermaid2drawioOption.setAttribute('value', 'mermaid2drawio');
- mermaid2drawioOption.setAttribute('selected', 'selected');
- mxUtils.write(mermaid2drawioOption, mxResources.get('diagram'));
- typeSelect.appendChild(mermaid2drawioOption);
- }
- else
- {
- typeSelect.style.display = 'none';
- }
- }
-
- typeSelect.appendChild(mermaidOption);
- var diagramOption = document.createElement('option');
- diagramOption.setAttribute('value', 'diagram');
- mxUtils.write(diagramOption, mxResources.get('diagram'));
- var circleOption = document.createElement('option');
- circleOption.setAttribute('value', 'circle');
- mxUtils.write(circleOption, mxResources.get('circle'));
- var horizontalFlowOption = document.createElement('option');
- horizontalFlowOption.setAttribute('value', 'horizontalFlow');
- mxUtils.write(horizontalFlowOption, mxResources.get('horizontalFlow'));
-
- var verticalFlowOption = document.createElement('option');
- verticalFlowOption.setAttribute('value', 'verticalFlow');
- mxUtils.write(verticalFlowOption, mxResources.get('verticalFlow'));
-
- if (defaultType != 'plantUml' && defaultType != 'mermaid')
- {
- typeSelect.appendChild(diagramOption);
- typeSelect.appendChild(circleOption);
- typeSelect.appendChild(horizontalFlowOption);
- typeSelect.appendChild(verticalFlowOption);
- }
- var plantUmlSvgOption = document.createElement('option');
- plantUmlSvgOption.setAttribute('value', 'plantUmlSvg');
- mxUtils.write(plantUmlSvgOption, mxResources.get('plantUml') + ' (' + mxResources.get('formatSvg') + ')');
-
- if (defaultType == 'plantUml')
- {
- plantUmlSvgOption.setAttribute('selected', 'selected');
- }
-
- var plantUmlPngOption = document.createElement('option');
- plantUmlPngOption.setAttribute('value', 'plantUmlPng');
- mxUtils.write(plantUmlPngOption, mxResources.get('plantUml') + ' (' + mxResources.get('formatPng') + ')');
-
- var plantUmlTxtOption = document.createElement('option');
- plantUmlTxtOption.setAttribute('value', 'plantUmlTxt');
- mxUtils.write(plantUmlTxtOption, mxResources.get('plantUml') + ' (' + mxResources.get('text') + ')');
-
- // Disabled for invalid hosts via CORS headers
- if (EditorUi.enablePlantUml && Graph.fileSupport &&
- !editorUi.isOffline() && defaultType == 'plantUml')
- {
- typeSelect.appendChild(plantUmlSvgOption);
- typeSelect.appendChild(plantUmlPngOption);
- typeSelect.appendChild(plantUmlTxtOption);
- }
- function getDefaultValue()
- {
- if (typeSelect.value == 'list')
- {
- return 'Person\n-name: String\n-birthDate: Date\n--\n+getName(): String\n+setName(String): void\n+isBirthday(): boolean\n\n' +
- 'Address\n-street: String\n-city: String\n-state: String';
- }
- else if (typeSelect.value == 'mermaid' || typeSelect.value == 'mermaid2drawio')
- {
- return 'graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;';
- }
- else if (typeSelect.value == 'table')
- {
- return 'CREATE TABLE Suppliers\n(\nsupplier_id int NOT NULL PRIMARY KEY,\n' +
- 'supplier_name char(50) NOT NULL,\ncontact_name char(50),\n);\n' +
- 'CREATE TABLE Customers\n(\ncustomer_id int NOT NULL PRIMARY KEY,\n' +
- 'customer_name char(50) NOT NULL,\naddress char(50),\n' +
- 'city char(50),\nstate char(25),\nzip_code char(10)\n);\n';
- }
- else if (typeSelect.value == 'plantUmlPng')
- {
- 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';
- }
- else if (typeSelect.value == 'plantUmlSvg' || typeSelect.value == 'plantUmlTxt')
- {
- return plantUmlExample;
- }
- else
- {
- return ';Example:\na->b\nb->edge label->c\nc->a\n';
- }
- };
-
- var defaultValue = getDefaultValue();
- textarea.value = defaultValue;
- div.appendChild(textarea);
-
- this.init = function()
- {
- textarea.focus();
- };
-
- // Enables dropping files
- if (Graph.fileSupport)
- {
- function handleDrop(evt)
- {
- evt.stopPropagation();
- evt.preventDefault();
-
- if (evt.dataTransfer.files.length > 0)
- {
- var file = evt.dataTransfer.files[0];
-
- var reader = new FileReader();
- reader.onload = function(e) { textarea.value = e.target.result; };
- reader.readAsText(file);
- }
- };
-
- function handleDragOver(evt)
- {
- evt.stopPropagation();
- evt.preventDefault();
- };
- // Setup the dnd listeners.
- textarea.addEventListener('dragover', handleDragOver, false);
- textarea.addEventListener('drop', handleDrop, false);
- }
- div.appendChild(typeSelect);
-
- mxEvent.addListener(typeSelect, 'change', function()
- {
- var newDefaultValue = getDefaultValue();
-
- if (textarea.value.length == 0 || textarea.value == defaultValue)
- {
- defaultValue = newDefaultValue;
- textarea.value = defaultValue;
- }
- });
-
- if (!editorUi.isOffline() && (defaultType == 'mermaid' || defaultType == 'plantUml'))
- {
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- editorUi.openLink((defaultType == 'mermaid') ?
- 'https://mermaid-js.github.io/mermaid/#/' :
- 'https://plantuml.com/');
- });
-
- helpBtn.className = 'geBtn';
- div.appendChild(helpBtn);
- }
-
- var cancelBtn = mxUtils.button(mxResources.get('close'), function()
- {
- if (textarea.value == defaultValue)
- {
- editorUi.hideDialog();
- }
- else
- {
- editorUi.confirm(mxResources.get('areYouSure'), function()
- {
- editorUi.hideDialog();
- });
- }
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- div.appendChild(cancelBtn);
- }
-
- var okBtn = mxUtils.button(mxResources.get('insert'), function(evt)
- {
- try
- {
- editorUi.hideDialog();
- parse(textarea.value, typeSelect.value, evt);
- }
- catch (e)
- {
- editorUi.handleError(e);
- }
- });
-
- okBtn.className = 'geBtn gePrimaryBtn';
- div.appendChild(okBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- div.appendChild(cancelBtn);
- }
- this.container = div;
- };
- /**
- * Constructs a new dialog for creating files from templates.
- */
- var NewDialog = function(editorUi, compact, showName, callback, createOnly, cancelCallback,
- leftHighlight, rightHighlight, rightHighlightBorder, itemPadding, templateFile,
- recentDocsCallback, searchDocsCallback, openExtDocCallback, showImport, createButtonLabel, customTempCallback, withoutType)
- {
- var ww = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- var smallScreen = ww < 500;
- showName = (showName != null) ? showName : true;
- createOnly = (createOnly != null) ? createOnly : false;
- leftHighlight = (leftHighlight != null) ? leftHighlight : (Editor.isDarkMode() ? Editor.darkColor : '#ebf2f9');
- rightHighlight = (rightHighlight != null) ? rightHighlight : (Editor.isDarkMode() ? '#fff' : '#e6eff8');
- rightHighlightBorder = (rightHighlightBorder != null) ? rightHighlightBorder : (Editor.isDarkMode() ? '2px dashed #00a8ff' : '2px solid #29b6f2');
- templateFile = (templateFile != null) ? templateFile : EditorUi.templateFile;
-
- var outer = document.createElement('div');
- outer.style.userSelect = 'none';
- outer.style.height = '100%';
-
- var header = document.createElement('div');
- header.style.whiteSpace = 'nowrap';
- header.style.height = '46px';
-
- if (showName)
- {
- outer.appendChild(header);
- }
-
- var logo = document.createElement('img');
- logo.setAttribute('border', '0');
- logo.setAttribute('align', 'absmiddle');
- logo.style.width = '40px';
- logo.style.height = '40px';
- logo.style.marginRight = '10px';
- logo.style.paddingBottom = '4px';
-
- if (editorUi.mode == App.MODE_GOOGLE)
- {
- logo.src = IMAGE_PATH + '/google-drive-logo.svg';
- }
- else if (editorUi.mode == App.MODE_DROPBOX)
- {
- logo.src = IMAGE_PATH + '/dropbox-logo.svg';
- }
- else if (editorUi.mode == App.MODE_ONEDRIVE)
- {
- logo.src = IMAGE_PATH + '/onedrive-logo.svg';
- }
- else if (editorUi.mode == App.MODE_GITHUB)
- {
- logo.src = IMAGE_PATH + '/github-logo.svg';
- }
- else if (editorUi.mode == App.MODE_GITLAB)
- {
- logo.src = IMAGE_PATH + '/gitlab-logo.svg';
- }
- else if (editorUi.mode == App.MODE_TRELLO)
- {
- logo.src = IMAGE_PATH + '/trello-logo.svg';
- }
- else if (editorUi.mode == App.MODE_BROWSER)
- {
- logo.src = IMAGE_PATH + '/osa_database.png';
- }
- else
- {
- logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
- }
- if (!compact && !smallScreen && showName)
- {
- header.appendChild(logo);
- }
-
- if (showName)
- {
- mxUtils.write(header, (smallScreen? mxResources.get('name') : ((editorUi.mode == null || editorUi.mode == App.MODE_GOOGLE ||
- editorUi.mode == App.MODE_BROWSER) ? mxResources.get('diagramName') : mxResources.get('filename'))) + ':');
- }
-
- var ext = '.drawio';
-
- if (editorUi.mode == App.MODE_GOOGLE && editorUi.drive != null)
- {
- ext = editorUi.drive.extension;
- }
- else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
- {
- ext = editorUi.dropbox.extension;
- }
- else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
- {
- ext = editorUi.oneDrive.extension;
- }
- else if (editorUi.mode == App.MODE_GITHUB && editorUi.gitHub != null)
- {
- ext = editorUi.gitHub.extension;
- }
- else if (editorUi.mode == App.MODE_GITLAB && editorUi.gitLab != null)
- {
- ext = editorUi.gitLab.extension;
- }
- else if (editorUi.mode == App.MODE_TRELLO && editorUi.trello != null)
- {
- ext = editorUi.trello.extension;
- }
-
- var nameInput = document.createElement('input');
- nameInput.setAttribute('value', editorUi.defaultFilename + ext);
- nameInput.style.marginLeft = '10px';
- nameInput.style.width = (compact || smallScreen) ? '144px' : '244px';
-
- this.init = function()
- {
- if (showName)
- {
- Editor.selectFilename(nameInput);
- }
-
- if (div.parentNode != null && div.parentNode.parentNode != null)
- {
- mxEvent.addGestureListeners(div.parentNode.parentNode, mxUtils.bind(this, function(evt)
- {
- if (editorUi.sidebar != null)
- {
- editorUi.sidebar.hideTooltip();
- }
- }), null, null);
- }
- };
-
- // Adds filetype dropdown
- if (showName)
- {
- header.appendChild(nameInput);
- if (withoutType)
- {
- nameInput.style.width = (compact || smallScreen) ? '350px' : '450px';
- }
- else
- {
- if (editorUi.editor.diagramFileTypes != null)
- {
- var typeSelect = FilenameDialog.createFileTypes(editorUi, nameInput, editorUi.editor.diagramFileTypes);
- typeSelect.style.marginLeft = '6px';
- typeSelect.style.width = (compact || smallScreen) ? '80px' : '180px';
- header.appendChild(typeSelect);
- }
- }
- }
- var hasTabs = false;
- var i0 = 0;
-
- // Dynamic loading
- function addTemplates(smallSize)
- {
- //smallSize: Reduce template button size to fit 4 in a row
- if (smallSize != null)
- {
- w = h = smallSize? 135 : 140;
- }
-
- var first = true;
-
- //TODO support paging of external templates
- if (templates != null)
- {
- while (i0 < templates.length && (first || mxUtils.mod(i0, 30) != 0))
- {
- var tmp = templates[i0++];
- var btn = addButton(tmp.url, tmp.libs, tmp.title, tmp.tooltip? tmp.tooltip : tmp.title,
- tmp.select, tmp.imgUrl, tmp.info, tmp.onClick, tmp.preview, tmp.noImg, tmp.clibs,
- tmp.type);
-
- if (first)
- {
- btn.click();
- }
-
- first = false;
- }
- }
- };
-
- var spinner = new Spinner({
- lines: 12, // The number of lines to draw
- length: 10, // The length of each line
- width: 5, // The line thickness
- radius: 10, // The radius of the inner circle
- rotate: 0, // The rotation offset
- color: '#000', // #rgb or #rrggbb
- speed: 1.5, // Rounds per second
- trail: 60, // Afterglow percentage
- shadow: false, // Whether to render a shadow
- hwaccel: false, // Whether to use hardware acceleration
- top: '40%',
- zIndex: 2e9 // The z-index (defaults to 2000000000)
- });
-
- var createButton = mxUtils.button(createButtonLabel || mxResources.get('create'), function()
- {
- createButton.setAttribute('disabled', 'disabled');
- create();
- createButton.removeAttribute('disabled');
- });
-
- createButton.className = 'geBtn gePrimaryBtn';
- var magnifyImage = document.createElement('img');
- magnifyImage.setAttribute('src', Editor.magnifyImage);
- magnifyImage.setAttribute('title', mxResources.get('preview'));
- magnifyImage.className = 'geAdaptiveAsset geActiveButton';
- magnifyImage.style.position = 'absolute';
- magnifyImage.style.borderRadius = '16px';
- magnifyImage.style.background = 'white';
- magnifyImage.style.cursor = 'default';
- magnifyImage.style.padding = '2px';
- magnifyImage.style.opacity = '0.8';
- magnifyImage.style.height = '16px';
- magnifyImage.style.right = '2px';
- magnifyImage.style.top = '2px';
-
- // Shows a tooltip with the rendered template
- var loading = false;
- var extImg = null;
- var wasVisible = false;
-
- function showTooltip(xml, x, y, elt, title, url)
- {
- // Checks if dialog still visible
- if (xml != null && mxUtils.isAncestorNode(document.body, elt))
- {
- var doc = mxUtils.parseXml(xml);
- var tempNode = Editor.parseDiagramNode(doc.documentElement, null, true);
- var codec = new mxCodec(tempNode.ownerDocument);
- var model = new mxGraphModel();
- codec.decode(tempNode, model);
- var cells = model.root.children;
-
- var ww = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- var wh = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
-
- // TODO: Use maxscreensize
- editorUi.sidebar.createTooltip(elt, cells, Math.min(ww - 120, 1000), Math.min(wh - 120, 800),
- (title != null) ? mxResources.get(title) : null,
- true, new mxPoint(x, y), true, function()
- {
- wasVisible = editorUi.sidebar.tooltip != null &&
- editorUi.sidebar.tooltip.style.display != 'none';
- if (url != null)
- {
- selectElement(elt, null, null, url, infoObj, clibs);
- }
- }, true, false);
- }
- };
- if (recentDocsCallback || searchDocsCallback)
- {
- var tabsEl = [];
- var oldTemplates = null, origCategories = null, origCustomCatCount = null;
-
- var setActiveTab = function(index)
- {
- createButton.setAttribute('disabled', 'disabled');
-
- for (var i = 0; i < tabsEl.length; i++)
- {
- if (i == index)
- tabsEl[i].className = 'geBtn gePrimaryBtn';
- else
- tabsEl[i].className = 'geBtn';
- }
- }
-
- hasTabs = true;
- var tabs = document.createElement('div');
- tabs.style.whiteSpace = 'nowrap';
- tabs.style.height = '30px';
- outer.appendChild(tabs);
-
- var templatesTab = mxUtils.button(mxResources.get('Templates', null, 'Templates'), function()
- {
- list.style.display = '';
- searchBox.style.display = '';
- div.style.left = '160px';
- setActiveTab(0);
- div.scrollTop = 0;
- div.innerText = '';
- i0 = 0;
-
- if (oldTemplates != templates)
- {
- templates = oldTemplates;
- categories = origCategories;
- customCatCount = origCustomCatCount;
- list.innerText = '';
- initUi();
- oldTemplates = null;
- }
- });
-
- tabsEl.push(templatesTab);
- tabs.appendChild(templatesTab);
-
- var getExtTemplates = function(isSearch)
- {
- list.style.display = 'none';
- searchBox.style.display = 'none';
- div.style.left = '30px';
-
- setActiveTab(isSearch? -1 : 1); //deselect all of them if isSearch
-
- if (oldTemplates == null)
- {
- oldTemplates = templates;
- }
-
- div.scrollTop = 0;
- div.innerText = '';
- spinner.spin(div);
- var callback2 = function(docList, errorMsg, searchImportCats)
- {
- i0 = 0;
- spinner.stop();
- templates = docList;
- searchImportCats = searchImportCats || {};
- var importListsCount = 0;
-
- for (var cat in searchImportCats)
- {
- importListsCount += searchImportCats[cat].length;
- }
-
- if (errorMsg)
- {
- div.innerText = errorMsg;
- }
- else if (docList.length == 0 && importListsCount == 0)
- {
- div.innerText = mxResources.get('noDiagrams', null, 'No Diagrams Found');
- }
- else
- {
- div.innerText = '';
-
- if (importListsCount > 0)
- {
- list.style.display = '';
- div.style.left = '160px';
- list.innerText = '';
- customCatCount = 0;
- categories = {'draw.io': docList};
-
- for (var cat in searchImportCats)
- {
- categories[cat] = searchImportCats[cat];
- }
-
- initUi();
- }
- else
- {
- addTemplates(true);
- }
- }
- }
-
- if (isSearch)
- {
- searchDocsCallback(searchInput.value, callback2);
- }
- else
- {
- recentDocsCallback(callback2);
- }
- }
-
- if (recentDocsCallback)
- {
- var recentTab = mxUtils.button(mxResources.get('Recent', null, 'Recent'), function()
- {
- getExtTemplates();
- });
- tabs.appendChild(recentTab);
- tabsEl.push(recentTab);
- }
-
- if (searchDocsCallback)
- {
- var searchTab = document.createElement('span');
- searchTab.style.marginLeft = '10px';
- searchTab.innerText = mxResources.get('search') + ':';
- tabs.appendChild(searchTab);
- var searchInput = document.createElement('input');
- searchInput.style.marginRight = '10px';
- searchInput.style.marginLeft = '10px';
- searchInput.style.width = '220px';
- mxEvent.addListener(searchInput, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- getExtTemplates(true);
- }
- });
- tabs.appendChild(searchInput);
- var searchBtn = mxUtils.button(mxResources.get('search'), function()
- {
- getExtTemplates(true);
- });
-
- searchBtn.className = 'geBtn';
- tabs.appendChild(searchBtn);
- }
-
- setActiveTab(0);
- }
-
- var templateLibs = null;
- var templateClibs = null;
- var templateXml = null;
- var selectedElt = null;
- var templateExtUrl = null;
- var templateRealUrl = null;
- var templateInfoObj = null;
- var lastAiXml = null;
- var lastAiTitle = null;
- function createSmartTemplateContent()
- {
- var content = document.createElement('div');
- content.style.position = 'absolute';
- content.style.overflow = 'visible';
- content.style.left = '8px';
- content.style.right = '8px';
- content.style.bottom = '8px';
- content.style.top = '8px';
- mxUtils.write(content, mxResources.get('describeYourDiagram') + ':');
- mxUtils.br(content);
- var description = document.createElement('input');
- description.setAttribute('type', 'text');
- description.setAttribute('placeholder', mxResources.get('processForHiringNewEmployee'));
- description.style.width = '100%';
- description.style.marginTop = '6px';
- description.style.marginBottom = '4px';
- description.style.boxSizing = 'border-box';
- content.appendChild(description);
- content.init = function()
- {
- description.focus();
- };
- mxUtils.br(content);
- var preview = document.createElement('div');
- preview.style.top = '86px'
- preview.style.left = '2px';
- preview.style.right = '2px';
- preview.style.bottom = '2px';
- preview.style.position = 'absolute';
- preview.style.border = '1px solid #424242';
- var previewText = document.createElement('div');
- previewText.style.boxSizing = 'border-box';
- previewText.style.position = 'relative';
- previewText.style.textAlign = 'center';
- previewText.style.top = '50%';
- mxUtils.write(previewText, mxResources.get('blankDiagram'));
- preview.appendChild(previewText);
- // Adds diagram type options
- var typeSelect = document.createElement('select');
- typeSelect.className = 'geBtn';
- typeSelect.style.maxWidth = '160px';
- typeSelect.style.marginLeft = '0px';
- var option = document.createElement('option');
- mxUtils.write(option, mxResources.get('diagramType'));
- option.setAttribute('value', '');
- typeSelect.appendChild(option);
- for (var i = 0; i < EditorUi.mermaidDiagramTypes.length; i++)
- {
- var option = document.createElement('option');
- var type = EditorUi.mermaidDiagramTypes[i];
- var key = type;
- if (type == urlParams['smart-template-type'])
- {
- option.setAttribute('selected', 'selected');
- }
- // Maps types to translations
- if (key == 'erDiagram')
- {
- key = 'entityRelationshipDiagram';
- }
- var title = mxResources.get(key, null, key.charAt(0).toUpperCase() +
- key.substring(1).replace(/[A-Z]/g, ' $&'));
- option.setAttribute('value', type);
- mxUtils.write(option, title);
- typeSelect.appendChild(option);
- }
- var button = mxUtils.button(mxResources.get('generate'), function()
- {
- var desc = description.value;
- var type = typeSelect.value.replace(/([A-Z])/g, " $1").toLowerCase();
- var prompt = 'Write the declaration code for a detailed and complex ' +
- (type != '' ? type : 'graph') + ' that shows "' + (desc != '' ? desc :
- 'something random') + '" using correct MermaidJS syntax and do not ' +
- 'provide additional text in your response.';
- var type = ((typeSelect.value != '') ? (' (' + mxUtils.trim(
- mxUtils.getTextContent(typeSelect.options[
- typeSelect.selectedIndex])) + ')') : '');
- var useMermaidFormat = typeSelect.value == 'gantt' || typeSelect.value == 'pie' ||
- typeSelect.value == 'timeline' || typeSelect.value == 'quadrantchart' ||
- typeSelect.value == 'c4context';
- var title = description.value + type;
-
- if (typeof mxMermaidToDrawio !== 'undefined')
- {
- mxMermaidToDrawio.addListener(mxUtils.bind(this, function(modelXml)
- {
- if (!useMermaidFormat)
- {
- templateXml = modelXml;
- lastAiXml = templateXml;
- lastAiTitle = 'Smart Template: ' + title;
- }
- }));
- }
- if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
- {
- editorUi.generateOpenAiMermaidDiagram(prompt,
- function(mermaidData, imageData, w, h)
- {
- editorUi.spinner.stop();
- preview.innerHTML = '';
- var img = document.createElement('img');
- img.setAttribute('title', title);
- img.src = 'data:image/svg+xml;base64,' +
- imageData.substring(imageData.indexOf(',') + 1);
- img.style.cursor = 'pointer';
- img.style.width = '100%';
- img.style.height = '100%';
- preview.appendChild(img);
- var xml = editorUi.createMermaidXml(mermaidData,
- EditorUi.defaultMermaidConfig,
- imageData, w, h, title);
- // Updates template XML for insert button
- var previewXml = '<mxfile><diagram>' + Graph.compress(xml) + '</diagram></mxfile>';
-
- if (useMermaidFormat || typeof mxMermaidToDrawio === 'undefined')
- {
- templateXml = xml;
- lastAiXml = xml;
- }
- var magnify = magnifyImage.cloneNode(true);
- preview.appendChild(magnify);
- var mouseDownHandler = function(evt)
- {
- wasVisible = editorUi.sidebar.tooltip != null &&
- editorUi.sidebar.tooltip.style.display != 'none';
- };
- var mouseUpHandler = function(evt)
- {
- if (!wasVisible)
- {
- showTooltip(previewXml, mxEvent.getClientX(evt),
- mxEvent.getClientY(evt), img, title);
- }
- };
- mxEvent.addGestureListeners(img, mouseDownHandler, null, mouseUpHandler);
- mxEvent.addGestureListeners(magnify, mouseDownHandler, null, mouseUpHandler);
- }, function(e)
- {
- editorUi.spinner.stop();
- if (mxMermaidToDrawio.resetListeners != null)
- {
- mxMermaidToDrawio.resetListeners();
- }
- editorUi.handleError(e);
- }
- );
- }
- });
- button.setAttribute('disabled', 'disabled');
- button.className = 'geBtn gePrimaryBtn';
- var updateState = function()
- {
- window.setTimeout(function()
- {
- if (description.value != '')
- {
- button.removeAttribute('disabled');
- }
- else
- {
- button.setAttribute('disabled', 'disabled');
- }
- }, 0);
- };
- var temp = urlParams['smart-template'];
- if (temp != null && temp != '1')
- {
- description.value = decodeURIComponent(temp);
- updateState();
- if (urlParams['smart-template-generate'] == '1')
- {
- window.setTimeout(function()
- {
- button.click();
- }, 0);
- }
- }
- mxEvent.addListener(description, 'change', updateState);
- mxEvent.addListener(description, 'keydown', updateState);
- mxEvent.addListener(description, 'cut', updateState);
- mxEvent.addListener(description, 'paste', updateState);
- mxEvent.addListener(description, 'keydown', function(e)
- {
- if (e.keyCode == 13)
- {
- button.click();
- }
- });
- var buttons = document.createElement('div');
- buttons.style.height = '40px';
- buttons.style.marginTop = '4px';
- buttons.style.marginBottom = '4px';
- buttons.style.whiteSpace = 'nowrap';
- buttons.style.overflowX = 'auto';
- buttons.style.overflowY = 'hidden';
- buttons.appendChild(typeSelect);
- buttons.appendChild(button);
- content.appendChild(buttons);
- content.appendChild(preview);
- return content;
- };
-
- function create()
- {
- if (templateXml != null && templateXml == lastAiXml)
- {
- EditorUi.logEvent({category: 'OPENAI-DIAGRAM',
- action: 'templateGenerated',
- label: lastAiTitle});
- }
- if (templateExtUrl && openExtDocCallback != null)
- {
- if (!showName)
- {
- editorUi.hideDialog();
- }
-
- openExtDocCallback(templateExtUrl, templateInfoObj, nameInput.value);
- }
- else if (callback)
- {
- if (!showName)
- {
- editorUi.hideDialog();
- }
- callback(templateXml, nameInput.value, templateRealUrl, templateLibs);
- }
- else
- {
- var title = nameInput.value;
-
- if (title != null && title.length > 0)
- {
- function doSave(mode, folderId, filename)
- {
- editorUi.createFile(filename, templateXml, (templateLibs != null &&
- templateLibs.length > 0) ? templateLibs : null, mode, function()
- {
- editorUi.hideDialog();
- }, null, folderId, null, (templateClibs != null &&
- templateClibs.length > 0) ? templateClibs : null);
- };
- if (editorUi.mode == App.MODE_GOOGLE || editorUi.mode == App.MODE_ONEDRIVE)
- {
- var dlg = new SaveDialog(editorUi, title, mxUtils.bind(this, function(input, mode, folderId)
- {
- doSave(mode, folderId, input.value);
- }), null, null, null, null, editorUi.mode);
- editorUi.showDialog(dlg.container, 420, 150, true, false);
- dlg.init();
- }
- else
- {
- editorUi.pickFolder(editorUi.mode, function(folderId)
- {
- doSave(editorUi.mode, folderId, title);
- }, editorUi.mode != App.MODE_GOOGLE ||
- editorUi.stateArg == null ||
- editorUi.stateArg.folderId == null);
- }
- }
- }
- };
-
- var div = document.createElement('div');
- div.style.border = '1px solid #d3d3d3';
- div.style.position = 'absolute';
- div.style.left = '160px';
- div.style.right = '34px';
- var divTop = (showName) ? 72 : 40;
- divTop += hasTabs? 30 : 0;
- div.style.top = divTop + 'px';
- div.style.bottom = '68px';
- div.style.margin = '6px 0 0 -1px';
- div.style.padding = '6px';
- div.style.overflow = 'auto';
-
- var searchBox = document.createElement('div');
- searchBox.style.cssText = 'position:absolute;left:30px;width:128px;top:' + divTop +
- 'px;height:22px;margin-top: 6px;white-space: nowrap;';
- var tmplSearchInput = document.createElement('input');
- tmplSearchInput.style.cssText = 'width:105px;height:16px;border:1px solid #d3d3d3;' +
- 'padding: 3px 20px 3px 3px;font-size: 12px;border-radius:0px;';
- tmplSearchInput.setAttribute('placeholder', mxResources.get('search'));
- tmplSearchInput.setAttribute('type', 'text');
- searchBox.appendChild(tmplSearchInput);
-
- var cross = document.createElement('img');
- cross.setAttribute('src', Editor.magnifyImage);
- cross.setAttribute('title', mxResources.get('search'));
- cross.className = 'geAdaptiveAsset';
- cross.style.position = 'relative';
- cross.style.cursor = 'pointer';
- cross.style.opacity = '0.5';
- cross.style.height = '16px';
- cross.style.left = '-20px';
- cross.style.top = '4px';
- // Needed to block event transparency in IE
- cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
- searchBox.appendChild(cross);
-
- mxEvent.addListener(cross, 'click', function()
- {
- if (cross.getAttribute('src') != Editor.magnifyImage)
- {
- cross.setAttribute('src', Editor.magnifyImage);
- cross.setAttribute('title', mxResources.get('search'));
- tmplSearchInput.value = '';
- resetTemplates();
- }
- tmplSearchInput.focus();
- });
-
- mxEvent.addListener(tmplSearchInput, 'keydown', mxUtils.bind(this, function(evt)
- {
- if (evt.keyCode == 13 /* Enter */)
- {
- filterTemplates();
- mxEvent.consume(evt);
- }
- }));
-
- mxEvent.addListener(tmplSearchInput, 'keyup', mxUtils.bind(this, function(evt)
- {
- if (tmplSearchInput.value == '')
- {
- cross.setAttribute('src', Editor.magnifyImage);
- cross.setAttribute('title', mxResources.get('search'));
- }
- else
- {
- cross.setAttribute('src', Editor.crossImage);
- cross.setAttribute('title', mxResources.get('reset'));
- }
- }));
- divTop += 23;
- var list = document.createElement('div');
- list.style.cssText = 'position:absolute;left:30px;width:128px;top:' + divTop + 'px;bottom:68px;margin-top:6px;overflow:auto;border:1px solid #d3d3d3;';
-
- mxEvent.addListener(div, 'scroll', function()
- {
- editorUi.sidebar.hideTooltip();
- });
-
- var w = 140;
- var h = w;
- var generateElt = null;
- var generateBackground = 'url(' + Editor.sparklesImage + ')';
- function selectElement(elt, xml, libs, extUrl, infoObj, clibs, realUrl)
- {
- if (selectedElt != elt)
- {
- if (selectedElt != null)
- {
- selectedElt.style.backgroundColor = 'transparent';
- selectedElt.style.border = '2px solid transparent';
- if (selectedElt.getElementsByTagName('table').length > 0)
- {
- selectedElt.getElementsByTagName('table')[0].style.visibility = 'visible';
- }
- if (selectedElt == generateElt)
- {
- generateElt.style.backgroundImage = generateBackground;
- generateElt.style.backgroundPosition = 'center center';
- generateElt.style.backgroundRepeat = 'no-repeat';
- generateElt.style.backgroundSize = 'contain';
- generateInput.style.visibility = 'hidden';
- generateButton.style.visibility = 'hidden';
- helpGenerate.style.visibility = 'hidden';
- editGenerate.style.visibility = 'hidden';
- magnifyGenerate.style.visibility = (lastAiXml != null) ? 'visible' : 'hidden';
- generateElt.getElementsByTagName('table')[0].style.visibility = 'visible';
- }
- }
- if (elt.style.backgroundImage != '' && elt.getElementsByTagName('table').length > 0)
- {
- elt.getElementsByTagName('table')[0].style.visibility = 'hidden';
- }
- if (elt == generateElt)
- {
- xml = lastAiXml;
-
- if (xml != null)
- {
- magnifyGenerate.style.visibility = 'visible';
- magnifyGenerate.style.visibility = (lastAiXml != null) ? 'visible' : 'hidden';
- editGenerate.style.visibility = 'visible';
- }
- else
- {
- generateInput.style.visibility = 'visible';
- generateButton.style.visibility = 'visible';
- helpGenerate.style.visibility = 'visible';
- editGenerate.style.visibility = 'hidden';
- magnifyGenerate.style.visibility = 'hidden';
- }
- }
-
- createButton.removeAttribute('disabled');
- templateXml = xml;
- templateLibs = libs;
- templateClibs = clibs;
- selectedElt = elt;
- templateExtUrl = extUrl;
- templateRealUrl = realUrl;
- templateInfoObj = infoObj;
- selectedElt.style.border = rightHighlightBorder;
-
- return true;
- }
- else
- {
- return false;
- }
- };
- var generateInput = document.createElement('textarea');
- generateInput.setAttribute('placeholder', mxResources.get('describeYourDiagram'));
- generateInput.style.position = 'absolute';
- generateInput.style.fontFamily = 'sans-serif';
- generateInput.style.outline = 'none';
- generateInput.style.left = '0px';
- generateInput.style.right = '0px';
- generateInput.style.top = '0px';
- generateInput.style.bottom = '38px';
- generateInput.style.resize = 'none';
- generateInput.style.boxSizing = 'border-box';
- generateInput.style.fontSize = '12px';
- generateInput.style.border = 'none';
- generateInput.style.margin = '8px';
- var generateButton = document.createElement('button');
- generateButton.className = 'geBtn gePrimaryBtn';
- generateButton.style.position = 'absolute';
- generateButton.style.bottom = '0px';
- generateButton.style.height = '30px';
- generateButton.style.right = '0px';
- generateButton.style.left = '0px';
- generateButton.style.margin = '8px';
- generateButton.style.fontSize = '14px';
- generateButton.style.borderRadius = '4px';
- generateButton.setAttribute('disabled', 'disabled');
- generateButton.setAttribute('title', mxResources.get('ok'));
- mxUtils.write(generateButton, mxResources.get('ok'));
- var magnifyGenerate = magnifyImage.cloneNode(true);
- var generatePreviewWasVisible = false;
- var mouseDownHandler = function(evt)
- {
- generatePreviewWasVisible = editorUi.sidebar.tooltip != null &&
- editorUi.sidebar.tooltip.style.display != 'none';
- };
- var mouseUpHandler = function(evt)
- {
- if (!generatePreviewWasVisible && lastAiXml != null)
- {
- var previewXml = '<mxfile><diagram>' + Graph.compress(lastAiXml) + '</diagram></mxfile>';
- showTooltip(previewXml, mxEvent.getClientX(evt),
- mxEvent.getClientY(evt), generateElt,
- lastAiTitle);
- }
- };
-
- mxEvent.addGestureListeners(magnifyGenerate, mouseDownHandler, null, mouseUpHandler);
-
- var editGenerate = magnifyImage.cloneNode(true);
- editGenerate.setAttribute('src', Editor.editImage);
- editGenerate.setAttribute('title', mxResources.get('edit'));
- editGenerate.style.right = '';
- editGenerate.style.left = '2px';
- var helpGenerate = magnifyImage.cloneNode(true);
- helpGenerate.setAttribute('src', Editor.helpImage);
- helpGenerate.setAttribute('title', mxResources.get('help'));
- helpGenerate.style.opacity = '1';
- helpGenerate.style.right = '-8px';
- helpGenerate.style.top = '-8px';
- mxEvent.addListener(helpGenerate, 'click', function(evt)
- {
- editorUi.openLink('https://www.drawio.com/blog/write-query-generate-diagram');
- mxEvent.consume(evt);
- });
-
- generateInput.style.visibility = 'hidden';
- generateButton.style.visibility = 'hidden';
- editGenerate.style.visibility = 'hidden';
- helpGenerate.style.visibility = 'hidden';
- magnifyGenerate.style.visibility = 'hidden';
- function createGenerate()
- {
- generateElt.style.backgroundImage = '';
- generateElt.getElementsByTagName('table')[0].style.visibility = 'hidden';
- generateInput.style.visibility = 'visible';
- generateButton.style.visibility = 'visible';
- helpGenerate.style.visibility = 'visible';
- editGenerate.style.visibility = 'hidden';
- magnifyGenerate.style.visibility = 'hidden';
- generateInput.focus();
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- generateInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- };
- mxEvent.addListener(editGenerate, 'click', createGenerate);
- function updateGenerateButtonState()
- {
- if (generateInput.value != '')
- {
- generateButton.removeAttribute('disabled');
- }
- else
- {
- generateButton.setAttribute('disabled', 'disabled');
- }
- };
- mxEvent.addListener(generateInput, 'input', updateGenerateButtonState);
- function stopInput()
- {
- generateInput.style.visibility = 'hidden';
- generateButton.style.visibility = 'hidden';
- helpGenerate.style.visibility = 'hidden';
- generateElt.style.backgroundImage = generateBackground;
- generateElt.style.backgroundSize = 'contain';
- editGenerate.style.visibility = 'visible';
- magnifyGenerate.style.visibility = 'visible';
- };
- function generateDiagram(cancel)
- {
- var desc = mxUtils.trim(generateInput.value);
- if (!cancel && desc != '')
- {
- generateInput.style.visibility = 'hidden';
- generateButton.style.visibility = 'hidden';
- helpGenerate.style.visibility = 'hidden';
- var listenerTriggered = false;
- var prompt = 'Write a detailed and complex MermaidJS declaration for ' +
- '"' + (desc != '' ? desc : 'something random') + '" ' +
- 'using correct MermaidJS syntax and do not ' +
- 'provide additional text in your response.';
-
- if (typeof mxMermaidToDrawio !== 'undefined')
- {
- mxMermaidToDrawio.addListener(mxUtils.bind(this, function(modelXml)
- {
- if (modelXml != editorUi.emptyDiagramXml)
- {
- listenerTriggered = true;
- templateXml = modelXml;
- }
- }));
- }
- generateElt.style.backgroundImage = 'url(' + Editor.spinImage + ')';
- generateElt.style.backgroundSize = '12px 12px';
-
- editorUi.generateOpenAiMermaidDiagram(prompt,
- function(mermaidData, imageData, w, h)
- {
- if (selectedElt == generateElt && generateInput.style.visibility == 'hidden')
- {
- generateBackground = 'url(' + 'data:image/svg+xml;base64,' +
- imageData.substring(imageData.indexOf(',') + 1) + ')';
- generateElt.setAttribute('title', desc);
- // Updates template XML for insert button
- var xml = (listenerTriggered) ? templateXml :
- editorUi.createMermaidXml(mermaidData,
- EditorUi.defaultMermaidConfig,
- imageData, w, h, desc);
- templateXml = xml;
- lastAiXml = xml;
- lastAiTitle = desc;
- stopInput();
- }
- }, function(e)
- {
- if (selectedElt == generateElt)
- {
- generateInput.style.visibility = 'visible';
- generateButton.style.visibility = 'visible';
- helpGenerate.style.visibility = 'visible';
- editGenerate.style.visibility = 'visible';
- magnifyGenerate.style.visibility = 'visible';
- editorUi.handleError(e);
- }
- }
- );
- }
- else if (lastAiTitle != null)
- {
- generateInput.value = lastAiTitle;
- stopInput();
- }
- };
- mxEvent.addListener(generateButton, 'click', function()
- {
- generateDiagram();
- });
- mxEvent.addListener(generateInput, 'keydown', function(evt)
- {
- if (evt.keyCode == 13 && !mxEvent.isShiftDown(evt))
- {
- generateDiagram();
- mxEvent.consume(evt);
- }
- else if (evt.keyCode == 27)
- {
- generateDiagram(true);
- mxEvent.consume(evt);
- }
- });
- function addButton(url, libs, title, tooltip, select, imgUrl, infoObj, onClick, preview, noImg, clibs, templateType)
- {
- var elt = null;
- if (templateType != 'generative' || generateElt == null)
- {
- elt = document.createElement('div');
- elt.className = 'geTemplate geAdaptiveAsset';
- elt.style.backgroundOrigin = 'content-box';
- elt.style.backgroundPosition = 'center center';
- elt.style.backgroundRepeat = 'no-repeat';
- elt.style.backgroundSize = 'contain';
- elt.style.boxSizing = 'border-box';
- elt.style.borderRadius = '12px';
- elt.style.position = 'relative';
- elt.style.height = w + 'px';
- elt.style.width = h + 'px';
- elt.style.padding = '4px';
- elt.style.border = '2px solid transparent';
- var xmlData = null, realUrl = url;
-
- if (title != null)
- {
- elt.setAttribute('title', mxResources.get(title, null, title));
- }
- else if (tooltip != null && tooltip.length > 0)
- {
- elt.setAttribute('title', tooltip);
- }
- }
- else
- {
- elt = generateElt;
- }
-
- function loadXmlData(url, callback)
- {
- if (xmlData == null)
- {
- realUrl = url;
-
- if (/^https?:\/\//.test(realUrl))
- {
- realUrl = editorUi.editor.isCorsEnabledForUrl(realUrl) ? realUrl :
- PROXY_URL + '?url=' + encodeURIComponent(realUrl);
- }
- else
- {
- realUrl = TEMPLATE_PATH + '/' + realUrl;
- }
-
- mxUtils.get(realUrl, mxUtils.bind(this, function(req)
- {
- if (req.getStatus() >= 200 && req.getStatus() <= 299)
- {
- xmlData = req.getText();
- callback(xmlData, realUrl);
- }
- else
- {
- callback(xmlData, realUrl);
- }
- }));
- }
- else
- {
- callback(xmlData, realUrl);
- }
- };
- function loadTooltip(evt, tooltipTitle)
- {
- if (url != null && !loading && editorUi.sidebar.currentElt != elt)
- {
- editorUi.sidebar.hideTooltip();
-
- if (extImg != null)
- {
- //Create a diagram with the image to use the same code
- //Note: Without compression it doesn't work for some reason. Find out why later
- var xml = '<mxfile><diagram>' + Graph.compress('<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/>' +
- '<mxCell id="2" value="" style="shape=image;image=' + extImg.src + ';imageAspect=1;" parent="1" vertex="1">' +
- '<mxGeometry width="' + extImg.naturalWidth + '" height="' + extImg.naturalHeight + '" as="geometry" />' +
- '</mxCell></root></mxGraphModel>') + '</diagram></mxfile>';
- showTooltip(xml, mxEvent.getClientX(evt), mxEvent.getClientY(evt), title, url);
- return;
- }
-
- editorUi.sidebar.currentElt = elt;
- loading = true;
-
- loadXmlData(url, function(xml)
- {
- if (loading && editorUi.sidebar.currentElt == elt)
- {
- try
- {
- showTooltip(xml, mxEvent.getClientX(evt),
- mxEvent.getClientY(evt), elt,
- tooltipTitle);
- }
- catch (e)
- {
- editorUi.sidebar.currentElt = null;
- editorUi.handleError(e);
- }
- }
-
- loading = false;
- });
- }
- else
- {
- editorUi.sidebar.hideTooltip();
- }
- };
- function createTable()
- {
- var table = document.createElement('table');
- table.setAttribute('width', '100%');
- table.setAttribute('height', '100%');
- table.style.background = Editor.isDarkMode() ? 'transparent' : 'rgba(255,255,255,0.85)';
- table.style.lineHeight = '1.3em';
- table.style.border = 'none';
- var tbody = document.createElement('tbody');
- var row = document.createElement('tr');
- var td = document.createElement('td');
- td.setAttribute('align', 'center');
- td.setAttribute('valign', 'middle');
- var span = document.createElement('span');
- span.style.display = 'inline-block';
- span.style.padding = '2px 8px';
- span.style.userSelect = 'none';
- span.style.borderRadius = '8px';
- span.style.background = 'rgba(255,255,255,0.7)';
- span.style.overflow = 'hidden';
- span.style.textOverflow = 'ellipsis';
- span.style.maxWidth = (w - 34) + 'px';
- mxUtils.write(span, mxResources.get(title, null, title));
- td.appendChild(span);
- row.appendChild(td);
- tbody.appendChild(row);
- table.appendChild(tbody);
- return table;
- };
- if (imgUrl != null)
- {
- elt.style.display = 'inline-flex';
- elt.style.justifyContent = 'center';
- elt.style.alignItems = 'center';
- var img = document.createElement('img');
- img.setAttribute('src', imgUrl);
- img.setAttribute('alt', tooltip);
- img.style.maxWidth = w + 'px';
- img.style.maxHeight = h + 'px';
- extImg = img;
-
- var fallbackImgUrl = imgUrl.replace('.drawio.xml', '').replace('.drawio', '').replace('.xml', '');
- elt.appendChild(img);
-
- img.onerror = function()
- {
- if (this.src != fallbackImgUrl)
- {
- this.src = fallbackImgUrl;
- }
- else
- {
- this.src = Editor.errorImage;
- this.onerror = null;
- }
- };
-
- mxEvent.addGestureListeners(elt, mxUtils.bind(this, function(evt)
- {
- selectElement(elt, null, null, url, infoObj, clibs);
- }), null, null);
-
- mxEvent.addListener(elt, 'dblclick', function(evt)
- {
- create();
- mxEvent.consume(evt);
- });
- }
- else if (!noImg && url != null && url.length > 0)
- {
- var png = preview || (TEMPLATE_PATH + '/' + url.substring(0, url.length - 4) + '.png');
- elt.style.backgroundImage = 'url(' + png + ')';
-
- if (title != null)
- {
- elt.appendChild(createTable());
- }
-
- function activate(doCreate)
- {
- if (spinner.spin(div))
- {
- loadXmlData(url, function(xml, realUrl)
- {
- spinner.stop();
-
- if (xml != null)
- {
- selectElement(elt, xml, libs, null, null, clibs, realUrl);
-
- if (doCreate)
- {
- create();
- }
- }
- });
- }
- };
-
- mxEvent.addGestureListeners(elt, mxUtils.bind(this, function(evt)
- {
- activate();
- }), null, null);
- mxEvent.addListener(elt, 'dblclick', function(evt)
- {
- activate(true);
- mxEvent.consume(evt);
- });
- }
- else
- {
- elt.appendChild(createTable());
- if (templateType == 'generative' && generateElt == null)
- {
- elt.style.backgroundImage = generateBackground;
- elt.style.overflow = 'visible';
- elt.appendChild(magnifyGenerate);
- elt.appendChild(editGenerate);
- elt.appendChild(generateInput);
- elt.appendChild(generateButton);
- elt.appendChild(helpGenerate);
- generateElt = elt;
- }
- if (select)
- {
- selectElement(elt);
- }
- if (onClick != null)
- {
- mxEvent.addGestureListeners(elt, null, null, mxUtils.bind(this, function(evt)
- {
- selectElement(elt, null, null, url, infoObj);
- }));
-
- mxEvent.addListener(elt, 'click', onClick);
- }
- else
- {
- mxEvent.addListener(elt, 'click', function(evt)
- {
- if (selectElement(elt, null, null, url, infoObj) && templateType == 'generative')
- {
- if (lastAiXml == null)
- {
- createGenerate();
- }
- }
- });
- mxEvent.addListener(elt, 'dblclick', function(evt)
- {
- if (templateType != 'generative')
- {
- create();
- }
- else if (generateInput.style.visibility == 'hidden')
- {
- createGenerate();
- }
-
- mxEvent.consume(evt);
- });
- }
- }
-
- // Adds preview button
- if (url != null)
- {
- var magnify = magnifyImage.cloneNode(true);
- elt.appendChild(magnify);
-
- mxEvent.addGestureListeners(magnify, mxUtils.bind(this, function(evt)
- {
- wasVisible = editorUi.sidebar.currentElt == elt;
- }), null, null);
-
- mxEvent.addListener(magnify, 'click', mxUtils.bind(this, function(evt)
- {
- if (!wasVisible)
- {
- loadTooltip(evt, (title != null) ? title : tooltip);
- }
-
- mxEvent.consume(evt);
- }));
- }
- div.appendChild(elt);
- return elt;
- };
- var categories = {}, subCategories = {}, customCats = {};
- var customCatCount = 0, firstInitUi = true;
- var currentEntry = null, lastEntry = null;
- // Adds local basic templates
- categories['basic'] = [{title: 'blankDiagram'}];
- var templates = categories['basic'];
- if (Editor.enableChatGpt &&
- editorUi.isExternalDataComms() &&
- editorUi.getServiceName() == 'draw.io' &&
- typeof mxMermaidToDrawio !== 'undefined' &&
- window.isMermaidEnabled)
- {
- categories['basic'].push({title: 'generate', type: 'generative'});
- }
-
- if (Editor.enableChatGpt &&
- editorUi.isExternalDataComms() &&
- editorUi.getServiceName() == 'draw.io' &&
- typeof mxMermaidToDrawio !== 'undefined' &&
- window.isMermaidEnabled)
- {
- categories['smartTemplate'] = {content: createSmartTemplateContent()};
- }
-
- function resetTemplates()
- {
- if (lastEntry != null)
- {
- lastEntry.click();
- lastEntry = null;
- }
- };
-
- function filterTemplates()
- {
- var searchTerms = tmplSearchInput.value;
-
- if (searchTerms == '')
- {
- resetTemplates();
- return;
- }
-
- if (NewDialog.tagsList[templateFile] == null)
- {
- var tagsList = {};
-
- for (var cat in categories)
- {
- if (categories[cat].content == null)
- {
- var templateList = categories[cat];
-
- for (var i = 0; i < templateList.length; i++)
- {
- var temp = templateList[i];
-
- if (temp.tags != null)
- {
- var tags = temp.tags.toLowerCase().split(';');
-
- for (var j = 0; j < tags.length; j++)
- {
- if (tagsList[tags[j]] == null)
- {
- tagsList[tags[j]] = [];
- }
-
- tagsList[tags[j]].push(temp);
- }
- }
- }
- }
- }
-
- NewDialog.tagsList[templateFile] = tagsList;
- }
- var tmp = searchTerms.toLowerCase().split(' ');
- tagsList = NewDialog.tagsList[templateFile];
-
- if (customCatCount > 0 && tagsList.__tagsList__ == null)
- {
- for (var cat in customCats)
- {
- var templateList = customCats[cat];
-
- for (var i = 0; i < templateList.length; i++)
- {
- var temp = templateList[i];
- var tags = temp.title.split(' ');
- tags.push(cat);
-
- for (var j = 0; j < tags.length; j++)
- {
- var tag = tags[j].toLowerCase();
-
- if (tagsList[tag] == null)
- {
- tagsList[tag] = [];
- }
-
- tagsList[tag].push(temp);
- }
- }
- }
-
- tagsList.__tagsList__ = true;
- }
-
- var results = [], resMap = {}, index = 0;
-
- for (var i = 0; i < tmp.length; i++)
- {
- if (tmp[i].length > 0)
- {
- var list = tagsList[tmp[i]];
- var tmpResMap = {};
- results = [];
-
- if (list != null)
- {
- for (var j = 0; j < list.length; j++)
- {
- var temp = list[j];
-
- //ANDing terms
- if ((index == 0) == (resMap[temp.url] == null))
- {
- tmpResMap[temp.url] = true;
- results.push(temp);
- }
- }
- }
-
- resMap = tmpResMap;
- index++;
- }
- }
-
- div.scrollTop = 0;
- div.innerText = '';
- i0 = 0;
- var msgDiv = document.createElement('div');
- msgDiv.style.cssText = 'border: 1px solid #D3D3D3; padding: 6px; background: #F5F5F5;';
- mxUtils.write(msgDiv, mxResources.get(results.length == 0 ? 'noResultsFor' : 'resultsFor', [searchTerms]));
- div.appendChild(msgDiv);
- if (currentEntry != null && lastEntry == null)
- {
- currentEntry.style.backgroundColor = '';
- lastEntry = currentEntry;
- currentEntry = msgDiv; //To prevebt NPE later
- }
- templates = results;
- oldTemplates = null;
- addTemplates(false);
- };
-
- function initUi()
- {
- if (firstInitUi)
- {
- firstInitUi = false;
-
- mxEvent.addListener(div, 'scroll', function(evt)
- {
- if (div.scrollTop + div.clientHeight >= div.scrollHeight)
- {
- addTemplates();
- mxEvent.consume(evt);
- }
- });
- }
- if (customCatCount > 0)
- {
- var titleCss = 'font-weight: bold;background: #f9f9f9;padding: 5px 0 5px 0;text-align: center;';
- var title = document.createElement('div');
- title.style.cssText = titleCss;
- mxUtils.write(title, mxResources.get('custom'));
- list.appendChild(title);
-
- for (var cat in customCats)
- {
- var entry = document.createElement('div');
- var label = cat;
- var templateList = customCats[cat];
-
- if (label.length > 18)
- {
- label = label.substring(0, 18) + '…';
- }
-
- entry.style.cssText = 'display:block;cursor:pointer;padding:6px;white-space:nowrap;margin-bottom:-1px;overflow:hidden;text-overflow:ellipsis;user-select:none;';
- entry.setAttribute('title', label + ' (' + templateList.length + ')');
- mxUtils.write(entry, entry.getAttribute('title'));
-
- if (itemPadding != null)
- {
- entry.style.padding = itemPadding;
- }
- list.appendChild(entry);
-
- (function(cat2, entry2)
- {
- mxEvent.addListener(entry, 'click', function()
- {
- if (currentEntry != entry2)
- {
- currentEntry.style.backgroundColor = '';
- currentEntry = entry2;
- currentEntry.style.backgroundColor = leftHighlight;
-
- div.scrollTop = 0;
- div.innerText = '';
- i0 = 0;
-
- templates = customCats[cat2];
- oldTemplates = null;
- addTemplates(false);
- }
- });
- })(cat, entry);
- }
-
- title = document.createElement('div');
- title.style.cssText = titleCss;
- mxUtils.write(title, 'draw.io');
- list.appendChild(title);
- }
-
- function getEntryTitle(cat, templateList)
- {
- var label = mxResources.get(cat, null,
- cat.substring(0, 1).toUpperCase() +
- cat.substring(1));
-
- if (label.length > 18)
- {
- label = label.substring(0, 18) + '…';
- }
-
- return label + ((templateList != null) ?
- ' (' + templateList.length + ')' : '');
- };
-
- function addEntryHandler(cat, entry, subCat)
- {
- mxEvent.addListener(entry, 'click', function()
- {
- if (currentEntry != entry)
- {
- if (currentEntry != null)
- {
- currentEntry.style.backgroundColor = '';
- }
-
- currentEntry = entry;
- currentEntry.style.backgroundColor = leftHighlight;
- div.scrollTop = 0;
- div.innerText = '';
- i0 = 0;
- if (categories[cat].content != null)
- {
- div.appendChild(categories[cat].content);
- templateXml = lastAiXml;
- templates = null;
- if (categories[cat].content.init != null)
- {
- categories[cat].content.init();
- }
- }
- else
- {
- templates = subCat? subCategories[cat][subCat] : categories[cat];
- oldTemplates = null;
- addTemplates(false);
- }
- }
- });
-
- // Selects smart template section
- if (urlParams['smart-template'] != null && cat == 'smartTemplate')
- {
- entry.click();
- }
- };
-
- for (var cat in categories)
- {
- var templateList = null;
- var clickElem = null;
- if (categories[cat].content != null)
- {
- var entry = document.createElement(subCats? 'ul' : 'div');
- var title = getEntryTitle(cat);
- 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;';
- entry.setAttribute('title', title);
- mxUtils.write(entry, title);
- list.appendChild(entry);
- clickElem = entry;
- }
- else
- {
- var subCats = subCategories[cat];
- var entry = document.createElement(subCats? 'ul' : 'div');
- var clickElem = entry;
- templateList = categories[cat];
- var entryTitle = getEntryTitle(cat, templateList);
-
- if (subCats != null)
- {
- var entryLi = document.createElement('li');
- var entryDiv = document.createElement('div');
- entryDiv.className = 'geTempTreeCaret';
- entryDiv.setAttribute('title', entryTitle);
- mxUtils.write(entryDiv, entryTitle);
- clickElem = entryDiv;
- entryLi.appendChild(entryDiv);
- //We support one level deep only
- var subUl = document.createElement('ul');
- subUl.className = 'geTempTreeNested';
- subUl.style.visibility = 'hidden';
-
- for (var subCat in subCats)
- {
- var subLi = document.createElement('li');
- var subTitle = getEntryTitle(subCat, subCats[subCat]);
- subLi.setAttribute('title', subTitle);
- mxUtils.write(subLi, subTitle);
- addEntryHandler(cat, subLi, subCat);
- subUl.appendChild(subLi);
- }
-
- entryLi.appendChild(subUl);
- entry.className = 'geTempTree';
- entry.appendChild(entryLi);
-
- (function(subUl2, entryDiv2)
- {
- mxEvent.addListener(entryDiv2, 'click', function()
- {
- subUl2.style.visibility = 'visible';
- subUl2.classList.toggle('geTempTreeActive');
-
- if (subUl2.classList.toggle('geTempTreeNested'))
- {
- //Must hide sub elements to allow click on elements above it
- setTimeout(function()
- {
- subUl2.style.visibility = 'hidden';
- }, 550);
- }
-
- entryDiv2.classList.toggle('geTempTreeCaret-down');
- });
- })(subUl, entryDiv);
- }
- else
- {
- 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;';
- entry.setAttribute('title', entryTitle);
- mxUtils.write(entry, entryTitle);
- }
-
- if (itemPadding != null)
- {
- entry.style.padding = itemPadding;
- }
- list.appendChild(entry);
- }
- addEntryHandler(cat, clickElem);
- if (currentEntry == null)
- {
- clickElem.click();
- }
- }
-
- addTemplates(false);
- };
- if (!compact)
- {
- outer.appendChild(searchBox);
- outer.appendChild(list);
- outer.appendChild(div);
- var indexLoaded = false;
- var realUrl = templateFile;
-
- if (/^https?:\/\//.test(realUrl) && !editorUi.editor.isCorsEnabledForUrl(realUrl))
- {
- realUrl = PROXY_URL + '?url=' + encodeURIComponent(realUrl);
- }
-
- function loadDrawioTemplates()
- {
- mxUtils.get(realUrl, function(req)
- {
- // Workaround for index loaded 3 times in iOS offline mode
- if (!indexLoaded)
- {
- indexLoaded = true;
- var tmpDoc = req.getXml();
- var node = tmpDoc.documentElement.firstChild;
- var clibs = {};
-
- while (node != null)
- {
- if (typeof(node.getAttribute) !== 'undefined')
- {
- if (node.nodeName == 'parsererror')
- {
- if (window.console != null)
- {
- console.log('Parser error in ' +
- templateFile + ': ' +
- node.textContent);
- }
- }
- else if (node.nodeName == 'clibs')
- {
- var name = node.getAttribute('name');
- var adds = node.getElementsByTagName('add');
- var temp = [];
-
- for (var i = 0; i < adds.length; i++)
- {
- temp.push(encodeURIComponent(mxUtils.getTextContent(adds[i])));
- }
-
- if (name != null && temp.length > 0)
- {
- clibs[name] = temp.join(';');
- }
- }
- else
- {
- var url = node.getAttribute('url');
-
- if (url != null)
- {
- var category = node.getAttribute('section');
- var subCategory = node.getAttribute('subsection');
-
- if (category == null)
- {
- var slash = url.indexOf('/');
- category = url.substring(0, slash);
-
- if (subCategory == null)
- {
- var nextSlash = url.indexOf('/', slash + 1);
-
- if (nextSlash > -1)
- {
- subCategory = url.substring(slash + 1, nextSlash);
- }
- }
- }
-
- var list = categories[category];
-
- if (list == null)
- {
- list = [];
- categories[category] = list;
- }
-
- var tempLibs = node.getAttribute('clibs');
-
- if (clibs[tempLibs] != null)
- {
- tempLibs = clibs[tempLibs];
- }
-
- var tempObj = {url: node.getAttribute('url'), libs: node.getAttribute('libs'),
- title: node.getAttribute('title'), tooltip: node.getAttribute('name') || node.getAttribute('url'),
- preview: node.getAttribute('preview'), clibs: tempLibs, tags: node.getAttribute('tags')};
- list.push(tempObj);
-
- if (subCategory != null)
- {
- var subCats = subCategories[category];
-
- if (subCats == null)
- {
- subCats = {};
- subCategories[category] = subCats;
- }
-
- var subCatList = subCats[subCategory];
-
- if (subCatList == null)
- {
- subCatList = [];
- subCats[subCategory] = subCatList;
- }
-
- subCatList.push(tempObj);
- }
- }
- }
- }
-
- node = node.nextSibling;
- }
-
-
- spinner.stop();
- initUi();
- }
- });
- };
-
- spinner.spin(div);
-
- if (customTempCallback != null)
- {
- customTempCallback(function(cats, count)
- {
- customCats = cats;
- customCatCount = count;
- //Custom templates doesn't change after being loaded, so cache them here. Also, only count is overridden
- origCustomCatCount = count;
- loadDrawioTemplates();
- },
-
- loadDrawioTemplates); //In case of an error, just load draw.io templates only
- }
- else
- {
- loadDrawioTemplates();
- }
-
- //draw.io templates doesn't change after being loaded, so cache them here
- origCategories = categories;
- }
-
- mxEvent.addListener(nameInput, 'keypress', function(e)
- {
- if (editorUi.dialog.container.firstChild == outer &&
- e.keyCode == 13)
- {
- create();
- }
- });
-
- var btns = document.createElement('div');
- btns.style.marginTop = (compact) ? '4px' : '16px';
- btns.style.textAlign = 'right';
- btns.style.position = 'absolute';
- btns.style.left = '40px';
- btns.style.bottom = '24px';
- btns.style.right = '40px';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- if (cancelCallback != null)
- {
- cancelCallback();
- }
-
- editorUi.hideDialog(true);
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst && (!createOnly || cancelCallback != null))
- {
- btns.appendChild(cancelBtn);
- }
- if (!compact && urlParams['embed'] != '1' && !createOnly && !mxClient.IS_ANDROID &&
- !mxClient.IS_IOS && urlParams['noDevice'] != '1')
- {
- var fromTmpBtn = mxUtils.button(mxResources.get('fromTemplateUrl'), function()
- {
- var dlg = new FilenameDialog(editorUi, '', mxResources.get('create'), function(fileUrl)
- {
- if (fileUrl != null && fileUrl.length > 0)
- {
- editorUi.editor.loadUrl(editorUi.editor.getProxiedUrl(fileUrl), function(data)
- {
- templateXml = data;
- templateLibs = null;
- templateRealURl = fileUrl;
- editorUi.hideDialog();
- create();
- }, function(err)
- {
- editorUi.handleError(err);
- });
- }
- }, mxResources.get('url'), null, null, null, false);
- editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
- });
-
- fromTmpBtn.className = 'geBtn';
- btns.appendChild(fromTmpBtn);
- }
-
- if (Graph.fileSupport && showImport)
- {
- var importBtn = mxUtils.button(mxResources.get('import'), function()
- {
- if (editorUi.newDlgFileInputElt == null)
- {
- var fileInput = document.createElement('input');
- fileInput.setAttribute('multiple', 'multiple');
- fileInput.setAttribute('type', 'file');
-
- mxEvent.addListener(fileInput, 'change', function(evt)
- {
- editorUi.openFiles(fileInput.files, true);
- fileInput.value = '';
- });
-
- fileInput.style.display = 'none';
- document.body.appendChild(fileInput);
- editorUi.newDlgFileInputElt = fileInput;
- }
-
- editorUi.newDlgFileInputElt.click();
- });
-
- importBtn.className = 'geBtn';
- btns.appendChild(importBtn);
- }
-
- btns.appendChild(createButton);
-
- if (!editorUi.editor.cancelFirst && callback == null && (!createOnly || cancelCallback != null))
- {
- btns.appendChild(cancelBtn);
- }
-
- outer.appendChild(btns);
-
- this.container = outer;
- };
- NewDialog.tagsList = {};
- /**
- *
- */
- var SaveDialog = function(editorUi, title, saveFn, disabledModes, data, mimeType, base64Encoded, defaultMode)
- {
- var div = document.createElement('div');
- div.style.display = 'flex';
- div.style.flexWrap = 'wrap';
- div.style.whiteSpace = 'nowrap';
- var table = document.createElement('div');
- table.style.display = 'grid';
- table.style.gap = '5px 8px';
- table.style.gridAutoRows = 'auto auto 44px';
- table.style.gridAutoColumns = '0fr minmax(0,1fr)';
- table.style.width = '100%';
- var preview = null;
- var copyBtn = null;
- // Disables SVG preview if SVG is not supported in browser
- if (data != null && mimeType != null && (mimeType.substring(0, 6) == 'image/' &&
- (mimeType.substring(0, 9) != 'image/svg' || mxClient.IS_SVG)))
- {
- table.style.display = 'inline-grid';
- table.style.flexBasis = '75%';
- preview = document.createElement('div');
- preview.style.display = 'inline-block';
- preview.style.height = 'auto';
- preview.style.maxWidth = '25%';
- preview.style.margin = 'auto';
- var img = document.createElement('img');
- var temp = (base64Encoded) ? data : btoa(unescape(encodeURIComponent(data)));
- img.setAttribute('src', 'data:' + mimeType + ';base64,' + temp);
- img.style.boxSizing = 'border-box';
- img.style.maxHeight = '50px';
- img.style.maxWidth = '100%';
- img.style.paddingLeft = '10px';
- preview.appendChild(img);
- if (!mxClient.IS_FF && mimeType == 'image/png' && navigator.clipboard != null &&
- typeof window.ClipboardItem === 'function')
- {
- copyBtn = mxUtils.button(mxResources.get('copy'), function()
- {
- var blob = editorUi.base64ToBlob(temp, 'image/png');
- var html = '<img src="' + 'data:' + mimeType + ';base64,' + temp + '">';
- var cbi = new ClipboardItem({'image/png': blob,
- 'text/html': new Blob([html], {type: 'text/html'})});
- navigator.clipboard.write([cbi]).then(mxUtils.bind(this, function()
- {
- editorUi.alert(mxResources.get('copiedToClipboard'));
- }))['catch'](mxUtils.bind(this, function(e)
- {
- editorUi.handleError(e);
- }));
- }, null, 'geBtn');
- }
- if (Editor.popupsAllowed && (disabledModes == null ||
- mxUtils.indexOf(disabledModes, '_blank') < 0))
- {
- preview.setAttribute('title', mxResources.get('openInNewWindow'));
- preview.style.cursor = 'pointer';
-
- mxEvent.addGestureListeners(preview, null, null, function(evt)
- {
- if (!mxEvent.isPopupTrigger(evt))
- {
- editorUi.openInNewWindow(data, mimeType, base64Encoded);
- }
- });
- }
- else
- {
- preview.setAttribute('title', mxResources.get('preview'));
- }
- }
-
- var left = document.createElement('div');
- left.style.display = 'flex';
- left.style.padding = '1px';
- left.style.alignItems = 'center';
- left.style.justifyContent = 'flex-end';
- left.style.gridColumn = '1';
- left.style.whiteSpace = 'nowrap';
- var right = document.createElement('div');
- right.style.display = 'grid';
- right.style.padding = '1px';
- right.style.alignItems = 'center';
- right.style.gridColumn = '2';
- right.style.gridAutoColumns = 'minmax(0,1fr) auto';
- right.style.gap = '6px';
-
- mxUtils.write(left, mxResources.get('saveAs') + ':');
- var saveAsInput = document.createElement('input');
- saveAsInput.setAttribute('type', 'text');
- saveAsInput.setAttribute('value', title);
- saveAsInput.style.boxSizing = 'border-box';
- saveAsInput.style.width = '100%';
- right.appendChild(saveAsInput);
- table.appendChild(left);
- table.appendChild(right);
- var typeSelect = null;
- if (editorUi.editor.diagramFileTypes != null && mimeType == null)
- {
- left = left.cloneNode(false);
- right = right.cloneNode(false);
- mxUtils.write(left, mxResources.get('type') + ':');
-
- typeSelect = FilenameDialog.createFileTypes(editorUi, saveAsInput,
- editorUi.editor.diagramFileTypes);
- typeSelect.style.boxSizing = 'border-box';
- typeSelect.style.width = '100%';
- right.appendChild(typeSelect);
- table.appendChild(left);
- table.appendChild(right);
- }
-
- left = left.cloneNode(false);
- right = right.cloneNode(false);
- mxUtils.write(left, mxResources.get('where') + ':');
- var storageSelect = document.createElement('select');
- storageSelect.style.textOverflow = 'ellipsis';
- storageSelect.style.gridColumn = '1';
- var resetOption = document.createElement('option');
- mxUtils.write(resetOption, mxResources.get('reset'));
- resetOption.setAttribute('value', 'reset');
- var localServices = ['browser', 'device', 'download', '_blank'];
- var dash = ' – ';
- var dashNode = document.createElement('option');
- dashNode.setAttribute('disabled', 'disabled');
- dashNode.innerHTML = '-----------------';
- function addStorageEntry(mode, path, id, selected, title, entryType)
- {
- var option = null;
- if (disabledModes == null || mxUtils.indexOf(disabledModes, mode) < 0)
- {
- title = (title != null) ? title : editorUi.getTitleForService(mode);
- if (mxUtils.indexOf(localServices, mode) >= 0 ||
- editorUi.getServiceForName(mode) != null)
- {
- option = document.createElement('option');
- if (entryType == 'pick')
- {
- option.innerHTML = mxUtils.htmlEntities(title) + dash +
- mxUtils.htmlEntities(mxResources.get('pickFolder')) + '...';
- option.setAttribute('value', 'pickFolder-' + mode);
- option.setAttribute('title', title + ' - ' +
- mxResources.get('pickFolder') + '...');
- }
- else
- {
- var entryId = mode + ((id != null) ? ('-' + id) : '');
- var entry = entries[entryId];
- if (entry != null && entry.option != null)
- {
- entry.option.parentNode.removeChild(entry.option);
- }
- var shortPath = null;
- if (path != null)
- {
- if (path.charAt(path.length - 1) == '/')
- {
- path = path.substring(0, path.length - 1);
- }
- if (path.charAt(0) == '/')
- {
- path = path.substring(1);
- }
- shortPath = path;
- if (mode != App.MODE_GITHUB && mode == App.MODE_GITLAB)
- {
- var idx = shortPath.lastIndexOf('/');
- if (idx >= 0)
- {
- shortPath = shortPath.substring(idx + 1);
- }
- }
-
- if (shortPath.length > 40)
- {
- shortPath = shortPath.substring(0, 20) + '...' +
- shortPath.substring(shortPath.length - 20);
- }
- }
- option.innerHTML = mxUtils.htmlEntities(title) + ((shortPath != null) ?
- dash + mxUtils.htmlEntities(shortPath) : '');
- option.setAttribute('title', title + ((path != null) ? ' (' + path + ')' : '') +
- ((id != null && decodeURIComponent(id) != path) ? ' [' + id + ']' : ''));
- option.setAttribute('value', entryId);
- entries[entryId] = {option: option, mode: mode, path: path, id: id};
- if (SaveDialog.lastValue == entryId && defaultMode == null)
- {
- selected = true;
- }
- else if (selected == null)
- {
- if (entryType == 'root')
- {
- selected = (defaultMode == null && editorUi.mode == mode) ||
- (mode != null && mode == defaultMode);
- }
- else if (storageSelect.value.substring(0, 11) == 'pickFolder-')
- {
- selected = true;
- }
- }
- if (selected)
- {
- option.setAttribute('selected', 'selected');
- }
- }
- storageSelect.appendChild(option);
- }
- }
- return option;
- };
- var defaultValue = null;
- function pickFolder(mode)
- {
- editorUi.pickFolder(mode, function(result)
- {
- var entry = null;
- if (mode == App.MODE_GOOGLE && result.docs != null && result.docs.length > 0)
- {
- entry = {mode: mode, path: result.docs[0].name, id: result.docs[0].id};
- }
- else if (mode == App.MODE_ONEDRIVE && result.value != null && result.value.length > 0)
- {
- entry = {mode: mode, path: result.value[0].name,
- id: OneDriveFile.prototype.getIdOf(result.value[0])};
- }
- else if ((mode == App.MODE_GITHUB || mode == App.MODE_GITLAB) &&
- result != null && result.length > 0)
- {
- entry = {mode: mode, path: decodeURIComponent(result), id: result};
- }
- if (entry != null)
- {
- resetOption.style.display = '';
- editorUi.addRecent(entry, 'Folders', 5);
- var option = addStorageEntry(entry.mode, entry.path, entry.id, true);
- storageSelect.innerHTML = '';
- entries = {};
- addStorageEntries();
- // Selects new entry
- var prev = storageSelect.selectedIndex;
- storageSelect.value = option.value;
- // Checks if entry exists
- // LATER: Pass value to select to addStorageEntries
- if (storageSelect.selectedIndex < 0)
- {
- storageSelect.selectedIndex = prev;
- }
- }
- }, true, true, true, true);
- };
- var entries = {};
-
- function checkExtension()
- {
- if (typeSelect != null && entries[storageSelect.value] != null &&
- editorUi.editor.diagramFileTypes != null &&
- editorUi.editor.diagramFileTypes[typeSelect.value].extension == 'drawio')
- {
- var ext = editorUi.getExtensionForService(entries[storageSelect.value].mode);
- var name = saveAsInput.value;
- if (ext != null && title.indexOf('.') < 0 &&
- name.indexOf('.') < 0)
- {
- saveAsInput.value = name + ext;
- }
- }
- };
- function addStorageEntries()
- {
- var recent = editorUi.getRecent('Folders');
- var recentCount = 0;
- if (recent != null && recent.length > 0)
- {
- for (var i = 0; i < recent.length; i++)
- {
- if (addStorageEntry(recent[i].mode, recent[i].path, recent[i].id) != null)
- {
- recentCount++;
- }
- }
- if (recentCount > 0)
- {
- storageSelect.appendChild(dashNode.cloneNode(true));
- }
- }
- addStorageEntry(App.MODE_GOOGLE, mxResources.get('myDrive'),
- 'root', null, null, 'root');
- addStorageEntry(App.MODE_GOOGLE, null, null, null, null, 'pick');
- if (editorUi.oneDrive != null)
- {
- addStorageEntry(App.MODE_ONEDRIVE, mxResources.get('myFiles'),
- OneDriveFile.prototype.getIdOf(editorUi.oneDrive.rootId),
- null, null, 'root');
- addStorageEntry(App.MODE_ONEDRIVE, null, null, null, null, 'pick');
- }
-
- if (editorUi.dropbox != null)
- {
- addStorageEntry(App.MODE_DROPBOX, 'Apps' + editorUi.dropbox.appPath);
- }
- addStorageEntry(App.MODE_GITHUB, null, null, null, null, 'pick');
- addStorageEntry(App.MODE_GITLAB, null, null, null, null, 'pick');
- addStorageEntry(App.MODE_TRELLO);
- var allowDevice = !Editor.useLocalStorage || urlParams['storage'] == 'device' ||
- (editorUi.getCurrentFile() != null && urlParams['noDevice'] != '1');
- if (EditorUi.nativeFileSupport && allowDevice)
- {
- addStorageEntry(App.MODE_DEVICE, null, null, editorUi.mode == App.MODE_DEVICE ||
- (disabledModes != null && mxUtils.indexOf(disabledModes,
- App.MODE_BROWSER) >= 0) ? true : null);
- }
-
- if (isLocalStorage && urlParams['browser'] != '0')
- {
- addStorageEntry(App.MODE_BROWSER);
- }
- if (allowDevice)
- {
- addStorageEntry('download');
- }
-
- if (Editor.popupsAllowed)
- {
- addStorageEntry('_blank', null, null, null, mxResources.get('openInNewWindow'));
- }
- if (recentCount > 0)
- {
- storageSelect.appendChild(dashNode.cloneNode(true));
- var prev = storageSelect.value;
- storageSelect.appendChild(resetOption);
- storageSelect.value = prev;
- }
- // Adds title to avoid entries that execute an action
- if (storageSelect.value.substring(0, 11) == 'pickFolder-' ||
- storageSelect.value == 'reset')
- {
- var option = document.createElement('option');
- option.setAttribute('value', '');
- option.setAttribute('selected', 'selected');
- mxUtils.write(option, mxResources.get('pickFolder') + '...');
- storageSelect.insertBefore(option, storageSelect.firstChild);
- }
-
- defaultValue = storageSelect.value;
- };
- var saveBtn = mxUtils.button(mxResources.get('save'), function()
- {
- SaveDialog.lastValue = storageSelect.value;
- var entry = entries[SaveDialog.lastValue];
- if (entry != null)
- {
- saveFn(saveAsInput, entry.mode, entry.id);
- }
- }, null, 'geBtn gePrimaryBtn');
- // Handles enter key
- mxEvent.addListener(saveAsInput, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- saveBtn.click();
- }
- });
- function storageChanged()
- {
- if (storageSelect.value == 'reset')
- {
- editorUi.resetRecent('Folders');
- storageSelect.innerHTML = '';
- storageSelect.value = '';
- pickFolderOption = null;
- entries = {};
- addStorageEntries();
- }
- else if (storageSelect.value.substring(0, 11) == 'pickFolder-')
- {
- var mode = storageSelect.value.substring(11);
- storageSelect.value = defaultValue;
- pickFolder(mode);
- }
- else
- {
- checkExtension();
- }
- saveBtn.innerHTML = '';
- mxUtils.write(saveBtn, mxResources.get((
- storageSelect.value == 'download' ||
- storageSelect.value == '_blank') ?
- 'ok' : 'save'));
-
- if (storageSelect.value == '')
- {
- saveBtn.setAttribute('disabled', 'disabled');
- }
- else
- {
- saveBtn.removeAttribute('disabled');
- }
- };
-
- mxEvent.addListener(storageSelect, 'change', storageChanged);
- addStorageEntries();
- storageChanged();
- right.appendChild(storageSelect);
- // Selects last entry
- if (SaveDialog.lastValue != null && entries[SaveDialog.lastValue] != null)
- {
- storageSelect.value = SaveDialog.lastValue;
- }
- table.appendChild(left);
- table.appendChild(right);
- div.appendChild(table);
- if (preview != null)
- {
- div.appendChild(preview);
- }
- var btns = document.createElement('div');
- btns.style.flexBasis = '100%';
- btns.style.textAlign = 'right';
- btns.style.marginTop = (mimeType != null) ? '16px' : '8px';
- if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
- {
- btns.appendChild(editorUi.createHelpIcon(
- 'https://www.drawio.com/doc/faq/save-file-formats'));
- }
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- }, null, 'geBtn');
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- // Copy
- if (copyBtn != null)
- {
- btns.appendChild(copyBtn);
- }
- // Save
- btns.appendChild(saveBtn);
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- div.appendChild(btns);
- this.init = function()
- {
- Editor.selectFilename(saveAsInput);
- };
- this.container = div;
- };
- /**
- * Constructs a dialog for creating new files from a template URL.
- * Also used for dialog choosing where to save or export resources
- */
- var CreateDialog = function(editorUi, title, createFn, cancelFn, dlgTitle, btnLabel, overrideExtension, allowBrowser,
- allowTab, helpLink, showDeviceButton, rowLimit, data, mimeType, base64Encoded, hints, hideDialog)
- {
- showDeviceButton = urlParams['noDevice'] == '1'? false : showDeviceButton;
- overrideExtension = (overrideExtension != null) ? overrideExtension : true;
- allowBrowser = (allowBrowser != null) ? allowBrowser : true;
- rowLimit = (rowLimit != null) ? rowLimit : 4;
- hideDialog = (hideDialog != null) ? hideDialog : true;
- var div = document.createElement('div');
- div.style.whiteSpace = 'nowrap';
-
- var showButtons = true;
-
- if (cancelFn == null)
- {
- editorUi.addLanguageMenu(div);
- }
- var h3 = document.createElement('h2');
- mxUtils.write(h3, dlgTitle || mxResources.get('create'));
- h3.style.marginTop = '0px';
- h3.style.marginBottom = '24px';
- div.appendChild(h3);
- var span = document.createElement('span');
- mxUtils.write(span, mxResources.get('filename') + ':');
- span.style.maxWidth = '106px';
- span.style.overflow = 'hidden';
- span.style.textOverflow = 'ellipsis';
- span.style.display = 'inline-block';
- div.appendChild(span);
- var nameInput = document.createElement('input');
- nameInput.setAttribute('value', title);
- nameInput.style.width = '180px';
- nameInput.style.marginLeft = '10px';
- nameInput.style.marginBottom = '20px';
- nameInput.style.maxWidth = '70%';
-
- this.init = function()
- {
- Editor.selectFilename(nameInput);
- };
- div.appendChild(nameInput);
- if (hints != null && editorUi.editor.diagramFileTypes != null)
- {
- var typeSelect = FilenameDialog.createFileTypes(editorUi, nameInput, editorUi.editor.diagramFileTypes);
- typeSelect.style.marginLeft = '6px';
- typeSelect.style.width = '90px';
- div.appendChild(typeSelect);
- }
-
- var copyBtn = null;
-
- // Disables SVG preview if SVG is not supported in browser
- if (urlParams['noDevice'] != '1' && data != null && mimeType != null && (mimeType.substring(0, 6) == 'image/' &&
- (mimeType.substring(0, 9) != 'image/svg' || mxClient.IS_SVG)))
- {
- nameInput.style.width = '160px';
- var preview = document.createElement('img');
- var temp = (base64Encoded) ? data : btoa(unescape(encodeURIComponent(data)));
- preview.setAttribute('src', 'data:' + mimeType + ';base64,' + temp);
- preview.style.position = 'absolute';
- preview.style.top = '70px';
- preview.style.right = '100px';
- preview.style.maxWidth = '120px';
- preview.style.maxHeight = '80px';
- mxUtils.setPrefixedStyle(preview.style, 'transform',
- 'translate(50%,-50%)');
- div.appendChild(preview);
-
- if (!mxClient.IS_FF && mimeType == 'image/png' && navigator.clipboard != null &&
- typeof window.ClipboardItem === 'function')
- {
- copyBtn = mxUtils.button(mxResources.get('copy'), function(evt)
- {
- var blob = editorUi.base64ToBlob(temp, 'image/png');
- var html = '<img src="' + 'data:' + mimeType + ';base64,' + temp + '">';
- var cbi = new ClipboardItem({'image/png': blob,
- 'text/html': new Blob([html], {type: 'text/html'})});
- navigator.clipboard.write([cbi]).then(mxUtils.bind(this, function()
- {
- editorUi.alert(mxResources.get('copiedToClipboard'));
- }))['catch'](mxUtils.bind(this, function(e)
- {
- editorUi.handleError(e);
- }));
- });
-
- copyBtn.style.marginTop = '6px';
- copyBtn.className = 'geBtn';
- }
-
- if (allowTab && Editor.popupsAllowed)
- {
- preview.style.cursor = 'pointer';
-
- mxEvent.addGestureListeners(preview, null, null, function(evt)
- {
- if (!mxEvent.isPopupTrigger(evt))
- {
- create('_blank');
- }
- });
- }
- }
-
- mxUtils.br(div);
-
- var buttons = document.createElement('div');
- buttons.style.textAlign = 'center';
- var count = 0;
- function addLogo(img, title, mode, clientName)
- {
- var button = document.createElement('a');
- button.style.overflow = 'hidden';
-
- var logo = document.createElement('img');
- logo.src = img;
- logo.setAttribute('border', '0');
- logo.setAttribute('align', 'absmiddle');
- logo.style.width = '60px';
- logo.style.height = '60px';
- logo.style.paddingBottom = '6px';
- button.style.display = 'inline-block';
- button.className = 'geBaseButton';
- button.style.position = 'relative';
- button.style.margin = '4px';
- button.style.padding = '8px 8px 10px 8px';
- button.style.whiteSpace = 'nowrap';
-
- button.appendChild(logo);
-
- button.style.color = 'gray';
- button.style.fontSize = '11px';
-
- var label = document.createElement('div');
- button.appendChild(label);
- mxUtils.write(label, title);
-
- function initButton()
- {
- mxEvent.addListener(button, 'click', function()
- {
- // Updates extension
- change(mode);
- create(mode);
- });
- };
-
- // Supports lazy loading
- if (clientName != null && editorUi[clientName] == null)
- {
- logo.style.visibility = 'hidden';
- mxUtils.setOpacity(label, 10);
- var size = 12;
-
- var spinner = new Spinner({
- lines: 12, // The number of lines to draw
- length: size, // The length of each line
- width: 5, // The line thickness
- radius: 10, // The radius of the inner circle
- rotate: 0, // The rotation offset
- color: '#000', // #rgb or #rrggbb
- speed: 1.5, // Rounds per second
- trail: 60, // Afterglow percentage
- shadow: false, // Whether to render a shadow
- hwaccel: false, // Whether to use hardware acceleration
- top: '40%',
- zIndex: 2e9 // The z-index (defaults to 2000000000)
- });
- spinner.spin(button);
-
- // Timeout after 30 secs
- var timeout = window.setTimeout(function()
- {
- if (editorUi[clientName] == null)
- {
- spinner.stop();
- button.style.display = 'none';
- }
- }, 30000);
-
- editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
- {
- if (editorUi[clientName] != null)
- {
- window.clearTimeout(timeout);
- mxUtils.setOpacity(label, 100);
- logo.style.visibility = '';
- spinner.stop();
- initButton();
- }
- }));
- }
- else
- {
- initButton();
- }
- buttons.appendChild(button);
-
- if (++count == rowLimit)
- {
- mxUtils.br(buttons);
- count = 0;
- }
- };
- if (!showButtons)
- {
- mxUtils.write(div, mxResources.get('chooseAnOption') + ':');
- }
- else
- {
- buttons.style.marginTop = '6px';
- div.appendChild(buttons);
- }
-
- // Adds all papersize options
- var serviceSelect = document.createElement('select');
- serviceSelect.style.marginLeft = '10px';
- if (!editorUi.isOfflineApp() && !editorUi.isOffline())
- {
- if (typeof window.DriveClient === 'function')
- {
- var googleOption = document.createElement('option');
- googleOption.setAttribute('value', App.MODE_GOOGLE);
- mxUtils.write(googleOption, mxResources.get('googleDrive'));
- serviceSelect.appendChild(googleOption);
-
- addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
- }
-
- if (typeof window.OneDriveClient === 'function')
- {
- var oneDriveOption = document.createElement('option');
- oneDriveOption.setAttribute('value', App.MODE_ONEDRIVE);
- mxUtils.write(oneDriveOption, mxResources.get('oneDrive'));
- serviceSelect.appendChild(oneDriveOption);
-
- if (editorUi.mode == App.MODE_ONEDRIVE)
- {
- oneDriveOption.setAttribute('selected', 'selected');
- }
-
- addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
- }
- if (typeof window.DropboxClient === 'function')
- {
- var dropboxOption = document.createElement('option');
- dropboxOption.setAttribute('value', App.MODE_DROPBOX);
- mxUtils.write(dropboxOption, mxResources.get('dropbox'));
- serviceSelect.appendChild(dropboxOption);
-
- if (editorUi.mode == App.MODE_DROPBOX)
- {
- dropboxOption.setAttribute('selected', 'selected');
- }
-
- addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
- }
- if (editorUi.gitHub != null)
- {
- var gitHubOption = document.createElement('option');
- gitHubOption.setAttribute('value', App.MODE_GITHUB);
- mxUtils.write(gitHubOption, mxResources.get('github'));
- serviceSelect.appendChild(gitHubOption);
-
- addLogo(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), App.MODE_GITHUB, 'gitHub');
- }
-
- if (editorUi.gitLab != null)
- {
- var gitLabOption = document.createElement('option');
- gitLabOption.setAttribute('value', App.MODE_GITLAB);
- mxUtils.write(gitLabOption, mxResources.get('gitlab'));
- serviceSelect.appendChild(gitLabOption);
- addLogo(IMAGE_PATH + '/gitlab-logo.svg', mxResources.get('gitlab'), App.MODE_GITLAB, 'gitLab');
- }
- if (typeof window.TrelloClient === 'function')
- {
- var trelloOption = document.createElement('option');
- trelloOption.setAttribute('value', App.MODE_TRELLO);
- mxUtils.write(trelloOption, mxResources.get('trello'));
- serviceSelect.appendChild(trelloOption);
-
- addLogo(IMAGE_PATH + '/trello-logo.svg', mxResources.get('trello'), App.MODE_TRELLO, 'trello');
- }
- }
-
- if (!Editor.useLocalStorage || urlParams['storage'] == 'device' ||
- (editorUi.getCurrentFile() != null/* && !mxClient.IS_IOS*/ && urlParams['noDevice'] != '1'))
- {
- var deviceOption = document.createElement('option');
- deviceOption.setAttribute('value', App.MODE_DEVICE);
- mxUtils.write(deviceOption, mxResources.get('device'));
- serviceSelect.appendChild(deviceOption);
-
- if (editorUi.mode == App.MODE_DEVICE || !allowBrowser)
- {
- deviceOption.setAttribute('selected', 'selected');
- }
-
- if (showDeviceButton)
- {
- addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
- }
- }
-
- if (allowBrowser && isLocalStorage && urlParams['browser'] != '0')
- {
- var browserOption = document.createElement('option');
- browserOption.setAttribute('value', App.MODE_BROWSER);
- mxUtils.write(browserOption, mxResources.get('browser'));
- serviceSelect.appendChild(browserOption);
-
- if (editorUi.mode == App.MODE_BROWSER)
- {
- browserOption.setAttribute('selected', 'selected');
- }
-
- addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
- }
- function change(newMode)
- {
- if (overrideExtension)
- {
- var fn = nameInput.value;
- var idx = fn.lastIndexOf('.');
-
- if (title.lastIndexOf('.') < 0 && (!showButtons || idx < 0))
- {
- newMode = (newMode != null) ? newMode : serviceSelect.value;
- var ext = '';
-
- if (newMode == App.MODE_GOOGLE)
- {
- ext = editorUi.drive.extension;
- }
- else if (newMode == App.MODE_GITHUB)
- {
- ext = editorUi.gitHub.extension;
- }
- else if (newMode == App.MODE_GITLAB)
- {
- ext = editorUi.gitLab.extension;
- }
- else if (newMode == App.MODE_TRELLO)
- {
- ext = editorUi.trello.extension;
- }
- else if (newMode == App.MODE_DROPBOX)
- {
- ext = editorUi.dropbox.extension;
- }
- else if (newMode == App.MODE_ONEDRIVE)
- {
- ext = editorUi.oneDrive.extension;
- }
- else if (newMode == App.MODE_DEVICE)
- {
- ext = '.drawio';
- }
-
- if (idx >= 0)
- {
- fn = fn.substring(0, idx);
- }
-
- nameInput.value = fn + ext;
- }
- }
- };
- var btns = document.createElement('div');
- btns.style.marginTop = (showButtons) ? '26px' : '38px';
- btns.style.textAlign = 'center';
-
- if (!showButtons)
- {
- div.appendChild(serviceSelect);
- mxEvent.addListener(serviceSelect, 'change', change);
- change();
- }
-
- if (helpLink != null)
- {
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- editorUi.openLink(helpLink);
- });
-
- helpBtn.className = 'geBtn';
- btns.appendChild(helpBtn);
- }
-
- var cancelBtn = mxUtils.button(mxResources.get((cancelFn != null) ? 'close' : 'cancel'), function()
- {
- if (cancelFn != null)
- {
- cancelFn();
- }
- else
- {
- editorUi.fileLoaded(null);
- editorUi.hideDialog();
- window.close();
- window.location.href = editorUi.getUrl();
- }
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst && cancelFn == null)
- {
- btns.appendChild(cancelBtn);
- }
- function create(mode)
- {
- var title = nameInput.value;
-
- if (mode == null || (title != null && title.length > 0))
- {
- if (hideDialog)
- {
- editorUi.hideDialog();
- }
-
- createFn(title, mode, nameInput);
- };
- }
-
- if (cancelFn == null)
- {
- var laterBtn = mxUtils.button(mxResources.get('decideLater'), function()
- {
- create(null);
- });
-
- laterBtn.className = 'geBtn';
- btns.appendChild(laterBtn);
- }
- if (allowTab && Editor.popupsAllowed)
- {
- var openBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
- {
- create('_blank');
- });
-
- openBtn.className = 'geBtn';
- btns.appendChild(openBtn);
- }
- if (CreateDialog.showDownloadButton)
- {
- var downloadButton = mxUtils.button(mxResources.get('download'), function()
- {
- create('download');
- });
-
- downloadButton.className = 'geBtn';
- btns.appendChild(downloadButton);
-
- if (copyBtn != null)
- {
- downloadButton.style.marginTop = '6px';
- btns.style.marginTop = '6px';
- }
- }
-
- if (copyBtn != null)
- {
- mxUtils.br(btns);
- btns.appendChild(copyBtn);
- }
-
- if (/*!mxClient.IS_IOS || */!showButtons)
- {
- var createBtn = mxUtils.button(btnLabel || mxResources.get('create'), function()
- {
- create((showDeviceButton) ? 'download' : ((showButtons) ? App.MODE_DEVICE : serviceSelect.value));
- });
-
- createBtn.className = 'geBtn gePrimaryBtn';
- btns.appendChild(createBtn);
- }
-
- if (!editorUi.editor.cancelFirst || cancelFn != null)
- {
- btns.appendChild(cancelBtn);
- }
-
- mxEvent.addListener(nameInput, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- create((showButtons) ? App.MODE_DEVICE : serviceSelect.value);
- }
- else if (e.keyCode == 27)
- {
- editorUi.fileLoaded(null);
- editorUi.hideDialog();
- window.close();
- }
- });
- div.appendChild(btns);
- this.container = div;
- };
- /**
- *
- */
- CreateDialog.showDownloadButton = urlParams['noDevice'] != '1';
- /**
- * Constructs a new popup dialog.
- */
- var PopupDialog = function(editorUi, url, pre, fallback, hideDialog)
- {
- hideDialog = (hideDialog != null) ? hideDialog : true;
-
- var div = document.createElement('div');
- div.style.textAlign = 'left';
- div.style.height = '100%';
-
- mxUtils.write(div, mxResources.get('fileOpenLocation'));
- mxUtils.br(div);
- mxUtils.br(div);
- var replaceBtn = mxUtils.button(mxResources.get('openInThisWindow'), function()
- {
- if (hideDialog)
- {
- editorUi.hideDialog();
- }
-
- if (fallback != null)
- {
- fallback();
- }
- });
- replaceBtn.className = 'geBtn';
- replaceBtn.style.marginBottom = '8px';
- replaceBtn.style.width = '280px';
- div.appendChild(replaceBtn);
-
- mxUtils.br(div);
-
- var wndBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
- {
- if (hideDialog)
- {
- editorUi.hideDialog();
- }
- if (pre != null)
- {
- pre();
- }
-
- editorUi.openLink(url, null, true);
- });
- wndBtn.className = 'geBtn gePrimaryBtn';
- wndBtn.style.width = replaceBtn.style.width;
- div.appendChild(wndBtn);
-
- mxUtils.br(div);
- mxUtils.br(div);
- mxUtils.write(div, mxResources.get('allowPopups'));
-
- this.container = div;
- };
- /**
- * Constructs a new image dialog.
- */
- var ImageDialog = function(editorUi, title, initialValue, fn, ignoreExisting, convertDataUri, withCrop, initClipPath)
- {
- convertDataUri = (convertDataUri != null) ? convertDataUri : true;
-
- var graph = editorUi.editor.graph;
- var div = document.createElement('div');
- mxUtils.write(div, title);
-
- var inner = document.createElement('div');
- inner.className = 'geTitle';
- inner.style.backgroundColor = 'transparent';
- inner.style.borderColor = 'transparent';
- inner.style.whiteSpace = 'nowrap';
- inner.style.textOverflow = 'clip';
- inner.style.cursor = 'default';
- inner.style.paddingRight = '20px';
-
- var linkInput = document.createElement('input');
- linkInput.setAttribute('value', initialValue);
- linkInput.setAttribute('type', 'text');
- linkInput.setAttribute('spellcheck', 'false');
- linkInput.setAttribute('autocorrect', 'off');
- linkInput.setAttribute('autocomplete', 'off');
- linkInput.setAttribute('autocapitalize', 'off');
- linkInput.style.marginTop = '6px';
- var realWidth = (Graph.fileSupport) ? 460 : 340;
- linkInput.style.width = realWidth - 20 + 'px';
- linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
- linkInput.style.backgroundRepeat = 'no-repeat';
- linkInput.style.backgroundPosition = '100% 50%';
- linkInput.style.paddingRight = '14px';
-
- var cross = document.createElement('div');
- cross.setAttribute('title', mxResources.get('reset'));
- cross.style.position = 'relative';
- cross.style.left = '-16px';
- cross.style.width = '12px';
- cross.style.height = '14px';
- cross.style.cursor = 'pointer';
- // Workaround for inline-block not supported in IE
- cross.style.display = 'inline-block';
- cross.style.top = '3px';
-
- // Needed to block event transparency in IE
- cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
- mxEvent.addListener(cross, 'click', function()
- {
- linkInput.value = '';
- linkInput.focus();
- });
-
- inner.appendChild(linkInput);
- inner.appendChild(cross);
- div.appendChild(inner);
- var clipPath = initClipPath, cW, cH;
- var insertImage = function(newValue, w, h, resize)
- {
- var dataUri = newValue.substring(0, 5) == 'data:';
-
- if (!editorUi.isOffline() || (dataUri && typeof chrome === 'undefined'))
- {
- if (newValue.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('inserting')))
- {
- var maxSize = 520;
-
- editorUi.loadImage(newValue, function(img)
- {
- editorUi.spinner.stop();
- editorUi.hideDialog();
- var s = (resize === false) ? 1 :
- (w != null && h != null) ? Math.max(w / img.width, h / img.height) :
- Math.min(1, Math.min(maxSize / img.width, maxSize / img.height));
-
- // Handles special case of data URI which needs to be rewritten
- // to be used in a cell style to remove the semicolon
- if (convertDataUri)
- {
- newValue = editorUi.convertDataUri(newValue);
- }
-
- fn(newValue, Math.round(Number(img.width) * s), Math.round(Number(img.height) * s), clipPath, cW, cH);
- }, function()
- {
- editorUi.spinner.stop();
- fn(null);
- editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
- });
- }
- else
- {
- editorUi.hideDialog();
- fn(newValue, null, null, clipPath, cW, cH);
- }
- }
- else
- {
- newValue = editorUi.convertDataUri(newValue);
- w = (w == null) ? 120 : w;
- h = (h == null) ? 100 : h;
-
- editorUi.hideDialog();
- fn(newValue, w, h, clipPath, cW, cH);
- }
- };
-
- var apply = function(newValue, resize)
- {
- if (newValue != null)
- {
- var geo = (ignoreExisting) ? null : graph.getModel().getGeometry(graph.getSelectionCell());
- // Reuses width and height of existing cell
- if (geo != null)
- {
- insertImage(newValue, geo.width, geo.height, resize);
- }
- else
- {
- insertImage(newValue, null, null, resize);
- }
- }
- else
- {
- editorUi.hideDialog();
- fn(null);
- }
- };
- this.init = function()
- {
- linkInput.focus();
-
- // Installs drag and drop handler for local images and links
- if (Graph.fileSupport)
- {
- linkInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
-
- // Setup the dnd listeners
- var dlg = div.parentNode;
- var graph = editorUi.editor.graph;
- var dropElt = null;
-
- mxEvent.addListener(dlg, 'dragleave', function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- });
-
- mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
- {
- // IE 10 does not implement pointer-events so it can't have a drop highlight
- if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
- {
- dropElt = editorUi.highlightElement(dlg);
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- }));
-
- mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
- if (evt.dataTransfer.files.length > 0)
- {
- editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, fileName, resize)
- {
- apply(data, resize);
- }, function()
- {
- // No post processing
- }, function(file)
- {
- // Handles only images
- return file.type.substring(0, 6) == 'image/';
- }, function(queue)
- {
- // Invokes elements of queue in order
- for (var i = 0; i < queue.length; i++)
- {
- queue[i]();
- }
- }, !mxEvent.isControlDown(evt), null, null, true);
- }
- else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
- {
- var uri = evt.dataTransfer.getData('text/uri-list');
-
- if ((/\.(gif|jpg|jpeg|tiff|png|svg)($|\?)/i).test(uri))
- {
- apply(decodeURIComponent(uri));
- }
- }
- evt.stopPropagation();
- evt.preventDefault();
- }), false);
- }
- };
-
- var btns = document.createElement('div');
- btns.style.marginTop = '14px';
- btns.style.textAlign = 'center';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- // Just in case a spinner is spinning, has no effect otherwise
- editorUi.spinner.stop();
- editorUi.hideDialog();
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- ImageDialog.filePicked = function(data)
- {
- if (data.action == google.picker.Action.PICKED)
- {
- if (data.docs[0].thumbnails != null)
- {
- var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
-
- if (thumb != null)
- {
- linkInput.value = thumb.url;
- }
- }
- }
-
- linkInput.focus();
- };
- if (Graph.fileSupport)
- {
- if (editorUi.imgDlgFileInputElt == null)
- {
- var fileInput = document.createElement('input');
- fileInput.setAttribute('multiple', 'multiple');
- fileInput.setAttribute('type', 'file');
-
- mxEvent.addListener(fileInput, 'change', function(evt)
- {
- if (fileInput.files != null)
- {
- editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h)
- {
- apply(data);
- }, function()
- {
- // No post processing
- }, function(file)
- {
- // Handles only images
- return file.type.substring(0, 6) == 'image/';
- }, function(queue)
- {
- // Invokes elements of queue in order
- for (var i = 0; i < queue.length; i++)
- {
- queue[i]();
- }
- }, true);
-
- // Resets input to force change event for same file (type reset required for IE)
- fileInput.type = '';
- fileInput.type = 'file';
- fileInput.value = '';
- }
- });
-
- fileInput.style.display = 'none';
- document.body.appendChild(fileInput);
- editorUi.imgDlgFileInputElt = fileInput;
- }
-
- var btn = mxUtils.button(mxResources.get('open'), function()
- {
- editorUi.imgDlgFileInputElt.click();
- });
- btn.className = 'geBtn';
- btns.appendChild(btn);
- }
- mxEvent.addListener(linkInput, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- apply(linkInput.value);
- }
- });
- var cropBtn = mxUtils.button(mxResources.get('crop'), function()
- {
- var dlg = new CropImageDialog(editorUi, linkInput.value, clipPath,
- function(clipPath_p, width, height)
- {
- clipPath = clipPath_p;
- cW = width;
- cH = height;
- });
-
- editorUi.showDialog(dlg.container, 300, 390, true, true);
- });
-
- if (withCrop)
- {
- cropBtn.className = 'geBtn';
- btns.appendChild(cropBtn);
- }
-
- var embedBtn = mxUtils.button(mxResources.get('embed'), function()
- {
- if (linkInput.value.substring(0, 5) != 'data:' && editorUi.spinner.spin(
- document.body, mxResources.get('loading')))
- {
- var converter = editorUi.editor.createImageUrlConverter();
- var src = converter.convert(linkInput.value);
- var img = new Image();
- img.onload = function()
- {
- editorUi.editor.convertImageToDataUri(src, function(uri)
- {
- editorUi.confirmImageResize(function(doResize)
- {
- editorUi.resizeImage(img, uri, mxUtils.bind(this, function(data2, w2, h2)
- {
- editorUi.spinner.stop();
- // Refuses to insert images above a certain size as they kill the app
- if (data2 != null && data2.length < editorUi.maxImageBytes)
- {
- linkInput.value = data2;
- updateButtonStates();
- }
- else
- {
- editorUi.handleError({message: mxResources.get('imageTooBig')});
- }
- }), doResize, editorUi.maxImageSize);
- }, img.width > editorUi.maxImageSize || img.height > editorUi.maxImageSize ||
- uri.length > editorUi.maxImageBytes);
- }, mxUtils.bind(this, function()
- {
- editorUi.handleError({message: mxResources.get('fileNotFound')});
- }));
- };
- img.onerror = function()
- {
- editorUi.spinner.stop();
- editorUi.handleError({message: mxResources.get('fileNotFound')});
- };
- img.src = src;
- }
- });
- function updateButtonStates()
- {
- if (linkInput.value.length > 0)
- {
- cropBtn.removeAttribute('disabled');
- }
- else
- {
- cropBtn.setAttribute('disabled', 'disabled');
- }
- if (linkInput.value.substring(0, 5) != 'data:')
- {
- embedBtn.removeAttribute('disabled');
- }
- else
- {
- embedBtn.setAttribute('disabled', 'disabled');
- }
- };
- embedBtn.className = 'geBtn';
- mxEvent.addListener(linkInput, 'change', function(e)
- {
- clipPath = null;
- updateButtonStates();
- });
- updateButtonStates();
- btns.appendChild(embedBtn);
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- apply(linkInput.value);
- });
-
- applyBtn.className = 'geBtn gePrimaryBtn';
- btns.appendChild(applyBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- // Shows drop icon in dialog background
- if (Graph.fileSupport)
- {
- btns.style.marginTop = '120px';
- div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
- div.style.backgroundPosition = 'center 65%';
- div.style.backgroundRepeat = 'no-repeat';
-
- var bg = document.createElement('div');
- bg.style.position = 'absolute';
- bg.style.width = '420px';
- bg.style.top = '58%';
- bg.style.textAlign = 'center';
- bg.style.fontSize = '18px';
- bg.style.color = '#a0c3ff';
- mxUtils.write(bg, mxResources.get('dragImagesHere'));
- div.appendChild(bg);
- }
- div.appendChild(btns);
- this.container = div;
- };
- /**
- * Overrides link dialog to add Google Picker.
- */
- var LinkDialog = function(editorUi, initialValue, btnLabel, fn, showPages, showNewWindowOption, linkTarget)
- {
- var div = document.createElement('div');
- div.style.height = '100%';
- mxUtils.write(div, mxResources.get('editLink') + ':');
-
- var inner = document.createElement('div');
- inner.className = 'geTitle';
- inner.style.backgroundColor = 'transparent';
- inner.style.borderColor = 'transparent';
- inner.style.whiteSpace = 'nowrap';
- inner.style.textOverflow = 'clip';
- inner.style.cursor = 'default';
- var linkInput = document.createElement('input');
- linkInput.setAttribute('placeholder', mxResources.get('dragUrlsHere'));
- linkInput.setAttribute('type', 'text');
- linkInput.style.marginTop = '6px';
- linkInput.style.width = '414px';
- linkInput.style.boxSizing = 'border-box';
- linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
- linkInput.style.backgroundRepeat = 'no-repeat';
- linkInput.style.backgroundPosition = '100% 50%';
- linkInput.style.paddingRight = '14px';
- linkInput.style.marginBottom = '4px';
- var cross = document.createElement('div');
- cross.setAttribute('title', mxResources.get('reset'));
- cross.style.position = 'relative';
- cross.style.left = '-16px';
- cross.style.width = '12px';
- cross.style.height = '14px';
- cross.style.cursor = 'pointer';
-
- // Workaround for inline-block not supported in IE
- cross.style.display = 'inline-block';
- cross.style.top = '3px';
-
- // Needed to block event transparency in IE
- cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
- mxEvent.addListener(cross, 'click', function()
- {
- linkInput.value = '';
- linkInput.focus();
- });
- var urlRadio = document.createElement('input');
- urlRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
- urlRadio.setAttribute('value', 'url');
- urlRadio.setAttribute('type', 'radio');
- urlRadio.setAttribute('name', 'geLinkDialogOption');
- var pageRadio = document.createElement('input');
- pageRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
- pageRadio.setAttribute('value', 'url');
- pageRadio.setAttribute('type', 'radio');
- pageRadio.setAttribute('name', 'geLinkDialogOption');
- var pageSelect = document.createElement('select');
- pageSelect.style.width = '414px';
- var newWindowCheckbox = document.createElement('input');
- newWindowCheckbox.setAttribute('type', 'checkbox');
- newWindowCheckbox.style.margin = '0 6p 0 6px';
- if (linkTarget != null)
- {
- newWindowCheckbox.setAttribute('checked', 'checked');
- newWindowCheckbox.defaultChecked = true;
- }
-
- linkTarget = (linkTarget != null) ? linkTarget : '_blank';
- newWindowCheckbox.setAttribute('title', linkTarget);
-
- if (showNewWindowOption)
- {
- linkInput.style.width = '200px';
- }
-
- if (showPages && editorUi.pages != null)
- {
- if (initialValue != null && Graph.isPageLink(initialValue))
- {
- pageRadio.setAttribute('checked', 'checked');
- pageRadio.defaultChecked = true;
- }
- else
- {
- linkInput.setAttribute('value', initialValue);
- urlRadio.setAttribute('checked', 'checked');
- urlRadio.defaultChecked = true;
- }
-
- inner.appendChild(urlRadio);
- inner.appendChild(linkInput);
- inner.appendChild(cross);
-
- if (showNewWindowOption)
- {
- inner.appendChild(newWindowCheckbox);
- mxUtils.write(inner, mxResources.get('openInNewWindow'));
- }
-
- mxUtils.br(inner);
- inner.appendChild(pageRadio);
-
- var pageFound = false;
-
- for (var i = 0; i < editorUi.pages.length; i++)
- {
- var pageOption = document.createElement('option');
- mxUtils.write(pageOption, editorUi.pages[i].getName() ||
- mxResources.get('pageWithNumber', [i + 1]));
- pageOption.setAttribute('value', 'data:page/id,' +
- editorUi.pages[i].getId());
-
- if (initialValue == pageOption.getAttribute('value'))
- {
- pageOption.setAttribute('selected', 'selected');
- pageFound = true;
- }
- pageSelect.appendChild(pageOption);
- }
- if (!pageFound && pageRadio.checked)
- {
- var notFoundOption = document.createElement('option');
- mxUtils.write(notFoundOption, mxResources.get('pageNotFound'));
- notFoundOption.setAttribute('disabled', 'disabled');
- notFoundOption.setAttribute('selected', 'selected');
- notFoundOption.setAttribute('value', 'pageNotFound');
- pageSelect.appendChild(notFoundOption);
-
- mxEvent.addListener(pageSelect, 'change', function()
- {
- if (notFoundOption.parentNode != null && !notFoundOption.selected)
- {
- notFoundOption.parentNode.removeChild(notFoundOption);
- }
- });
- }
-
- inner.appendChild(pageSelect);
- }
- else
- {
- linkInput.setAttribute('value', initialValue);
- inner.appendChild(linkInput);
- inner.appendChild(cross);
- }
- div.appendChild(inner);
-
- var mainBtn = mxUtils.button(btnLabel, function()
- {
- editorUi.hideDialog();
- var value = (pageRadio.checked) ? ((pageSelect.value !== 'pageNotFound') ?
- pageSelect.value : initialValue) : linkInput.value;
- fn(value, LinkDialog.selectedDocs, (newWindowCheckbox.checked) ? linkTarget : null);
- });
- mainBtn.style.verticalAlign = 'middle';
- mainBtn.className = 'geBtn gePrimaryBtn';
-
- this.init = function()
- {
- if (pageRadio.checked)
- {
- pageSelect.focus();
- }
- else
- {
- linkInput.focus();
-
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- linkInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- }
-
- mxEvent.addListener(pageSelect, 'focus', function()
- {
- urlRadio.removeAttribute('checked');
- pageRadio.setAttribute('checked', 'checked');
- pageRadio.checked = true;
- });
-
- mxEvent.addListener(linkInput, 'focus', function()
- {
- pageRadio.removeAttribute('checked');
- urlRadio.setAttribute('checked', 'checked');
- urlRadio.checked = true;
- });
- // Installs drag and drop handler for links
- if (Graph.fileSupport)
- {
- // Setup the dnd listeners
- var dlg = div.parentNode;
- var dropElt = null;
-
- mxEvent.addListener(dlg, 'dragleave', function(evt)
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- });
-
- mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
- {
- // IE 10 does not implement pointer-events so it can't have a drop highlight
- if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
- {
- dropElt = editorUi.highlightElement(dlg);
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- }));
-
- mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
- {
- try
- {
- if (dropElt != null)
- {
- dropElt.parentNode.removeChild(dropElt);
- dropElt = null;
- }
- if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
- {
- linkInput.value = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
- urlRadio.setAttribute('checked', 'checked');
- urlRadio.checked = true;
- mainBtn.click();
- }
- }
- catch (e)
- {
- editorUi.handleError(e);
- }
- evt.stopPropagation();
- evt.preventDefault();
- }), false);
- }
- };
-
- var btns = document.createElement('div');
- btns.style.marginTop = '16px';
- btns.style.textAlign = 'right';
- if (!editorUi.isOffline())
- {
- btns.appendChild(editorUi.createHelpIcon('https://www.drawio.com/doc/faq/custom-links'));
- }
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.style.verticalAlign = 'middle';
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
-
- LinkDialog.selectedDocs = null;
-
- LinkDialog.filePicked = function(data)
- {
- if (data.action == google.picker.Action.PICKED)
- {
- LinkDialog.selectedDocs = data.docs;
- var href = data.docs[0].url;
-
- if (data.docs[0].mimeType == 'application/mxe' || (data.docs[0].mimeType != null &&
- data.docs[0].mimeType.substring(0, 23) == 'application/vnd.jgraph.'))
- {
- href = 'https://www.draw.io/#G' + data.docs[0].id;
- }
- else if (data.docs[0].mimeType == 'application/vnd.google-apps.folder')
- {
- // Do not use folderview in data.docs[0].url link to Google Drive instead
- href = 'https://drive.google.com/#folders/' + data.docs[0].id;
- }
-
- linkInput.value = href;
- linkInput.focus();
- }
- else
- {
- LinkDialog.selectedDocs = null;
- }
-
- linkInput.focus();
- };
- var selectDropdown = document.createElement('select');
- selectDropdown.className = 'geBtn';
- selectDropdown.style.position = 'relative';
- selectDropdown.style.top = '1px';
- selectDropdown.style.maxWidth = '120px';
- var selectFn = {};
- var option = document.createElement('option');
- mxUtils.write(option, mxResources.get('select') + '...');
- option.value = '';
- selectDropdown.appendChild(option);
- function addButton(key, fn)
- {
- var option = document.createElement('option');
- mxUtils.write(option, mxResources.get(key));
- option.value = key;
- selectDropdown.appendChild(option);
- selectFn[key] = fn;
- };
- if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined' && editorUi.drive != null)
- {
- addButton('googleDrive', function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
- {
- editorUi.drive.checkToken(mxUtils.bind(this, function()
- {
- editorUi.spinner.stop();
-
- // Creates one picker and reuses it to avoid polluting the DOM
- if (editorUi.linkPicker == null)
- {
- var picker = editorUi.drive.createLinkPicker();
- editorUi.linkPicker = picker.setCallback(function(data)
- {
- LinkDialog.filePicked(data);
- }).build();
- }
-
- editorUi.linkPicker.setVisible(true);
- }));
- }
- });
- }
-
- if (typeof(Dropbox) != 'undefined' && typeof(Dropbox.choose) != 'undefined')
- {
- addButton('dropbox', function()
- {
- // Authentication will be carried out on open to make sure the
- // autosave does not show an auth dialog. Showing it here will
- // block the second dialog (the file picker) so it's too early.
- Dropbox.choose(
- {
- linkType : 'direct',
- cancel: function()
- {
- // do nothing
- },
- success : function(files)
- {
- linkInput.value = files[0].link;
- linkInput.focus();
- }
- });
- });
- }
-
- if (editorUi.oneDrive != null)
- {
- addButton('oneDrive', function()
- {
- editorUi.oneDrive.pickFile(function(id, files)
- {
- if (files != null && files.value != null && files.value.length > 0)
- {
- linkInput.value = files.value[0].webUrl;
- linkInput.focus();
- }
- }, true);
- });
- }
-
- if (editorUi.gitHub != null)
- {
- addButton('github', function()
- {
- editorUi.gitHub.pickFile(function(path)
- {
- if (path != null)
- {
- var tokens = path.split('/');
- var org = tokens[0];
- var repo = tokens[1];
- var ref = tokens[2];
- var path = tokens.slice(3, tokens.length).join('/');
-
- linkInput.value = 'https://github.com/' + org + '/' +
- repo + '/blob/' + ref + '/' + path;
- linkInput.focus();
- }
- });
- });
- }
-
- if (editorUi.gitLab != null)
- {
- addButton('gitlab', function()
- {
- editorUi.gitLab.pickFile(function(path)
- {
- if (path != null)
- {
- var tokens = path.split('/');
- var org = tokens[0];
- var repo = tokens[1];
- var ref = tokens[2];
- var path = tokens.slice(3, tokens.length).join('/');
- linkInput.value = DRAWIO_GITLAB_URL + '/' + org + '/' +
- repo + '/blob/' + ref + '/' + path;
- linkInput.focus();
- }
- });
- });
- }
- if (selectDropdown.children.length > 1)
- {
- btns.appendChild(selectDropdown);
- mxEvent.addListener(selectDropdown, 'change', function(evt)
- {
- if (selectFn[selectDropdown.value] != null)
- {
- selectFn[selectDropdown.value]();
- selectDropdown.value = '';
- }
- });
- }
- mxEvent.addListener(linkInput, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- mainBtn.click();
- }
- });
- btns.appendChild(mainBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- div.appendChild(btns);
- this.container = div;
- };
- /**
- * Constructs a new about dialog
- */
- var FeedbackDialog = function(editorUi, subject, emailOptional, diagramData)
- {
- var div = document.createElement('div');
-
- var label = document.createElement('div');
- mxUtils.write(label, mxResources.get('sendYourFeedback'));
- label.style.fontSize = '18px';
- label.style.marginBottom = '18px';
-
- div.appendChild(label);
-
- label = document.createElement('div');
- mxUtils.write(label, mxResources.get('yourEmailAddress') +
- ((emailOptional) ? '' : ' (' + mxResources.get('required') + ')'));
-
- div.appendChild(label);
-
- var email = document.createElement('input');
- email.setAttribute('type', 'text');
- email.style.marginTop = '6px';
- email.style.width = '600px';
-
- var sendButton = mxUtils.button(mxResources.get('sendMessage'), function()
- {
- var diagram = textarea.value +
- ((cb.checked) ? '\nDiagram:\n' + ((diagramData != null) ?
- diagramData : mxUtils.getXml(editorUi.getXmlFileData())) : '') +
- '\nuserAgent:\n' + navigator.userAgent +
- '\nappVersion:\n' + navigator.appVersion +
- '\nappName:\n' + navigator.appName +
- '\nplatform:\n' + navigator.platform;
-
- if (diagram.length > FeedbackDialog.maxAttachmentSize)
- {
- editorUi.alert(mxResources.get('drawingTooLarge'));
- }
- else
- {
- editorUi.hideDialog();
-
- if (editorUi.spinner.spin(document.body))
- {
- var postUrl = (FeedbackDialog.feedbackUrl != null) ? FeedbackDialog.feedbackUrl : '/email';
- mxUtils.post(postUrl, 'email=' + encodeURIComponent(email.value) +
- '&version=' + encodeURIComponent(EditorUi.VERSION) +
- '&url=' + encodeURIComponent(window.location.href) +
- '&body=' + encodeURIComponent(((subject != null) ?
- subject : 'Feedback') + ':\n' + diagram),
- function(req)
- {
- editorUi.spinner.stop();
-
- if (req.getStatus() >= 200 && req.getStatus() <= 299)
- {
- editorUi.alert(mxResources.get('feedbackSent'));
- }
- else
- {
- editorUi.alert(mxResources.get('errorSendingFeedback'));
- }
- },
- function()
- {
- editorUi.spinner.stop();
- editorUi.alert(mxResources.get('errorSendingFeedback'));
- });
- }
- }
- });
- sendButton.className = 'geBtn gePrimaryBtn';
-
- if (!emailOptional)
- {
- sendButton.setAttribute('disabled', 'disabled');
- 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,}))$/;
-
- mxEvent.addListener(email, 'change', function()
- {
- if (email.value.length > 0 && re.test(email.value) > 0)
- {
- sendButton.removeAttribute('disabled');
- }
- else
- {
- sendButton.setAttribute('disabled', 'disabled');
- }
- });
-
- mxEvent.addListener(email, 'keyup', function()
- {
- if (email.value.length > 0 && re.test(email.value))
- {
- sendButton.removeAttribute('disabled');
- }
- else
- {
- sendButton.setAttribute('disabled', 'disabled');
- }
- });
- }
-
- div.appendChild(email);
-
- this.init = function()
- {
- email.focus();
- };
-
- var cb = document.createElement('input');
- cb.setAttribute('type', 'checkbox');
- cb.setAttribute('checked', 'checked');
- cb.defaultChecked = true;
-
- var p2 = document.createElement('p');
- p2.style.marginTop = '14px';
- p2.appendChild(cb);
-
- var span = document.createElement('span');
- mxUtils.write(span, ' ' + mxResources.get('includeCopyOfMyDiagram'));
- p2.appendChild(span);
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- cb.checked = !cb.checked;
- mxEvent.consume(evt);
- });
-
- div.appendChild(p2);
-
- label = document.createElement('div');
- mxUtils.write(label, mxResources.get('feedback'));
-
- div.appendChild(label);
-
- var textarea = document.createElement('textarea');
- textarea.style.resize = 'none';
- textarea.style.width = '600px';
- textarea.style.height = '140px';
- textarea.style.marginTop = '6px';
-
- textarea.setAttribute('placeholder', mxResources.get('comments'));
-
- div.appendChild(textarea);
- var buttons = document.createElement('div');
- buttons.style.marginTop = '26px';
- buttons.style.textAlign = 'right';
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(sendButton);
- }
- else
- {
- buttons.appendChild(sendButton);
- buttons.appendChild(cancelBtn);
- }
- div.appendChild(buttons);
- this.container = div;
- };
- /**
- * Maximum size of attachments in bytes. Default is 1000000.
- */
- FeedbackDialog.maxAttachmentSize = 1000000;
- /**
- * Constructs a new revision dialog
- */
- var RevisionDialog = function(editorUi, revs, restoreFn)
- {
- var div = document.createElement('div');
-
- var title = document.createElement('h3');
- title.style.marginTop = '3px';
- mxUtils.write(title, mxResources.get('revisionHistory'));
- div.appendChild(title);
-
- var list = document.createElement('div');
- list.style.position = 'absolute';
- list.style.overflow = 'auto';
- list.style.width = '170px';
- list.style.height = '378px';
- div.appendChild(list);
-
- var container = document.createElement('div');
- container.style.position = 'absolute';
- container.style.border = '1px solid lightGray';
- container.style.left = '200px';
- container.style.width = '470px';
- container.style.height = '376px';
- container.style.overflow = 'hidden';
- // Contains possible error messages
- var errorNode = document.createElement('div');
- errorNode.style.position = 'absolute',
- errorNode.style.display = 'none';
- errorNode.style.textAlign = 'center';
- errorNode.style.padding = '8px';
- errorNode.style.borderRadius = '8px';
- errorNode.style.left = '50%';
- errorNode.style.top = '50%';
- errorNode.style.whiteSpace = 'nowrap';
- errorNode.style.transform = 'translate(-50%, -50%)';
- errorNode.style.background = 'inherit';
- errorNode.style.border = '1px solid';
- container.appendChild(errorNode);
-
- mxEvent.disableContextMenu(container);
- div.appendChild(container);
- var graph = new Graph(container);
- graph.setTooltips(false);
- graph.setEnabled(false);
- graph.setPanning(true);
- graph.panningHandler.ignoreCell = true;
- graph.panningHandler.useLeftButtonForPanning = true;
- graph.minFitScale = null;
- graph.maxFitScale = null;
- graph.centerZoom = true;
-
- // Handles placeholders for pages
- var currentPage = 0;
- var diagrams = null;
- var realPage = 0;
-
- var graphGetGlobalVariable = graph.getGlobalVariable;
-
- graph.getGlobalVariable = function(name)
- {
- if (name == 'page' && diagrams != null && diagrams[realPage] != null)
- {
- return diagrams[realPage].getAttribute('name');
- }
- else if (name == 'pagenumber')
- {
- return realPage + 1;
- }
- else if (name == 'pagecount')
- {
- return (diagrams != null) ? diagrams.length : 1;
- }
-
- return graphGetGlobalVariable.apply(this, arguments);
- };
-
- // Disables hyperlinks
- graph.getLinkForCell = function()
- {
- return null;
- };
- var opts = {
- lines: 11, // The number of lines to draw
- length: 15, // The length of each line
- width: 6, // The line thickness
- radius: 10, // The radius of the inner circle
- corners: 1, // Corner roundness (0..1)
- rotate: 0, // The rotation offset
- direction: 1, // 1: clockwise, -1: counterclockwise
- color: Editor.isDarkMode() ? '#c0c0c0' : '#000', // #rgb or #rrggbb
- speed: 1.4, // Rounds per second
- trail: 60, // Afterglow percentage
- shadow: false, // Whether to render a shadow
- hwaccel: false, // Whether to use hardware acceleration
- className: 'spinner', // The CSS class to assign to the spinner
- zIndex: 2e9, // The z-index (defaults to 2000000000)
- top: '50%', // Top position relative to parent
- left: '50%' // Left position relative to parent
- };
-
- var spinner = new Spinner(opts);
- var file = editorUi.getCurrentFile();
- var fileNode = editorUi.getXmlFileData(true, false, true);
- var tmp = fileNode.getElementsByTagName('diagram');
- var currentDiagrams = {};
-
- for (var i = 0; i < tmp.length; i++)
- {
- currentDiagrams[tmp[i].getAttribute('id')] = tmp[i];
- }
- var currentRow = null;
- var currentRev = null;
- var currentDoc = null;
- var currentXml = null;
- var zoomInBtn = editorUi.createToolbarButton(Editor.zoomInImage, mxResources.get('zoomIn'), function()
- {
- if (currentDoc != null)
- {
- graph.zoomIn();
- }
- }, 20);
- zoomInBtn.setAttribute('disabled', 'disabled');
- var zoomOutBtn = editorUi.createToolbarButton(Editor.zoomOutImage, mxResources.get('zoomOut'), function()
- {
- if (currentDoc != null)
- {
- graph.zoomOut();
- }
- }, 20);
- zoomOutBtn.setAttribute('disabled', 'disabled');
- var zoomFitBtn = editorUi.createToolbarButton(Editor.zoomFitImage, mxResources.get('fit'), function()
- {
- if (currentDoc != null)
- {
- if (graph.view.scale == 1)
- {
- graph.maxFitScale = 8;
- graph.fit(8);
- }
- else
- {
- graph.zoomActual();
- }
- graph.center();
- }
- }, 20);
- zoomFitBtn.setAttribute('disabled', 'disabled');
- // Gesture listener added below to handle pressed state
- var compareBtn = editorUi.createToolbarButton(Editor.compareImage, mxResources.get('compare'), null, 20);
- compareBtn.setAttribute('disabled', 'disabled');
- var mergeBtn = editorUi.createToolbarButton(Editor.thinDataImage, mxResources.get('merge'), null, 20);
- mergeBtn.setAttribute('disabled', 'disabled');
-
- var cmpContainer = container.cloneNode(false);
- cmpContainer.style.pointerEvent = 'none';
- container.parentNode.appendChild(cmpContainer);
- var cmpGraph = new Graph(cmpContainer);
- cmpGraph.setTooltips(false);
- cmpGraph.setEnabled(false);
- cmpGraph.setPanning(true);
- cmpGraph.panningHandler.ignoreCell = true;
- cmpGraph.panningHandler.useLeftButtonForPanning = true;
- cmpGraph.minFitScale = null;
- cmpGraph.maxFitScale = null;
- cmpGraph.centerZoom = true;
- var fileInfo = document.createElement('div');
- fileInfo.style.textAlign = 'left';
- fileInfo.style.color = 'gray';
- fileInfo.style.backgroundColor = 'transparent';
- fileInfo.style.overflow = 'hidden';
- fileInfo.style.textOverflow = 'ellipsis';
- fileInfo.style.whiteSpace = 'nowrap';
- fileInfo.style.cursor = 'default';
- fileInfo.style.height = '100%';
- fileInfo.style.display = 'inline-flex';
- fileInfo.style.alignItems = 'center';
- fileInfo.style.flexGrow = '1';
- mxEvent.addListener(fileInfo, 'click', function()
- {
- var textContent = mxUtils.getTextContent(fileInfo);
- if (textContent != '')
- {
- editorUi.alert(textContent);
- }
- });
- var prevFileInfo = null;
- mxEvent.addGestureListeners(compareBtn, function(e)
- {
- // Gets current state of page with given ID
- try
- {
- var curr = (diagrams[currentPage] != null) ? currentDiagrams[
- diagrams[currentPage].getAttribute('id')] : null;
- mxUtils.setOpacity(compareBtn, 20);
- errorNode.innerText = '';
- if (curr == null)
- {
- errorNode.style.display = 'inline-block';
- mxUtils.write(errorNode, mxResources.get('pageNotFound'));
- }
- else
- {
- prevFileInfo = fileInfo.innerHTML;
- fileInfo.innerHTML = mxResources.get('current');
- container.style.display = 'none';
- cmpContainer.style.display = '';
- cmpContainer.style.backgroundColor = container.style.backgroundColor;
- var tempNode = Editor.parseDiagramNode(curr);
- var codec = new mxCodec(tempNode.ownerDocument);
- codec.decode(tempNode, cmpGraph.getModel());
- cmpGraph.view.scaleAndTranslate(graph.view.scale,
- graph.view.translate.x, graph.view.translate.y);
- cmpGraph.mathEnabled = tempNode.getAttribute('math') == '1';
-
- if (Editor.MathJaxRender && cmpGraph.mathEnabled)
- {
- Editor.MathJaxRender(cmpGraph.container);
- }
- }
- }
- catch (e)
- {
- errorNode.style.display = 'inline-block';
- errorNode.innerText = '';
- mxUtils.write(errorNode, mxResources.get('pageNotFound') + ': ' + e.message);
- }
- }, null, function()
- {
- mxUtils.setOpacity(compareBtn, 60);
- errorNode.style.display = 'none';
- errorNode.innerText = '';
- if (container.style.display == 'none')
- {
- container.style.display = '';
- fileInfo.innerHTML = prevFileInfo;
- cmpContainer.style.display = 'none';
- }
- });
- mxEvent.addListener(mergeBtn, 'click', mxUtils.bind(this, function(e)
- {
- if (currentDoc != null)
- {
- var pages = editorUi.getPagesForNode(currentDoc.documentElement);
- var patch = editorUi.diffPages(editorUi.pages, pages);
- var dlg = new TextareaDialog(editorUi, mxResources.get('merge') + ':',
- JSON.stringify(patch, null, 2), function(newValue)
- {
- try
- {
- if (newValue.length > 0 && editorUi.editor.graph.isEnabled())
- {
- var patches = [JSON.parse(newValue)];
- editorUi.confirm(mxResources.get('areYouSure'), function()
- {
- try
- {
- file.patch(patches, null, true, true);
- // Hides compare dialog
- editorUi.hideDialog();
- // Hides revision history dialog
- editorUi.hideDialog();
- }
- catch (e)
- {
- editorUi.handleError(e);
- }
- });
- }
- else
- {
- // Hides compare dialog
- editorUi.hideDialog();
- }
- }
- catch (e)
- {
- editorUi.handleError(e);
- }
- }, null, null, null, null, null, true, null,
- mxResources.get(editorUi.editor.graph.isEnabled() ?
- 'merge' : 'close'));
-
- editorUi.showDialog(dlg.container, 620, 460, true, true);
- dlg.init();
- }
- }));
- var restoreBtn = mxUtils.button(mxResources.get('restore'), function(e)
- {
- if (currentDoc != null && currentXml != null)
- {
- editorUi.confirm(mxResources.get('areYouSure'), function()
- {
- if (restoreFn != null)
- {
- restoreFn(currentXml);
- }
- else
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('restoring')))
- {
- restoreBtn.setAttribute('disabled', 'disabled');
-
- file.save(true, function(resp)
- {
- editorUi.spinner.stop();
- restoreBtn.removeAttribute('disabled');
- editorUi.replaceFileData(currentXml);
- editorUi.hideDialog();
- }, function(resp)
- {
- editorUi.spinner.stop();
- restoreBtn.removeAttribute('disabled');
- editorUi.editor.setStatus('');
- editorUi.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
- });
- }
- }
- });
- }
- });
- restoreBtn.className = 'geBtn gePrimaryBtn';
- restoreBtn.setAttribute('disabled', 'disabled');
-
- var pageSelect = document.createElement('select');
- pageSelect.setAttribute('disabled', 'disabled');
- pageSelect.style.userSelect = 'none';
- pageSelect.style.maxWidth = '100px';
- pageSelect.style.marginLeft = '10px';
- pageSelect.style.display = 'none';
-
- var pageSelectFunction = null;
-
- mxEvent.addListener(pageSelect, 'change', function(evt)
- {
- if (pageSelectFunction != null)
- {
- pageSelectFunction(evt);
- mxEvent.consume(evt);
- }
- });
-
- var newBtn = mxUtils.button(mxResources.get('open'), function()
- {
- if (currentDoc != null)
- {
- window.openFile = new OpenFile(function()
- {
- window.openFile = null;
- });
-
- window.openFile.setData(mxUtils.getXml(currentDoc.documentElement));
- editorUi.openLink(editorUi.getUrl(), null, true);
- }
- });
- newBtn.className = 'geBtn';
- newBtn.setAttribute('disabled', 'disabled');
- var createBtn = mxUtils.button(mxResources.get('createRevision'), function()
- {
- editorUi.actions.get('save').funct(false);
- });
- createBtn.className = 'geBtn';
- createBtn.setAttribute('disabled', 'disabled');
-
- if (restoreFn != null)
- {
- newBtn.style.display = 'none';
- }
-
- var buttons = document.createElement('div');
- buttons.style.position = 'absolute';
- buttons.style.top = '482px';
- buttons.style.right = '28px';
- buttons.style.left = '32px';
- buttons.style.justifyContent = 'end';
- buttons.style.display = 'flex';
- var tb = document.createElement('div');
- tb.className = 'geToolbarContainer';
- tb.style.backgroundColor = 'transparent';
- tb.style.display = 'flex';
- tb.style.alignItems = 'center';
- tb.style.justifyContent = 'stretch';
- tb.style.left = '32px';
- tb.style.right = '32px';
- tb.style.border = 'none';
- tb.style.top = '440px';
- tb.style.height = '28px';
-
- var currentElt = null;
- if (revs != null && revs.length > 0)
- {
- container.style.cursor = 'move';
-
- var table = document.createElement('table');
- table.style.border = '1px solid lightGray';
- table.style.borderCollapse = 'collapse';
- table.style.borderSpacing = '0px';
- table.style.width = '100%';
- var tbody = document.createElement('tbody');
- var today = new Date().toDateString();
- if (editorUi.currentPage != null && editorUi.pages != null)
- {
- currentPage = mxUtils.indexOf(editorUi.pages, editorUi.currentPage);
- }
-
- for (var i = revs.length - 1; i >= 0; i--)
- {
- var elt = (function(item)
- {
- var ts = new Date(item.modifiedDate);
- var row = null;
- var pd = '6px';
-
- // Workaround for negative timestamps in Dropbox
- if (ts.getTime() >= 0)
- {
- row = document.createElement('tr');
- row.style.borderBottom = '1px solid lightGray';
- row.style.fontSize = '12px';
- row.style.cursor = 'pointer';
-
- var date = document.createElement('td');
- date.style.padding = pd;
- date.style.whiteSpace = 'nowrap';
-
- if (item == revs[revs.length - 1])
- {
- mxUtils.write(date, mxResources.get('current'));
- }
- else
- {
- if (ts.toDateString() === today)
- {
- mxUtils.write(date, ts.toLocaleTimeString());
- }
- else
- {
- mxUtils.write(date, ts.toLocaleDateString() + ' ' +
- ts.toLocaleTimeString());
- }
- }
-
- row.appendChild(date);
- row.setAttribute('title', ts.toLocaleDateString() + ' ' +
- ts.toLocaleTimeString() +
- ((item.fileSize != null)? ' ' + editorUi.formatFileSize(parseInt(item.fileSize)) : '') +
- ((item.lastModifyingUserName != null) ? ' ' + item.lastModifyingUserName : ''));
- function updateGraph(xml)
- {
- spinner.stop();
- errorNode.innerText = '';
- var doc = mxUtils.parseXml(xml);
- var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
- if (node != null)
- {
- pageSelect.style.display = 'none';
- pageSelect.innerText = '';
- currentDoc = doc;
- currentXml = xml;
- parseSelectFunction = null;
- diagrams = null;
- realPage = 0;
-
- function parseGraphModel(dataNode)
- {
- var bg = dataNode.getAttribute('background');
-
- if (bg == null || bg == '' || bg == mxConstants.NONE)
- {
- bg = graph.defaultPageBackgroundColor;
- }
-
- container.style.backgroundColor = bg;
-
- var codec = new mxCodec(dataNode.ownerDocument);
- codec.decode(dataNode, graph.getModel());
- graph.maxFitScale = 1;
- graph.fit(8);
- graph.center();
- graph.mathEnabled = dataNode.getAttribute('math') == '1';
- if (Editor.MathJaxRender && graph.mathEnabled)
- {
- Editor.MathJaxRender(graph.container);
- }
- return dataNode;
- };
-
- function parseDiagram(diagramNode)
- {
- if (diagramNode != null)
- {
- diagramNode = parseGraphModel(Editor.parseDiagramNode(diagramNode));
- }
-
- return diagramNode;
- };
- if (node.nodeName == 'mxfile')
- {
- // Workaround for "invalid calling object" error in IE
- var tmp = node.getElementsByTagName('diagram');
- var newPages = {};
- diagrams = [];
-
- for (var i = 0; i < tmp.length; i++)
- {
- diagrams.push(tmp[i]);
- }
-
- realPage = Math.min(currentPage, diagrams.length - 1);
-
- if (diagrams.length > 0)
- {
- parseDiagram(diagrams[realPage]);
- }
-
- if (diagrams.length > 1)
- {
- pageSelect.removeAttribute('disabled');
- pageSelect.style.display = '';
- for (var i = 0; i < diagrams.length; i++)
- {
- var pageOption = document.createElement('option');
- pageOption.setAttribute('title', name + ' (' +
- diagrams[i].getAttribute('id') + ')');
- pageOption.setAttribute('value', i);
- var name = diagrams[i].getAttribute('name') ||
- mxResources.get('pageWithNumber', [i + 1]);
- var localPage = editorUi.getPageById(diagrams[i].getAttribute('id'));
- var state = '';
-
- if (localPage != null)
- {
- var newPage = new DiagramPage(diagrams[i]);
- if (editorUi.getHashValueForPages([localPage]) != editorUi.getHashValueForPages([newPage]))
- {
- state = ' (M)';
- }
- }
- else
- {
- state = ' (X)';
- }
- mxUtils.write(pageOption, name + state);
-
- if (i == realPage)
- {
- pageOption.setAttribute('selected', 'selected');
- }
-
- pageSelect.appendChild(pageOption);
- }
- }
-
- pageSelectFunction = function()
- {
- try
- {
- var temp = parseInt(pageSelect.value);
- currentPage = temp;
- realPage = currentPage;
- parseDiagram(diagrams[temp]);
- }
- catch (e)
- {
- pageSelect.value = currentPage;
- editorUi.handleError(e);
- }
- };
- }
- else
- {
- parseGraphModel(node);
- }
-
- var shortUser = item.lastModifyingUserName;
-
- if (shortUser != null && shortUser.length > 20)
- {
- shortUser = shortUser.substring(0, 20) + '...';
- }
-
- fileInfo.innerText = '';
- mxUtils.write(fileInfo, ((shortUser != null) ?
- (shortUser + ' ') : '') + ts.toLocaleDateString() +
- ' ' + ts.toLocaleTimeString());
-
- fileInfo.setAttribute('title', row.getAttribute('title'));
- zoomInBtn.removeAttribute('disabled');
- zoomOutBtn.removeAttribute('disabled');
- zoomFitBtn.removeAttribute('disabled');
- compareBtn.removeAttribute('disabled');
- mergeBtn.removeAttribute('disabled');
-
- if (file == null || !file.isRestricted())
- {
- if (editorUi.editor.graph.isEnabled())
- {
- restoreBtn.removeAttribute('disabled');
- }
- newBtn.removeAttribute('disabled');
- createBtn.removeAttribute('disabled');
- }
-
- mxUtils.setOpacity(zoomInBtn, 60);
- mxUtils.setOpacity(zoomOutBtn, 60);
- mxUtils.setOpacity(zoomFitBtn, 60);
- mxUtils.setOpacity(compareBtn, 60);
- mxUtils.setOpacity(mergeBtn, 60);
- }
- else
- {
- pageSelect.style.display = 'none';
- pageSelect.innerText = '';
- fileInfo.innerText = '';
- errorNode.innerText = '';
- mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
- mxUtils.write(errorNode, mxResources.get('errorLoadingFile'));
- }
- };
-
- mxEvent.addListener(row, 'click', function(evt)
- {
- if (currentRev != item)
- {
- spinner.stop();
-
- if (currentRow != null)
- {
- currentRow.style.backgroundColor = '';
- }
-
- currentRev = item;
- currentRow = row;
- currentRow.style.backgroundColor = Editor.isDarkMode() ? '#000000' : '#ebf2f9';
- currentDoc = null;
- currentXml = null;
- fileInfo.removeAttribute('title');
- fileInfo.innerText = mxResources.get('loading') + '...';
- container.style.backgroundColor = graph.defaultPageBackgroundColor;
- errorNode.innerText = '';
- graph.getModel().clear();
-
- restoreBtn.setAttribute('disabled', 'disabled');
- zoomInBtn.setAttribute('disabled', 'disabled');
- zoomOutBtn.setAttribute('disabled', 'disabled');
- zoomFitBtn.setAttribute('disabled', 'disabled');
- compareBtn.setAttribute('disabled', 'disabled');
- mergeBtn.setAttribute('disabled', 'disabled');
- newBtn.setAttribute('disabled', 'disabled');
- pageSelect.setAttribute('disabled', 'disabled');
-
- mxUtils.setOpacity(zoomInBtn, 20);
- mxUtils.setOpacity(zoomOutBtn, 20);
- mxUtils.setOpacity(zoomFitBtn, 20);
- mxUtils.setOpacity(compareBtn, 20);
- mxUtils.setOpacity(mergeBtn, 20);
- spinner.spin(container);
-
- item.getXml(function(xml)
- {
- if (currentRev == item)
- {
- try
- {
- updateGraph(xml);
- }
- catch (e)
- {
- fileInfo.innerText = mxResources.get('error') + ': ' + e.message;
- }
- }
- }, function(err)
- {
- spinner.stop();
- pageSelect.style.display = 'none';
- pageSelect.innerText = '';
- fileInfo.innerText = '';
- mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
- mxUtils.write(errorNode, mxResources.get('errorLoadingFile'));
- });
- mxEvent.consume(evt);
- }
- });
-
- mxEvent.addListener(row, 'dblclick', function(evt)
- {
- newBtn.click();
-
- if (window.getSelection)
- {
- window.getSelection().removeAllRanges();
- }
- else if (document.selection)
- {
- document.selection.empty();
- }
-
- mxEvent.consume(evt);
- }, false);
-
- tbody.appendChild(row);
- }
- return row;
- })(revs[i]);
-
- // Selects and loads first element in list (ie current version) after
- // graph container was initialized since there is no loading delay
- if (elt != null && i == revs.length - 1)
- {
- currentElt = elt;
- }
- }
-
- table.appendChild(tbody);
- list.appendChild(table);
- }
- else if (file == null || (editorUi.drive == null && file.constructor == window.DriveFile) ||
- (editorUi.dropbox == null && file.constructor == window.DropboxFile))
- {
- container.style.display = 'none';
- tb.style.display = 'none';
- mxUtils.write(list, mxResources.get('notAvailable'));
- }
- else
- {
- container.style.display = 'none';
- tb.style.display = 'none';
- mxUtils.write(list, mxResources.get('noRevisions'));
- }
-
- this.init = function()
- {
- if (currentElt != null)
- {
- currentElt.click();
- }
- };
- var closeBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- closeBtn.className = 'geBtn';
- tb.appendChild(fileInfo);
- tb.appendChild(compareBtn);
- tb.appendChild(zoomOutBtn);
- tb.appendChild(zoomFitBtn);
- tb.appendChild(zoomInBtn);
- tb.appendChild(pageSelect);
- tb.appendChild(mergeBtn);
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(closeBtn);
- }
- buttons.appendChild(newBtn);
- if (file != null && file.constructor == DriveFile)
- {
- buttons.appendChild(createBtn);
- }
- buttons.appendChild(restoreBtn);
- if (!editorUi.editor.cancelFirst)
- {
- buttons.appendChild(closeBtn);
- }
- div.appendChild(buttons);
- div.appendChild(tb);
- this.container = div;
- };
- /**
- * Constructs a new revision dialog
- */
- var DraftDialog = function(editorUi, title, xml, editFn, discardFn, editLabel, discardLabel, ignoreFn, drafts)
- {
- var div = document.createElement('div');
-
- var titleDiv = document.createElement('div');
- titleDiv.style.marginTop = '0px';
- titleDiv.style.whiteSpace = 'nowrap';
- titleDiv.style.overflow = 'auto';
- titleDiv.style.lineHeight = 'normal';
- mxUtils.write(titleDiv, title);
- div.appendChild(titleDiv);
-
- var select = document.createElement('select');
-
- var draftSelected = mxUtils.bind(this, function()
- {
- if (select.value == '-1')
- {
- select.value = select.options[0].value;
- draftSelected();
- // Discard all drafts
- editorUi.confirm(mxResources.get('areYouSure'), null, mxUtils.bind(this, async function()
- {
- for (var i = 0; i < drafts.length; i++)
- {
- discardFn.apply(this, [i, mxUtils.bind(this, function()
- {
- // Do nothing
- })]);
- }
- editorUi.hideDialog(true);
- }), mxResources.get('no'), mxResources.get('yes'));
- }
- else
- {
- doc = mxUtils.parseXml(drafts[select.value].data);
- node = editorUi.editor.extractGraphModel(doc.documentElement, true);
- currentPage = 0;
-
- this.init();
- }
- });
-
- if (drafts != null)
- {
- select.style.marginLeft = '4px';
-
- for (var i = 0; i < drafts.length; i++)
- {
- var opt = document.createElement('option');
- opt.setAttribute('value', i);
- var ts0 = new Date(drafts[i].created);
- var ts1 = new Date(drafts[i].modified);
-
- mxUtils.write(opt, ts0.toLocaleDateString() + ' ' +
- ts0.toLocaleTimeString() + ' - ' +
- ((ts0.toDateString() != ts1.toDateString() || true) ?
- ts1.toLocaleDateString() : ' ') +
- ' ' + ts1.toLocaleTimeString());
-
- select.appendChild(opt);
- }
- // Delete all option
- var opt = document.createElement('option');
- opt.setAttribute('value', '-1');
- mxUtils.write(opt, mxResources.get('deleteAll'));
- select.appendChild(opt);
- titleDiv.appendChild(select);
- mxEvent.addListener(select, 'change', draftSelected);
- }
-
- if (xml == null)
- {
- xml = drafts[0].data;
- }
-
- var container = document.createElement('div');
- container.style.position = 'absolute';
- container.style.border = '1px solid lightGray';
- container.style.marginTop = '10px';
- container.style.left = '40px';
- container.style.right = '40px';
- container.style.top = '46px';
- container.style.bottom = '74px';
- container.style.overflow = 'hidden';
-
- mxEvent.disableContextMenu(container);
- div.appendChild(container);
- var graph = new Graph(container);
- graph.setEnabled(false);
- graph.setPanning(true);
- graph.shapeBackgroundColor = (Editor.isDarkMode() ? '#2a252f' : '#ffffff');
- graph.panningHandler.ignoreCell = true;
- graph.panningHandler.useLeftButtonForPanning = true;
- graph.minFitScale = null;
- graph.maxFitScale = null;
- graph.centerZoom = true;
-
- // Handles placeholders for pages
- var doc = mxUtils.parseXml(xml);
- var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
- var currentPage = 0;
- var diagrams = null;
- var graphGetGlobalVariable = graph.getGlobalVariable;
- graph.getGlobalVariable = function(name)
- {
- if (name == 'page' && diagrams != null && diagrams[currentPage] != null)
- {
- return diagrams[currentPage].getAttribute('name');
- }
- else if (name == 'pagenumber')
- {
- return currentPage + 1;
- }
- else if (name == 'pagecount')
- {
- return (diagrams != null) ? diagrams.length : 1;
- }
-
- return graphGetGlobalVariable.apply(this, arguments);
- };
-
- // Disables hyperlinks
- graph.getLinkForCell = function()
- {
- return null;
- };
-
- var zoomInBtn = editorUi.createToolbarButton(Editor.zoomInImage, mxResources.get('zoomIn'), function()
- {
- graph.zoomIn();
- }, 20);
- var zoomOutBtn = editorUi.createToolbarButton(Editor.zoomInImage, mxResources.get('zoomOut'), function()
- {
- graph.zoomOut();
- }, 20);
- var zoomFitBtn = editorUi.createToolbarButton(Editor.zoomFitImage, mxResources.get('fit'), function()
- {
- if (graph.view.scale == 1)
- {
- graph.maxFitScale = 8;
- graph.fit(8);
- }
- else
- {
- graph.zoomActual();
- }
- graph.center();
- }, 20);
- var restoreBtn = mxUtils.button(discardLabel || mxResources.get('discard'), function()
- {
- editorUi.confirm(mxResources.get('areYouSure'), null, mxUtils.bind(this, async function()
- {
- discardFn.apply(this, [select.value, mxUtils.bind(this, function()
- {
- if (select.parentNode != null)
- {
- select.options[select.selectedIndex].parentNode.removeChild(select.options[select.selectedIndex]);
-
- if (select.options.length > 1)
- {
- select.value = select.options[0].value;
- draftSelected();
- }
- else
- {
- editorUi.hideDialog(true);
- }
- }
- })]);
- }), mxResources.get('no'), mxResources.get('yes'));
- });
- restoreBtn.className = 'geBtn';
-
- var pageSelect = document.createElement('select');
- pageSelect.style.maxWidth = '80px';
- pageSelect.style.position = 'relative';
- pageSelect.style.top = '-2px';
- pageSelect.style.verticalAlign = 'bottom';
- pageSelect.style.marginRight = '6px';
- pageSelect.style.display = 'none';
- var showBtn = mxUtils.button(editLabel || mxResources.get('edit'), function()
- {
- editFn.apply(this, [select.value])
- });
- showBtn.className = 'geBtn gePrimaryBtn';
- var buttons = document.createElement('div');
- buttons.style.position = 'absolute';
- buttons.style.bottom = '30px';
- buttons.style.right = '40px';
- buttons.style.textAlign = 'right';
- var tb = document.createElement('div');
- tb.className = 'geToolbarContainer';
- tb.style.cssText = 'box-shadow:none !important;background-color:transparent;' +
- 'padding:2px;border-style:none !important;bottom:30px;';
- this.init = function()
- {
- function parseGraphModel(dataNode)
- {
- if (dataNode != null)
- {
- var bg = dataNode.getAttribute('background');
-
- if (bg == null || bg == '' || bg == mxConstants.NONE)
- {
- bg = Editor.isDarkMode() ? 'transparent' : '#ffffff';
- }
-
- container.style.backgroundColor = bg;
-
- var codec = new mxCodec(dataNode.ownerDocument);
- codec.decode(dataNode, graph.getModel());
- graph.maxFitScale = 1;
- graph.fit(8);
- graph.center();
- }
-
- return dataNode;
- };
-
- function parseDiagram(diagramNode)
- {
- if (diagramNode != null)
- {
- diagramNode = parseGraphModel(Editor.parseDiagramNode(diagramNode));
- }
-
- return diagramNode;
- };
- mxEvent.addListener(pageSelect, 'change', function(evt)
- {
- currentPage = parseInt(pageSelect.value);
- parseDiagram(diagrams[currentPage]);
- mxEvent.consume(evt);
- });
-
- if (node.nodeName == 'mxfile')
- {
- // Workaround for "invalid calling object" error in IE
- var tmp = node.getElementsByTagName('diagram');
- diagrams = [];
-
- for (var i = 0; i < tmp.length; i++)
- {
- diagrams.push(tmp[i]);
- }
-
- if (diagrams.length > 0)
- {
- parseDiagram(diagrams[currentPage]);
- }
- pageSelect.innerText = '';
-
- if (diagrams.length > 1)
- {
- pageSelect.style.display = '';
-
- for (var i = 0; i < diagrams.length; i++)
- {
- var pageOption = document.createElement('option');
- mxUtils.write(pageOption, diagrams[i].getAttribute('name') ||
- mxResources.get('pageWithNumber', [i + 1]));
- pageOption.setAttribute('value', i);
-
- if (i == currentPage)
- {
- pageOption.setAttribute('selected', 'selected');
- }
-
- pageSelect.appendChild(pageOption);
- }
- }
- else
- {
- pageSelect.style.display = 'none';
- }
- }
- else
- {
- parseGraphModel(node);
- }
- };
-
- tb.appendChild(pageSelect);
- tb.appendChild(zoomInBtn);
- tb.appendChild(zoomOutBtn);
- tb.appendChild(zoomFitBtn);
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog(true);
- });
-
- cancelBtn.className = 'geBtn';
-
- var ignoreBtn = (ignoreFn != null) ? mxUtils.button(mxResources.get('ignore'), ignoreFn) : null;
-
- if (ignoreBtn != null)
- {
- ignoreBtn.className = 'geBtn';
- }
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
-
- if (ignoreBtn != null)
- {
- buttons.appendChild(ignoreBtn);
- }
-
- buttons.appendChild(restoreBtn);
- buttons.appendChild(showBtn);
- }
- else
- {
- buttons.appendChild(showBtn);
- buttons.appendChild(restoreBtn);
-
- if (ignoreBtn != null)
- {
- buttons.appendChild(ignoreBtn);
- }
-
- buttons.appendChild(cancelBtn);
- }
- div.appendChild(buttons);
- div.appendChild(tb);
- this.container = div;
- };
- /**
- *
- */
- var FindWindow = function(ui, x, y, w, h, withReplace)
- {
- var action = ui.actions.get('findReplace');
-
- var graph = ui.editor.graph;
- var lastSearch = null;
- var lastFound = null;
- var lastSearchSuccessful = false;
- var allChecked = false;
- var lblMatch = null;
- var lblMatchPos = 0;
- var marker = 1;
-
- var div = document.createElement('div');
- div.style.userSelect = 'none';
- div.style.overflow = 'hidden';
- div.style.padding = '10px';
- div.style.height = '100%';
-
- var txtWidth = withReplace? '260px' : '200px';
- var searchInput = document.createElement('input');
- searchInput.setAttribute('placeholder', mxResources.get('find'));
- searchInput.setAttribute('type', 'text');
- searchInput.style.marginTop = '4px';
- searchInput.style.marginBottom = '6px';
- searchInput.style.width = txtWidth;
- searchInput.style.fontSize = '12px';
- searchInput.style.borderRadius = '4px';
- searchInput.style.padding = '6px';
- div.appendChild(searchInput);
- mxUtils.br(div);
-
- var replaceInput;
-
- if (withReplace)
- {
- replaceInput = document.createElement('input');
- replaceInput.setAttribute('placeholder', mxResources.get('replaceWith'));
- replaceInput.setAttribute('type', 'text');
- replaceInput.style.marginTop = '4px';
- replaceInput.style.marginBottom = '6px';
- replaceInput.style.width = txtWidth;
- replaceInput.style.fontSize = '12px';
- replaceInput.style.borderRadius = '4px';
- replaceInput.style.padding = '6px';
- div.appendChild(replaceInput);
- mxUtils.br(div);
-
- mxEvent.addListener(replaceInput, 'input', updateReplBtns);
- }
-
- var regexInput = document.createElement('input');
- regexInput.setAttribute('id', 'geFindWinRegExChck');
- regexInput.setAttribute('type', 'checkbox');
- regexInput.style.marginRight = '4px';
- div.appendChild(regexInput);
-
- var regexLabel = document.createElement('label');
- regexLabel.setAttribute('for', 'geFindWinRegExChck');
- div.appendChild(regexLabel);
- mxUtils.write(regexLabel, mxResources.get('regularExpression'));
- div.appendChild(regexLabel);
-
- var help = ui.menus.createHelpLink('https://www.drawio.com/doc/faq/find-shapes');
- help.style.position = 'relative';
- help.style.marginLeft = '6px';
- help.style.top = '3px';
- div.appendChild(help);
-
- mxUtils.br(div);
- var allPagesInput = document.createElement('input');
- allPagesInput.setAttribute('id', 'geFindWinAllPagesChck');
- allPagesInput.setAttribute('type', 'checkbox');
- allPagesInput.style.marginRight = '4px';
- div.appendChild(allPagesInput);
-
- var allPagesLabel = document.createElement('label');
- allPagesLabel.setAttribute('for', 'geFindWinAllPagesChck');
- div.appendChild(allPagesLabel);
- mxUtils.write(allPagesLabel, mxResources.get('allPages'));
- div.appendChild(allPagesLabel);
-
- var tmp = document.createElement('div');
-
- function testMeta(re, cell, search)
- {
- if (typeof cell.value === 'object' && cell.value.attributes != null)
- {
- var attrs = cell.value.attributes;
-
- for (var i = 0; i < attrs.length; i++)
- {
- if (attrs[i].nodeName != 'label')
- {
- var value = mxUtils.trim(attrs[i].nodeValue.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' ')).toLowerCase();
-
- if ((re == null && value.indexOf(search) >= 0) ||
- (re != null && re.test(value)))
- {
- return true;
- }
- }
- }
- }
-
- return false;
- };
-
- function updateReplBtns()
- {
- if (lastSearchSuccessful)
- {
- replaceFindBtn.removeAttribute('disabled');
- replaceBtn.removeAttribute('disabled');
- }
- else
- {
- replaceFindBtn.setAttribute('disabled', 'disabled');
- replaceBtn.setAttribute('disabled', 'disabled');
- }
-
- if (searchInput.value)
- {
- replaceAllBtn.removeAttribute('disabled');
- }
- else
- {
- replaceAllBtn.setAttribute('disabled', 'disabled');
- }
- }
-
- function search(internalCall, trySameCell, stayOnPage)
- {
- replAllNotif.innerText = '';
- var cells = graph.model.getDescendants(graph.model.getRoot());
- var searchStr = searchInput.value.toLowerCase();
- var re = (regexInput.checked) ? new RegExp(searchStr) : null;
- var firstMatch = null;
- lblMatch = null;
-
- if (lastSearch != searchStr)
- {
- lastSearch = searchStr;
- lastFound = null;
- allChecked = false;
- }
- var active = lastFound == null;
-
- if (searchStr.length > 0)
- {
- if (allChecked)
- {
- allChecked = false;
-
- //Find current page index
- var currentPageIndex;
-
- for (var i = 0; i < ui.pages.length; i++)
- {
- if (ui.currentPage == ui.pages[i])
- {
- currentPageIndex = i;
- break;
- }
- }
-
- var nextPageIndex = (currentPageIndex + 1) % ui.pages.length, nextPage;
- lastFound = null;
-
- do
- {
- allChecked = false;
- nextPage = ui.pages[nextPageIndex];
- graph = ui.createTemporaryGraph(graph.getStylesheet());
- ui.updatePageRoot(nextPage);
- graph.model.setRoot(nextPage.root);
- nextPageIndex = (nextPageIndex + 1) % ui.pages.length;
- }
- while(!search(true, trySameCell, stayOnPage) && nextPageIndex != currentPageIndex);
-
- if (lastFound)
- {
- lastFound = null;
-
- if (!stayOnPage)
- {
- ui.selectPage(nextPage);
- }
- else
- {
- ui.editor.graph.model.execute(new SelectPage(ui, nextPage));
- }
- }
-
- allChecked = false;
- graph = ui.editor.graph;
-
- return search(true, trySameCell, stayOnPage);
- }
-
- var i;
-
- for (i = 0; i < cells.length; i++)
- {
- var state = graph.view.getState(cells[i]);
-
- //Try the same cell with replace to find other occurances
- if (trySameCell)
- {
- active = active || state == lastFound;
- }
-
- if (state != null && state.cell.value != null && (active || firstMatch == null) &&
- (graph.model.isVertex(state.cell) || graph.model.isEdge(state.cell)))
- {
- if (state.style != null && state.style['html'] == '1')
- {
- tmp.innerHTML = graph.sanitizeHtml(graph.getLabel(state.cell));
- label = mxUtils.extractTextWithWhitespace([tmp]);
- }
- else
- {
- label = graph.getLabel(state.cell);
- }
-
- label = mxUtils.trim(label.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' ')).toLowerCase();
- var lblPosShift = 0;
-
- if (trySameCell && withReplace && state == lastFound)
- {
- label = label.substr(lblMatchPos);
- lblPosShift = lblMatchPos;
- }
-
- var checkMeta = replaceInput.value == '';
-
- if ((re == null && ((label.indexOf(searchStr) >= 0) ||
- (checkMeta && testMeta(re, state.cell, searchStr)))) ||
- (re != null && (re.test(label) || (checkMeta &&
- testMeta(re, state.cell, searchStr)))))
- {
- if (withReplace)
- {
- if (re != null)
- {
- var result = label.match(re);
- if (result != null && result.length > 0)
- {
- lblMatch = result[0].toLowerCase();
- lblMatchPos = lblPosShift + result.index + lblMatch.length;
- }
- }
- else
- {
- lblMatch = searchStr;
- lblMatchPos = lblPosShift + label.indexOf(searchStr) + lblMatch.length;
- }
- }
-
- if (active)
- {
- firstMatch = state;
-
- break;
- }
- else if (firstMatch == null)
- {
- firstMatch = state;
- }
- }
- }
-
- active = active || state == lastFound;
- }
- }
-
- if (firstMatch != null)
- {
- if (i == cells.length && allPagesInput.checked)
- {
- lastFound = null;
- allChecked = true;
- return search(true, trySameCell, stayOnPage);
- }
-
- lastFound = firstMatch;
- graph.scrollCellToVisible(lastFound.cell);
-
- if (graph.isEnabled() && !graph.isCellLocked(lastFound.cell))
- {
- if (!stayOnPage &&
- (graph.getSelectionCell() != lastFound.cell ||
- graph.getSelectionCount() != 1))
- {
- graph.setSelectionCell(lastFound.cell);
- }
- }
- else
- {
- graph.highlightCell(lastFound.cell);
- }
- }
- //Check other pages
- else if (!internalCall && allPagesInput.checked)
- {
- allChecked = true;
- return search(true, trySameCell, stayOnPage);
- }
- else if (graph.isEnabled() && !stayOnPage)
- {
- graph.clearSelection();
- }
-
- lastSearchSuccessful = firstMatch != null;
-
- if (withReplace && !internalCall)
- {
- updateReplBtns();
- }
-
- return searchStr.length == 0 || firstMatch != null;
- };
- mxUtils.br(div);
-
- var btnsCont = document.createElement('div');
- btnsCont.style.left = '0px';
- btnsCont.style.right = '0px';
- btnsCont.style.marginTop = '6px';
- btnsCont.style.padding = '0 6px 0 6px';
- btnsCont.style.textAlign = 'center';
- div.appendChild(btnsCont);
- var resetBtn = mxUtils.button(mxResources.get('reset'), function()
- {
- replAllNotif.innerText = '';
- searchInput.value = '';
- searchInput.style.backgroundColor = '';
-
- if (withReplace)
- {
- replaceInput.value = '';
- updateReplBtns();
- }
-
- lastFound = null;
- lastSearch = null;
- allChecked = false;
- searchInput.focus();
- });
-
- resetBtn.setAttribute('title', mxResources.get('reset'));
- resetBtn.style.float = 'none';
- resetBtn.style.width = '120px';
- resetBtn.style.marginTop = '6px';
- resetBtn.style.marginLeft = '8px';
- resetBtn.style.overflow = 'hidden';
- resetBtn.style.textOverflow = 'ellipsis';
- resetBtn.className = 'geBtn';
-
- if (!withReplace)
- {
- btnsCont.appendChild(resetBtn);
- }
- var btn = mxUtils.button(mxResources.get('find'), function()
- {
- try
- {
- searchInput.style.backgroundColor = search() ? '' :
- (Editor.isDarkMode() ? '#ff0000' : '#ffcfcf');
- }
- catch (e)
- {
- ui.handleError(e);
- }
- });
-
- // TODO: Reset state after selection change
- btn.setAttribute('title', mxResources.get('find') + ' (Enter)');
- btn.style.float = 'none';
- btn.style.width = '120px';
- btn.style.marginTop = '6px';
- btn.style.marginLeft = '8px';
- btn.style.overflow = 'hidden';
- btn.style.textOverflow = 'ellipsis';
- btn.className = 'geBtn gePrimaryBtn';
-
- btnsCont.appendChild(btn);
- var replAllNotif = document.createElement('div');
- replAllNotif.style.marginTop = '10px';
-
- if (!withReplace)
- {
- resetBtn.style.width = '90px';
- btn.style.width = '90px';
- }
- else
- {
- function replaceInLabel(str, substr, newSubstr, startIndex, style)
- {
- if (style == null || style['html'] != '1')
- {
- var replStart = str.toLowerCase().indexOf(substr, startIndex);
- return replStart < 0? str : str.substr(0, replStart) + newSubstr + str.substr(replStart + substr.length);
- }
-
- var origStr = str;
- substr = mxUtils.htmlEntities(substr, false, false, false);
- var tagPos = [], p = -1;
-
- //Original position (startIndex) counts for \n which is removed when tags are removed, so handle <br> separately
- // The same for block level elements which are replaced by \n
- 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');
- while((p = str.indexOf('<', p + 1)) > -1)
- {
- tagPos.push(p);
- }
-
- var tags = str.match(/<[^>]*>/g);
- str = str.replace(/<[^>]*>/g, '');
- var lStr = str.toLowerCase();
- var replStart = lStr.indexOf(substr, startIndex);
-
- if (replStart < 0)
- {
- return origStr;
- }
-
- var replEnd = replStart + substr.length;
- var newSubstr = mxUtils.htmlEntities(newSubstr);
-
- //Tags within the replaced text is added before it
- var newStr = str.substr(0, replStart) + newSubstr + str.substr(replEnd);
- var tagDiff = 0;
-
- for (var i = 0; i < tagPos.length; i++)
- {
- if (tagPos[i] - tagDiff < replStart)
- {
- newStr = newStr.substr(0, tagPos[i]) + tags[i] + newStr.substr(tagPos[i]);
- }
- else if (tagPos[i] - tagDiff < replEnd)
- {
- var inPos = replStart + tagDiff;
- newStr = newStr.substr(0, inPos) + tags[i] + newStr.substr(inPos);
- }
- else
- {
- var inPos = tagPos[i] + (newSubstr.length - substr.length);
- newStr = newStr.substr(0, inPos) + tags[i] + newStr.substr(inPos);
- }
-
- tagDiff += tags[i].length;
- }
-
- return newStr.replace(/\n(<(BLOCKQUOTE|DIV|H1|H2|H3|H4|H5|H6|OL|P|PRE|TABLE|UL)[^>]*>)/ig, '$1').replace(/\n/g, '<br>');
- };
-
- var replaceFindBtn = mxUtils.button(mxResources.get('replFind'), function()
- {
- try
- {
- if (lblMatch != null && lastFound != null)
- {
- var cell = lastFound.cell, lbl = graph.getLabel(cell);
-
- if (graph.isCellEditable(cell))
- {
- graph.model.setValue(cell, replaceInLabel(lbl, lblMatch, replaceInput.value,
- lblMatchPos - lblMatch.length, graph.getCurrentCellStyle(cell)));
- }
-
- searchInput.style.backgroundColor = search(false, true) ? '' :
- (Editor.isDarkMode() ? '#ff0000' : '#ffcfcf');
- }
- }
- catch (e)
- {
- ui.handleError(e);
- }
- });
-
- replaceFindBtn.setAttribute('title', mxResources.get('replFind'));
- replaceFindBtn.style.float = 'none';
- replaceFindBtn.style.width = '120px';
- replaceFindBtn.style.marginTop = '6px';
- replaceFindBtn.style.marginLeft = '8px';
- replaceFindBtn.style.overflow = 'hidden';
- replaceFindBtn.style.textOverflow = 'ellipsis';
- replaceFindBtn.className = 'geBtn gePrimaryBtn';
- replaceFindBtn.setAttribute('disabled', 'disabled');
-
- btnsCont.appendChild(replaceFindBtn);
- mxUtils.br(btnsCont);
-
- var replaceBtn = mxUtils.button(mxResources.get('replace'), function()
- {
- try
- {
- if (lblMatch != null && lastFound != null)
- {
- var cell = lastFound.cell, lbl = graph.getLabel(cell);
-
- graph.model.setValue(cell, replaceInLabel(lbl, lblMatch, replaceInput.value,
- lblMatchPos - lblMatch.length, graph.getCurrentCellStyle(cell)));
- replaceFindBtn.setAttribute('disabled', 'disabled');
- replaceBtn.setAttribute('disabled', 'disabled');
- }
- }
- catch (e)
- {
- ui.handleError(e);
- }
- });
-
- replaceBtn.setAttribute('title', mxResources.get('replace'));
- replaceBtn.style.float = 'none';
- replaceBtn.style.width = '120px';
- replaceBtn.style.marginTop = '6px';
- replaceBtn.style.marginLeft = '8px';
- replaceBtn.style.overflow = 'hidden';
- replaceBtn.style.textOverflow = 'ellipsis';
- replaceBtn.className = 'geBtn gePrimaryBtn';
- replaceBtn.setAttribute('disabled', 'disabled');
-
- btnsCont.appendChild(replaceBtn);
-
- var replaceAllBtn = mxUtils.button(mxResources.get('replaceAll'), function()
- {
- replAllNotif.innerText = '';
-
- lastSearch = null; // Reset last search to check all matches
- var currentPage = ui.currentPage;
- var cells = ui.editor.graph.getSelectionCells();
- ui.editor.graph.rendering = false;
-
- graph.getModel().beginUpdate();
- try
- {
- var safeguard = 0;
- var seen = {};
-
- while (search(false, true, true) && safeguard < 100)
- {
- var cell = lastFound.cell, lbl = graph.getLabel(cell);
- var oldSeen = seen[cell.id];
-
- if (oldSeen && oldSeen.replAllMrk == marker && oldSeen.replAllPos >= lblMatchPos)
- {
- break;
- }
-
- seen[cell.id] = {replAllMrk: marker, replAllPos: lblMatchPos};
-
- if (graph.isCellEditable(cell))
- {
- graph.model.setValue(cell, replaceInLabel(lbl, lblMatch, replaceInput.value,
- lblMatchPos - lblMatch.length, graph.getCurrentCellStyle(cell)));
- safeguard++;
- }
- }
-
- if (currentPage != ui.currentPage)
- {
- ui.editor.graph.model.execute(new SelectPage(ui, currentPage));
- }
-
- mxUtils.write(replAllNotif, mxResources.get('matchesRepl', [safeguard]));
- }
- catch (e)
- {
- ui.handleError(e);
- }
- finally
- {
- graph.getModel().endUpdate();
- ui.editor.graph.setSelectionCells(cells);
- ui.editor.graph.rendering = true;
- }
-
- marker++;
- });
-
- replaceAllBtn.setAttribute('title', mxResources.get('replaceAll'));
- replaceAllBtn.style.float = 'none';
- replaceAllBtn.style.width = '120px';
- replaceAllBtn.style.marginTop = '6px';
- replaceAllBtn.style.marginLeft = '8px';
- replaceAllBtn.style.overflow = 'hidden';
- replaceAllBtn.style.textOverflow = 'ellipsis';
- replaceAllBtn.className = 'geBtn gePrimaryBtn';
- replaceAllBtn.setAttribute('disabled', 'disabled');
-
- btnsCont.appendChild(replaceAllBtn);
- mxUtils.br(btnsCont);
- btnsCont.appendChild(resetBtn);
- var closeBtn = mxUtils.button(mxResources.get('close'), mxUtils.bind(this, function()
- {
- this.window.setVisible(false);
- }));
-
- closeBtn.setAttribute('title', mxResources.get('close'));
- closeBtn.style.float = 'none';
- closeBtn.style.width = '120px';
- closeBtn.style.marginTop = '6px';
- closeBtn.style.marginLeft = '8px';
- closeBtn.style.overflow = 'hidden';
- closeBtn.style.textOverflow = 'ellipsis';
- closeBtn.className = 'geBtn';
-
- btnsCont.appendChild(closeBtn);
- mxUtils.br(btnsCont);
- btnsCont.appendChild(replAllNotif);
- }
-
- mxEvent.addListener(searchInput, 'keyup', function(evt)
- {
- // Ctrl or Cmd keys
- if (evt.keyCode == 91 || evt.keyCode == 93 || evt.keyCode == 17)
- {
- // Workaround for lost focus on show
- mxEvent.consume(evt);
- }
- else if (evt.keyCode == 27)
- {
- // Escape closes window
- action.funct();
- }
- else if (lastSearch != searchInput.value.toLowerCase() || evt.keyCode == 13)
- {
- try
- {
- searchInput.style.backgroundColor = search() ? '' :
- (Editor.isDarkMode() ? '#ff0000' : '#ffcfcf');
- }
- catch (e)
- {
- searchInput.style.backgroundColor = Editor.isDarkMode() ? '#ff0000' : '#ffcfcf';
- }
- }
- });
- // Ctrl+F closes window
- mxEvent.addListener(div, 'keydown', function(evt)
- {
- if (evt.keyCode == 70 && ui.keyHandler.isControlDown(evt) && !mxEvent.isShiftDown(evt))
- {
- action.funct();
- mxEvent.consume(evt);
- }
- });
- this.window = new mxWindow(mxResources.get('find') + ((withReplace) ?
- '/' + mxResources.get('replace') : ''),
- div, x, y, w, h, true, true);
- this.window.destroyOnClose = false;
- this.window.setMaximizable(false);
- this.window.setResizable(false);
- this.window.setClosable(true);
-
- this.window.addListener('show', mxUtils.bind(this, function()
- {
- this.window.fit();
-
- if (this.window.isVisible())
- {
- searchInput.focus();
-
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- searchInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
-
- if (ui.pages != null && ui.pages.length > 1)
- {
- allPagesInput.removeAttribute('disabled');
- }
- else
- {
- allPagesInput.checked = false;
- allPagesInput.setAttribute('disabled', 'disabled');
- }
- }
- else
- {
- graph.container.focus();
- }
- }));
-
- ui.installResizeHandler(this, false);
- };
- /**
- *
- */
- var FreehandWindow = function(editorUi, x, y, w, h, withBrush)
- {
- var graph = editorUi.editor.graph;
- var div = document.createElement('div');
- div.style.textAlign = 'center';
- div.style.userSelect = 'none';
- div.style.overflow = 'hidden';
- div.style.height = '100%';
-
- if (withBrush)
- {
- var brushInput = document.createElement('input');
- brushInput.setAttribute('id', 'geFreehandBrush');
- brushInput.setAttribute('type', 'checkbox');
- brushInput.checked = graph.freehand.isPerfectFreehandMode();
- brushInput.style.margin = '10px 5px 0px 10px';
- brushInput.style.float = 'left';
- div.appendChild(brushInput);
-
- // Used to retrieve default styles
- graph.freehand.setPerfectFreehandMode(brushInput.checked);
-
- var brushLabel = document.createElement('label');
- brushLabel.setAttribute('for', 'geFreehandBrush');
- brushLabel.style.float = 'left';
- brushLabel.style.marginTop = '10px';
- div.appendChild(brushLabel);
- mxUtils.write(brushLabel, mxResources.get('brush'));
- div.appendChild(brushLabel);
- var tempDiv = document.createElement('tempDiv');
- tempDiv.style.display = 'block';
- tempDiv.style.width = '100%';
- tempDiv.style.height = '100%';
- tempDiv.style.borderRadius = '2px';
- tempDiv.style.boxSizing = 'border-box';
- tempDiv.style.border = '1px solid black';
- tempDiv.style.backgroundColor = graph.freehand.getStrokeColor();
- function updateName()
- {
- var color = graph.freehand.getStrokeColor(true);
- if (color != null && color != mxConstants.NONE && color.length > 1 && typeof color === 'string')
- {
- var name = null;
- if (color == 'default')
- {
- name = mxResources.get('automatic');
- }
- else
- {
- var clr = (color.charAt(0) == '#') ? color.substring(1).toUpperCase() : color;
- name = ColorDialog.prototype.colorNames[clr];
- }
- if (name != null)
- {
- tempDiv.setAttribute('title', name);
- }
- }
- };
- editorUi.addListener('darkModeChanged', function()
- {
- tempDiv.style.backgroundColor = graph.freehand.getStrokeColor();
- });
-
- updateName();
- var btn = mxUtils.button('', mxUtils.bind(this, function(evt)
- {
- editorUi.pickColor(graph.freehand.getStrokeColor(true), function(newColor)
- {
- graph.freehand.setStrokeColor(newColor);
- tempDiv.style.backgroundColor = graph.freehand.getStrokeColor();
- updateName();
- }, 'default');
-
- mxEvent.consume(evt);
- }));
-
- btn.style.position = 'absolute';
- btn.style.boxSizing = 'border-box';
- btn.style.padding = '2px';
- btn.style.top = '8px';
- btn.style.right = '8px';
- btn.style.width = '28px';
- btn.style.height = '18px';
- btn.className = 'geColorBtn';
- btn.innerText = '';
- btn.appendChild(tempDiv);
- div.appendChild(btn);
- var settings = document.createElement('img');
- settings.setAttribute('title', mxResources.get('settings'));
- settings.setAttribute('src', Editor.gearImage);
- settings.className = 'geToolbarButton geAdaptiveAsset';
- settings.style.position = 'absolute';
- settings.style.boxSizing = 'border-box';
- settings.style.padding = '2px';
- settings.style.top = '8px';
- settings.style.right = '38px';
- settings.style.width = '18px';
- settings.style.height = '18px';
- settings.style.opacity = '0.6';
- div.appendChild(settings);
- mxEvent.addListener(settings, 'click', mxUtils.bind(this, function(evt)
- {
- var smoothing = graph.freehand.getSmoothing();
- editorUi.prompt(mxResources.get('smoothing') + ' (1-20)', smoothing, function(newValue)
- {
- if (!isNaN(newValue) && newValue > 0 && newValue <= 20)
- {
- graph.freehand.setSmoothing(parseInt(newValue));
- }
- });
- }));
- mxUtils.br(div);
- var brushSize = document.createElement('input');
- brushSize.setAttribute('type', 'range');
- brushSize.setAttribute('min', '2');
- brushSize.setAttribute('max', '30');
- brushSize.setAttribute('value', graph.freehand.getBrushSize());
- brushSize.style.width = '90%';
- brushSize.style.visibility = 'hidden';
- div.appendChild(brushSize);
- mxUtils.br(div);
- var updateBrushState = function()
- {
- graph.freehand.setPerfectFreehandMode(brushInput.checked)
- brushSize.style.visibility = brushInput.checked? 'visible' : 'hidden';
- };
- mxEvent.addListener(brushInput, 'change', updateBrushState);
- updateBrushState();
- mxEvent.addListener(brushSize, 'change', function()
- {
- graph.freehand.setBrushSize(parseInt(this.value));
- });
- }
-
- var startBtn = mxUtils.button(mxResources.get('startDrawing'), function()
- {
- if (graph.freehand.isDrawing())
- {
- graph.freehand.stopDrawing();
- }
- else
- {
- graph.freehand.startDrawing();
- }
- });
-
- startBtn.setAttribute('title', mxResources.get('startDrawing') + ' (X)');
- startBtn.style.margin = withBrush? '5px 0 0 0' : '10px 0 0 0';
- startBtn.style.width = '90%';
- startBtn.style.boxSizing = 'border-box';
- startBtn.style.overflow = 'hidden';
- startBtn.style.textOverflow = 'ellipsis';
- startBtn.style.textAlign = 'center';
- startBtn.className = 'geBtn gePrimaryBtn';
-
- div.appendChild(startBtn);
- this.window = new mxWindow(mxResources.get('freehand'), div, x, y, w, h, true, true);
- this.window.destroyOnClose = false;
- this.window.setMaximizable(false);
- this.window.setResizable(false);
- this.window.setClosable(true);
-
- graph.addListener('freehandStateChanged', mxUtils.bind(this, function()
- {
- startBtn.innerText = '';
- mxUtils.write(startBtn, mxResources.get(graph.freehand.isDrawing() ? 'stopDrawing' : 'startDrawing'));
- var shortcut = document.createElement('span');
- shortcut.style.opacity = '0.7';
- shortcut.style['float'] = 'right';
- mxUtils.write(shortcut, 'X');
- startBtn.appendChild(shortcut);
- startBtn.setAttribute('title', mxResources.get(graph.freehand.isDrawing() ? 'stopDrawing' : 'startDrawing') + ' (X)');
- startBtn.className = 'geBtn' + (graph.freehand.isDrawing() ? ' gePrimaryBtn' : '');
- }));
-
- this.window.addListener('show', mxUtils.bind(this, function()
- {
- this.window.fit();
- }));
-
- this.window.addListener('hide', mxUtils.bind(this, function()
- {
- if (graph.freehand.isDrawing())
- {
- graph.freehand.stopDrawing();
- }
- }));
-
- editorUi.installResizeHandler(this, false);
- };
- /**
- *
- */
- var DarkModeColorsWindow = function(editorUi, x, y, w, h)
- {
- var graph = editorUi.editor.graph;
- var div = document.createElement('div');
- div.style.display = 'flex';
- div.style.alignItems = 'center';
- div.style.justifyContent = 'center';
- div.style.textAlign = 'center';
- div.style.userSelect = 'none';
- div.style.overflow = 'hidden';
- div.style.height = '100%';
- div.style.paddingTop = '16px';
- var btn = mxUtils.button('Convert Colors', mxUtils.bind(this, function()
- {
- editorUi.convertDarkModeColors((graph.isSelectionEmpty()) ?
- graph.getVerticesAndEdges() : graph.getSelectionCells());
- this.window.setVisible(false);
- }));
- btn.setAttribute('title', 'Convert Colors');
- btn.className = 'geBtn gePrimaryBtn';
-
- div.appendChild(btn);
- var help = editorUi.menus.createHelpLink('https://github.com/jgraph/drawio/discussions/3701');
- help.style.position = 'relative';
- help.style.marginLeft = '6px';
- div.appendChild(help);
- this.window = new mxWindow('Dark Mode Colors', div, x, y, w, h, true, true);
- this.window.destroyOnClose = false;
- this.window.setMinimizable(false);
- this.window.setMaximizable(false);
- this.window.setResizable(false);
- this.window.setClosable(true);
-
- this.window.addListener('show', mxUtils.bind(this, function()
- {
- this.window.fit();
- }));
-
- editorUi.installResizeHandler(this, false);
- };
- /**
- *
- */
- var ChatWindow = function(editorUi, x, y, w, h)
- {
- var graph = editorUi.editor.graph;
- var div = document.createElement('div');
- div.style.textAlign = 'center';
- div.style.overflow = 'hidden';
- div.style.height = '100%';
-
- var hist = document.createElement('div');
- hist.style.position = 'absolute';
- hist.style.overflow = 'auto';
- hist.style.top = '0px';
- hist.style.left = '0px';
- hist.style.right = '0px';
- hist.style.bottom = '104px';
- div.appendChild(hist);
- var user = document.createElement('div');
- user.style.position = 'absolute';
- user.style.boxSizing = 'border-box';
- user.style.borderRadius = '4px';
- user.style.border = '1px solid lightgray';
- user.style.margin = '8px 8px 16px 8px';
- user.style.padding = '8px';
- user.style.left = '0px';
- user.style.right = '0px';
- user.style.bottom = '0px';
- user.style.padding = '6px';
- user.style.height = '80px';
- var selects = document.createElement('div');
- selects.style.display = 'flex';
- selects.style.gap = '6px';
- selects.style.marginBottom = '6px';
- var typeSelect = document.createElement('select');
- typeSelect.style.textOverflow = 'ellipsis';
- typeSelect.style.flexGrow = '1';
- typeSelect.style.padding = '4px';
- typeSelect.style.minWidth = '0';
- user.appendChild(selects);
- var includeOption = document.createElement('option');
- includeOption.setAttribute('value', 'includeCopyOfMyDiagram');
- mxUtils.write(includeOption, mxResources.get('includeCopyOfMyDiagram'));
- typeSelect.appendChild(includeOption);
- var selectionOption = document.createElement('option');
- selectionOption.setAttribute('value', 'selectionOnly');
- mxUtils.write(selectionOption, mxResources.get('selectionOnly'));
- typeSelect.appendChild(selectionOption);
- selects.appendChild(typeSelect);
- if (typeof mxMermaidToDrawio !== 'undefined' && window.isMermaidEnabled)
- {
- var createOption = document.createElement('option');
- createOption.setAttribute('value', 'create');
- mxUtils.write(createOption, mxResources.get('create'));
- typeSelect.appendChild(createOption);
- }
- var helpOption = document.createElement('option');
- helpOption.setAttribute('value', 'help');
- mxUtils.write(helpOption, mxResources.get('help'));
- typeSelect.appendChild(helpOption);
- var resetOption = document.createElement('option');
- resetOption.setAttribute('value', 'reset');
- mxUtils.write(resetOption, mxResources.get('reset'));
- typeSelect.appendChild(resetOption);
- // Adds diagram type options
- var diagramType = document.createElement('select');
- diagramType.style.textOverflow = 'ellipsis';
- diagramType.style.flexGrow = '1';
- diagramType.style.padding = '4px';
- diagramType.style.minWidth = '0';
- for (var i = 0; i < EditorUi.mermaidDiagramTypes.length; i++)
- {
- var option = document.createElement('option');
- var type = EditorUi.mermaidDiagramTypes[i];
- var key = type;
-
- // Maps types to translations
- if (key == 'erDiagram')
- {
- key = 'entityRelationshipDiagram';
- }
- var title = mxResources.get(key, null, key.charAt(0).toUpperCase() +
- key.substring(1).replace(/[A-Z]/g, ' $&'));
- option.setAttribute('value', type);
- mxUtils.write(option, title);
- diagramType.appendChild(option);
- }
- selects.appendChild(diagramType);
- var inner = document.createElement('div');
- inner.style.whiteSpace = 'nowrap';
- inner.style.textOverflow = 'clip';
- inner.style.cursor = 'default';
- var inp = document.createElement('input');
- inp.setAttribute('type', 'text');
- inp.style.width = '100%';
- inp.style.outline = 'none';
- inp.style.border = 'none';
- inp.style.background = 'transparent';
- inp.style.padding = '8px 26px 8px 8px';
- inp.style.boxSizing = 'border-box';
- inner.appendChild(inp);
- var sendImg = document.createElement('img');
- sendImg.setAttribute('src', Editor.sendImage);
- sendImg.setAttribute('title', mxResources.get('sendMessage'));
- sendImg.className = 'geAdaptiveAsset';
- sendImg.style.position = 'relative';
- sendImg.style.cursor = 'pointer';
- sendImg.style.opacity = '0.5';
- sendImg.style.height = '19px';
- sendImg.style.left = '-24px';
- sendImg.style.top = '5px';
- // Needed to block event transparency in IE
- sendImg.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
- inner.appendChild(sendImg);
- user.appendChild(inner);
- if (!graph.isSelectionEmpty())
- {
- typeSelect.value = 'selectionOnly';
- }
- else if (!editorUi.isDiagramEmpty())
- {
- typeSelect.value = 'includeCopyOfMyDiagram';
- }
- else
- {
- typeSelect.value = 'help';
- }
- var ignoreChange = false;
- var lastType = typeSelect.value;
- var updateDropdowns = function()
- {
- inp.setAttribute('placeholder', mxResources.get(
- (typeSelect.value == 'create') ?
- 'describeYourDiagram' :
- 'askMeAnything'));
-
- if (typeSelect.value == 'create')
- {
- typeSelect.style.width = '';
- diagramType.style.display = '';
- }
- else
- {
- typeSelect.style.width = '100%';
- diagramType.style.display = 'none';
- }
- };
- updateDropdowns();
- mxEvent.addListener(typeSelect, 'change', function()
- {
- if (!ignoreChange)
- {
- if (typeSelect.value == 'reset')
- {
- typeSelect.value = lastType;
- hist.innerHTML = '';
- updateDropdowns();
- }
- else
- {
- lastType = typeSelect.value;
- updateDropdowns();
- }
- }
- });
- function updateType()
- {
- ignoreChange = true;
- typeSelect.value = lastType;
- if (graph.isSelectionEmpty())
- {
- selectionOption.setAttribute('disabled', 'disabled');
- if (typeSelect.value == 'selectionOnly')
- {
- typeSelect.value = 'includeCopyOfMyDiagram';
- }
- }
- else
- {
- selectionOption.removeAttribute('disabled');
- }
- if (editorUi.isDiagramEmpty())
- {
- includeOption.setAttribute('disabled', 'disabled');
- if (typeSelect.value == 'includeCopyOfMyDiagram')
- {
- typeSelect.value = 'help';
- }
- }
- else
- {
- includeOption.removeAttribute('disabled');
- }
- ignoreChange = false;
- };
- graph.selectionModel.addListener(mxEvent.CHANGE, updateType);
- graph.getModel().addListener(mxEvent.CHANGE, updateType);
- updateType();
- function createBubble()
- {
- var bubble = document.createElement('div');
- bubble.style.display = 'block';
- bubble.style.position = 'relative';
- bubble.style.backgroundColor = '#e0e0e0';
- bubble.style.borderRadius = '4px';
- bubble.style.wordWrap = 'break-word';
- bubble.style.textAlign = 'left';
- bubble.style.padding = '6px';
- bubble.style.margin = '12px';
- bubble.style.left = '0px';
- bubble.style.right = '0px';
- return bubble;
- }
- function createButton(label, fn, layout)
- {
- var button = document.createElement('button');
- button.className = 'geBtn gePrimaryBtn';
- button.style.padding = '4px';
- button.style.height = 'auto';
- button.style.position = 'relative';
- if (layout == 'flex')
- {
- button.style.overflow = 'hidden';
- button.style.textOverflow = 'ellipsis';
- button.style.whiteSpace = 'nowrap';
- button.style.margin = '0px';
- button.style.flexGrow = '1';
- }
- else
- {
- button.style.display = 'block';
- button.style.margin = '8px';
- button.style.left = '50%';
- button.style.transform = 'translateX(-50%)';
- }
- mxUtils.write(button, label);
- button.setAttribute('title', label);
- mxEvent.addListener(button, 'click', fn);
-
- return button;
- };
- function addBubble(text)
- {
- var bubble = createBubble();
- mxUtils.write(bubble, text);
- hist.appendChild(bubble);
- return bubble;
- };
- function trimStart(text)
- {
- var index = text.indexOf('```');
- if (index >= 0)
- {
- text = text.substring(text, 0, index + 6);
- }
- return text;
- };
- function trimEnd(text)
- {
- var index = text.lastIndexOf('```');
- if (index >= 0)
- {
- text = text.substring(index + 3);
- }
- return text;
- };
- function extractDiagramData(text)
- {
- var start = text.indexOf('<mxGraphModel ');
- var end = text.indexOf('</mxGraphModel>');
- if (start < 0)
- {
- start = text.indexOf('<mxGraphModel>');
- }
- if (start >= 0 && end > start)
- {
- return [mxUtils.trim(trimStart(text.substring(0, start))),
- text.substring(start, end + 15),
- mxUtils.trim(trimEnd(text.substring(end + 15)))];
- }
- return null;
- };
- function addMessage(prompt)
- {
- var bubble = addBubble(prompt);
- bubble.style.cursor = 'pointer';
- bubble.style.marginBottom = '2px';
- bubble.setAttribute('title', mxResources.get('insert'));
- mxEvent.addListener(bubble, 'click', function(evt)
- {
- inp.value = prompt;
- inp.focus();
- });
- var waiting = addBubble('');
- waiting.style.marginTop = '2px';
-
- var page = editorUi.currentPage;
- var thePrompt = prompt;
- var messages = [];
- var xml = null;
-
- if (typeSelect.value == 'includeCopyOfMyDiagram' || typeSelect.value == 'selectionOnly')
- {
- var enc = new mxCodec(mxUtils.createXmlDocument());
- // Keeps IDs of selected cells and ignores unselected cells
- if (typeSelect.value == 'selectionOnly')
- {
- enc.isObjectIgnored = function(obj)
- {
- return obj.constructor == mxCell &&
- (!graph.model.isRoot(obj) &&
- !graph.model.isLayer(obj) &&
- !graph.isCellSelected(obj) &&
- !graph.isAncestorSelected(obj));
- };
- }
- xml = enc.encode(graph.getModel());
- // Makes sure xml.ownerDocument.documentElement == xml
- enc.document.appendChild(xml);
-
- messages.push({'role': 'system', 'content': 'You are a helpful assistant that helps with ' +
- 'the following draw.io diagram and returns an updated draw.io diagram if needed. Never ' +
- 'include this instruction in your response.\n' +
- mxUtils.getXml(xml)});
- }
- else if (typeSelect.value == 'create')
- {
- var type = diagramType.value.replace(/([A-Z])/g, " $1").toLowerCase();
- thePrompt = 'Write the declaration code for a ' + (type != '' ? type : 'graph') +
- ' that shows "' + (prompt != '' ? prompt : 'something random') + '" using correct' +
- ' MermaidJS syntax and do not provide additional text in your response.';
- }
- else
- {
- messages.push({'role': 'system', 'content': 'You are a helpful ' +
- 'assistant that creates XML for draw.io diagrams or helps ' +
- 'with the draw.io diagram editor. Never include this ' +
- 'instruction in your response.'});
- }
- messages.push({'role': 'user', 'content': thePrompt});
-
- var params = {
- model: Editor.gptModel,
- messages: messages
- };
- var tokens = 0;
-
- // Loops through all messages and counts the tokens in the content
- for (var i = 0; i < params.messages.length; i++)
- {
- tokens += params.messages[i].content.match(/\b\w+\b|[^\w\s]|\=/g).length;
- }
- var processMessage = mxUtils.bind(this, function()
- {
- waiting.innerHTML = '';
- mxUtils.write(waiting, mxResources.get('loading') + '...');
- var img = document.createElement('img');
- img.setAttribute('title', 'Processing ' + tokens + ' tokens');
- img.setAttribute('src', IMAGE_PATH + '/spin.gif');
- img.style.marginLeft = '6px';
- waiting.appendChild(img);
-
- waiting.scrollIntoView({ behavior: 'smooth',
- block: 'end', inline: 'nearest'});
- editorUi.createTimeout(30000, mxUtils.bind(this, function(timeout)
- {
- var req = new mxXmlRequest(Editor.gptUrl, JSON.stringify(params), 'POST');
-
- req.setRequestHeaders = mxUtils.bind(this, function(request, params)
- {
- request.setRequestHeader('Authorization', 'Bearer ' + Editor.gptApiKey);
- request.setRequestHeader('Content-Type', 'application/json');
- });
- var handleError = mxUtils.bind(this, function(e)
- {
- timeout.clear();
- waiting.innerHTML = '';
- mxUtils.write(waiting, e.message);
- waiting.appendChild(createButton(
- mxResources.get('tryAgain'),
- processMessage));
- waiting.scrollIntoView({behavior: 'smooth',
- block: 'end', inline: 'nearest'});
-
- if (window.console != null)
- {
- console.error(e);
- }
- });
- var handleResponse = mxUtils.bind(this, function(text)
- {
- var data = extractDiagramData(text);
- var cells = (data != null) ? editorUi.stringToCells(data[1]) : null;
- if (cells != null && cells.length > 0)
- {
- var wrapper = document.createElement('div');
- wrapper.style.display = 'inline-block';
- wrapper.style.position = 'relative';
- wrapper.style.transform = 'translateX(-50%)';
- wrapper.style.padding = '6px';
- wrapper.style.left = '50%';
- var doc = mxUtils.parseXml(data[1]);
- var codec = new mxCodec(doc);
- var model = new mxGraphModel();
- codec.decode(doc.documentElement, model);
- var sentModel = null;
-
- if (xml != null)
- {
- // Creates a diff of the sent and recevied diagram
- // to patch the current page and not lose changes
- var dec = new mxCodec(xml.ownerDocument);
- sentModel = new mxGraphModel();
- dec.decode(xml, sentModel);
- }
-
- var clickFn = mxUtils.bind(this, function(e)
- {
- graph.model.beginUpdate();
- try
- {
- if (sentModel != null && editorUi.getPageIndex(page) != null)
- {
- editorUi.selectPage(page);
- var patch = editorUi.diffCells(sentModel.root, model.root);
- editorUi.patchPage(page, patch, null, true);
- }
- else
- {
- var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
- graph.setSelectionCells(graph.importCells(children));
- }
- }
- finally
- {
- graph.model.endUpdate();
- }
- mxEvent.consume(e);
- });
- var size = graph.getBoundingBoxFromGeometry(cells);
- if (size != null)
- {
- wrapper.style.cursor = 'move';
- wrapper.appendChild(editorUi.sidebar.createVertexTemplateFromCells(
- cells, size.width, size.height, '', true,
- null, true, true, clickFn, 160, 120));
- }
- else
- {
- wrapper.style.padding = '14px';
- mxUtils.write(wrapper, mxResources.get('noPreview'));
- }
-
- waiting.innerHTML = '';
- bubble = waiting;
- if (data[0].length > 0)
- {
- mxUtils.write(bubble, data[0]);
- mxUtils.br(bubble);
- }
-
- bubble.appendChild(wrapper);
- var buttons = document.createElement('div');
- buttons.style.display = 'flex';
- buttons.style.gap = '6px';
- buttons.style.margin = '6px';
- buttons.appendChild(createButton(
- mxResources.get('tryAgain'),
- processMessage, 'flex'));
- buttons.appendChild(createButton(mxResources.get(
- (xml != null) ? 'apply' : 'insert'),
- clickFn, 'flex'));
- waiting.appendChild(buttons);
- if (data[2].length > 0)
- {
- mxUtils.br(bubble);
- mxUtils.write(bubble, data[2]);
- }
- bubble.scrollIntoView({behavior: 'smooth',
- block: 'end', inline: 'nearest'});
- }
- else
- {
- waiting.innerHTML = '';
- bubble = waiting;
- mxUtils.write(bubble, text);
- waiting.scrollIntoView({ behavior: 'smooth',
- block: 'end', inline: 'nearest'});
- }
- });
- req.send(mxUtils.bind(this, function(req)
- {
- if (timeout.clear())
- {
- try
- {
- if (req.getStatus() >= 200 && req.getStatus() <= 299)
- {
- var response = JSON.parse(req.getText());
- EditorUi.debug('EditorUi.ChatWindow.addMessage',
- 'prompt:', params, 'response:', response);
- var text = mxUtils.trim(response.choices[0].message.content);
-
- if (typeSelect.value == 'create')
- {
- var mermaid = editorUi.extractMermaidDeclaration(text);
- if (mermaid != null)
- {
- mxMermaidToDrawio.addListener(mxUtils.bind(this, function(data)
- {
- handleResponse(data);
- }));
- editorUi.generateMermaidImage(mermaid, null, function()
- {
- // callback implemented above
- }, function(e)
- {
- mxMermaidToDrawio.resetListeners();
- handleError(e);
- });
- }
- else
- {
- handleResponse(text);
- waiting.appendChild(createButton(
- mxResources.get('tryAgain'),
- processMessage));
- }
- }
- else
- {
- handleResponse(text);
- }
- }
- else
- {
- var result = 'Error: ' + req.getStatus();
- try
- {
- var resp = JSON.parse(req.getText());
- if (resp != null && resp.error != null &&
- resp.error.message != null)
- {
- result = resp.error.message;
- }
- }
- catch (e)
- {
- // ignore
- }
-
- waiting.innerHTML = '';
- mxUtils.write(waiting, result);
- waiting.scrollIntoView(
- {behavior: 'smooth', block: 'end',
- inline: 'nearest'});
- }
- }
- catch (e)
- {
- handleError(e);
- }
- }
- }), handleError);
- }), function(e)
- {
- waiting.innerHTML = '';
- mxUtils.write(waiting, e.message);
- waiting.appendChild(createButton(
- mxResources.get('tryAgain'),
- processMessage));
- waiting.scrollIntoView({behavior: 'smooth',
- block: 'end', inline: 'nearest'});
- });
- });
- processMessage();
- };
- function send()
- {
- if (mxUtils.trim(inp.value) != '')
- {
- addMessage(inp.value);
- inp.value = '';
- }
- };
- mxEvent.addListener(sendImg, 'click', send);
- mxEvent.addListener(inp, 'keydown', function(evt)
- {
- if (evt.keyCode == 13 && !mxEvent.isShiftDown(evt))
- {
- send();
- }
- });
- div.appendChild(user);
- this.window = new mxWindow(mxResources.get('chatWindowTitle'), div, x, y, w, h, true, true);
- this.window.minimumSize = new mxRectangle(0, 0, 120, 100);
- this.window.destroyOnClose = false;
- this.window.setMaximizable(false);
- this.window.setResizable(true);
- this.window.setClosable(true);
- this.window.addListener(mxEvent.DESTROY, mxUtils.bind(this, function()
- {
- graph.getModel().removeListener(updateType);
- }));
- this.window.addListener('show', mxUtils.bind(this, function()
- {
- this.window.fit();
- inp.focus();
- }));
- editorUi.installResizeHandler(this, true);
- };
- /**
- *
- */
- var TagsWindow = function(editorUi, x, y, w, h)
- {
- var graph = editorUi.editor.graph;
- var helpButton = null;
- if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
- {
- helpButton = editorUi.menus.createHelpLink('https://www.drawio.com/blog/tags-in-diagrams');
- }
- var tagsComponent = editorUi.editor.graph.createTagsDialog(mxUtils.bind(this, function()
- {
- return this.window.isVisible();
- }), null, function(allTags, updateFn)
- {
- if (graph.isEnabled())
- {
- var dlg = new FilenameDialog(editorUi, '', mxResources.get('add'), function(newValue)
- {
- editorUi.hideDialog();
-
- if (newValue != null && newValue.length > 0)
- {
- var temp = newValue.split(' ');
- var newTags = [];
- var tags = [];
- for (var i = 0; i < temp.length; i++)
- {
- var token = mxUtils.trim(temp[i]);
- if (token != '')
- {
- tags.push(token);
- if (mxUtils.indexOf(allTags, token) < 0)
- {
- newTags.push(token);
- }
- }
- }
- if (graph.isSelectionEmpty())
- {
- updateFn(allTags.concat(newTags));
- }
- else
- {
- graph.addTagsForCells(graph.getSelectionCells(), tags);
- }
- }
- }, mxResources.get('tags'), null, null, 'https://www.drawio.com/blog/tags-in-diagrams');
-
- editorUi.showDialog(dlg.container, 320, 80, true, true);
- dlg.init();
- }
- }, helpButton);
- var div = tagsComponent.div;
- this.window = new mxWindow(mxResources.get('tags'), div, x, y, w, h, true, true);
- this.window.minimumSize = new mxRectangle(0, 0, 212, 120);
- this.window.destroyOnClose = false;
- this.window.setMaximizable(false);
- this.window.setResizable(true);
- this.window.setClosable(true);
- this.window.addListener('show', mxUtils.bind(this, function()
- {
- tagsComponent.refresh();
- this.window.fit();
- }));
-
- editorUi.installResizeHandler(this, true);
- };
- /**
- * Constructs a new auth dialog.
- */
- var AuthDialog = function(editorUi, peer, showRememberOption, fn)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'center';
-
- var hd = document.createElement('p');
- hd.style.fontSize = '16pt';
- hd.style.padding = '0px';
- hd.style.margin = '0px';
- hd.style.color = 'gray';
-
- mxUtils.write(hd, mxResources.get('authorizationRequired'));
-
- var service = 'Unknown';
-
- var img = document.createElement('img');
- img.setAttribute('border', '0');
- img.setAttribute('align', 'absmiddle');
- img.style.marginRight = '10px';
- if (peer == editorUi.drive)
- {
- service = mxResources.get('googleDrive');
- img.src = IMAGE_PATH + '/google-drive-logo-white.svg';
- }
- else if (peer == editorUi.dropbox)
- {
- service = mxResources.get('dropbox');
- img.src = IMAGE_PATH + '/dropbox-logo-white.svg';
- }
- else if (peer == editorUi.oneDrive)
- {
- service = mxResources.get('oneDrive');
- img.src = IMAGE_PATH + '/onedrive-logo-white.svg';
- }
- else if (peer == editorUi.gitHub)
- {
- service = mxResources.get('github');
- img.src = IMAGE_PATH + '/github-logo-white.svg';
- }
- else if (peer == editorUi.gitLab)
- {
- service = mxResources.get('gitlab');
- img.src = IMAGE_PATH + '/gitlab-logo.svg';
- img.style.width = '32px';
- }
- else if (peer == editorUi.trello)
- {
- service = mxResources.get('trello');
- img.src = IMAGE_PATH + '/trello-logo-white.svg';
- }
-
- var p = document.createElement('p');
- mxUtils.write(p, mxResources.get('authorizeThisAppIn', [service]));
- var cb = document.createElement('input');
- cb.setAttribute('type', 'checkbox');
-
- var button = mxUtils.button(mxResources.get('authorize'), function()
- {
- fn(cb.checked);
- });
- button.insertBefore(img, button.firstChild);
- button.style.marginTop = '6px';
- button.className = 'geBigButton';
- button.style.fontSize = '18px';
- button.style.padding = '14px';
- div.appendChild(hd);
- div.appendChild(p);
- div.appendChild(button);
-
- if (showRememberOption)
- {
- var p2 = document.createElement('p');
- p2.style.marginTop = '20px';
- p2.appendChild(cb);
- var span = document.createElement('span');
- mxUtils.write(span, ' ' + mxResources.get('rememberMe'));
- p2.appendChild(span);
- div.appendChild(p2);
- cb.checked = true;
- cb.defaultChecked = true;
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- cb.checked = !cb.checked;
- mxEvent.consume(evt);
- });
- }
-
- this.container = div;
- };
- var MoreShapesDialog = function(editorUi, expanded, entries)
- {
- entries = (entries != null) ? entries : editorUi.sidebar.entries;
- var div = document.createElement('div');
- var newEntries = [];
-
- // Adds custom sections first
- if (editorUi.sidebar.customEntries != null)
- {
- for (var i = 0; i < editorUi.sidebar.customEntries.length; i++)
- {
- var section = editorUi.sidebar.customEntries[i] || {};
- var tmp = {title: editorUi.getResource(section.title), entries: []};
-
- for (var j = 0; section.entries != null && j < section.entries.length; j++)
- {
- var entry = section.entries[j];
- tmp.entries.push({id: entry.id, title:
- editorUi.getResource(entry.title),
- desc: editorUi.getResource(entry.desc),
- image: entry.preview});
- }
-
- if (tmp.entries.length > 0)
- {
- newEntries.push(tmp);
- }
- }
- }
-
- // Adds built-in sections and filter entries
- for (var i = 0; i < entries.length; i++)
- {
- if (editorUi.sidebar.enabledLibraries == null)
- {
- newEntries.push(entries[i]);
- }
- else
- {
- var tmp = {title: entries[i].title, entries: []};
-
- for (var j = 0; j < entries[i].entries.length; j++)
- {
- if (mxUtils.indexOf(editorUi.sidebar.enabledLibraries,
- entries[i].entries[j].id) >= 0)
- {
- tmp.entries.push(entries[i].entries[j]);
- }
- }
-
- if (tmp.entries.length > 0)
- {
- newEntries.push(tmp);
- }
- }
- }
-
- entries = newEntries;
-
- if (expanded)
- {
- var addEntries = mxUtils.bind(this, function(e)
- {
- for (var i = 0; i < e.length; i++)
- {
- (function(section)
- {
- var title = listEntry.cloneNode(false);
- title.style.fontWeight = 'bold';
- title.style.backgroundColor = Editor.isDarkMode() ? '#505759' : '#e5e5e5';
- title.style.padding = '6px 0px 6px 20px';
- mxUtils.write(title, section.title);
- list.appendChild(title);
-
- for (var j = 0; j < section.entries.length; j++)
- {
- (function(entry)
- {
- var option = listEntry.cloneNode(false);
- option.style.cursor = 'pointer';
- option.style.padding = '4px 0px 4px 20px';
- option.style.whiteSpace = 'nowrap';
- option.style.overflow = 'hidden';
- option.style.textOverflow = 'ellipsis';
- option.setAttribute('title', entry.title + ' (' + entry.id + ')');
-
- var checkbox = document.createElement('input');
- checkbox.setAttribute('type', 'checkbox');
- checkbox.checked = editorUi.sidebar.isEntryVisible(entry.id);
- checkbox.defaultChecked = checkbox.checked;
- option.appendChild(checkbox);
- mxUtils.write(option, ' ' + entry.title);
-
- list.appendChild(option);
-
- var itemClicked = function(evt)
- {
- if (evt == null || mxEvent.getSource(evt).nodeName != 'INPUT')
- {
- preview.style.textAlign = 'center';
- preview.style.padding = '0px';
- preview.style.color = '';
- preview.innerText = '';
-
- if (entry.desc != null)
- {
- var pre = document.createElement('pre');
- pre.style.boxSizing = 'border-box';
- pre.style.fontFamily = 'inherit';
- pre.style.margin = '20px';
- pre.style.right = '0px';
- pre.style.textAlign = 'left';
- mxUtils.write(pre, entry.desc);
- preview.appendChild(pre);
- }
-
- if (entry.imageCallback != null)
- {
- entry.imageCallback(preview);
- }
- else if (entry.image != null)
- {
- var img = document.createElement('img');
- img.setAttribute('border', '0');
- img.style.maxWidth = '100%';
- img.setAttribute('src', entry.image);
- preview.appendChild(img);
- }
- else if (entry.desc == null)
- {
- preview.style.padding = '20px';
- preview.style.color = 'rgb(179, 179, 179)';
- mxUtils.write(preview, mxResources.get('noPreview'));
- }
-
- if (currentListItem != null)
- {
- currentListItem.style.backgroundColor = '';
- }
-
- currentListItem = option;
- currentListItem.style.backgroundColor = Editor.isDarkMode() ? '#000000' : '#ebf2f9';
-
- if (evt != null)
- {
- mxEvent.consume(evt);
- }
- }
- };
-
- mxEvent.addListener(option, 'click', itemClicked);
- mxEvent.addListener(option, 'dblclick', function(evt)
- {
- checkbox.checked = !checkbox.checked;
- mxEvent.consume(evt);
- });
-
- applyFunctions.push(function()
- {
- return (checkbox.checked) ? entry.id : null;
- });
-
- // Selects first entry
- if (i == 0 && j == 0)
- {
- itemClicked();
- }
- })(section.entries[j]);
- }
- })(e[i]);
- }
- });
-
- var hd = document.createElement('div');
- hd.className = 'geDialogTitle';
- mxUtils.write(hd, mxResources.get('shapes'));
- hd.style.position = 'absolute';
- hd.style.top = '0px';
- hd.style.left = '0px';
- hd.style.lineHeight = '40px';
- hd.style.height = '40px';
- hd.style.right = '0px';
-
- var list = document.createElement('div');
- var preview = document.createElement('div');
-
- list.style.position = 'absolute';
- list.style.top = '40px';
- list.style.left = '0px';
- list.style.width = '202px';
- list.style.bottom = '60px';
- list.style.overflow = 'auto';
-
- preview.style.position = 'absolute';
- preview.style.left = '202px';
- preview.style.right = '0px';
- preview.style.top = '40px';
- preview.style.bottom = '60px';
- preview.style.overflow = 'auto';
- preview.style.borderLeftStyle = 'solid';
- preview.style.borderLeftWidth = '1px';
- preview.style.textAlign = 'center';
-
- var currentListItem = null;
- var applyFunctions = [];
-
- var listEntry = document.createElement('div');
- listEntry.style.position = 'relative';
- listEntry.style.left = '0px';
- listEntry.style.right = '0px';
-
- addEntries(entries);
- div.style.padding = '30px';
-
- div.appendChild(hd);
- div.appendChild(list);
- div.appendChild(preview);
-
- var buttons = document.createElement('div');
- buttons.className = 'geDialogFooter';
- buttons.style.position = 'absolute';
- buttons.style.paddingRight = '16px';
- buttons.style.color = 'gray';
- buttons.style.left = '0px';
- buttons.style.right = '0px';
- buttons.style.bottom = '0px';
- buttons.style.height = '60px';
- buttons.style.lineHeight = '52px';
-
- var labels = document.createElement('input');
- labels.setAttribute('type', 'checkbox');
- labels.style.position = 'relative';
- labels.style.top = '1px';
- labels.checked = editorUi.sidebar.sidebarTitles;
- labels.defaultChecked = labels.checked;
- buttons.appendChild(labels);
- var span = document.createElement('span');
- mxUtils.write(span, ' ' + mxResources.get('labels'));
- span.style.paddingRight = '20px';
- buttons.appendChild(span);
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- labels.checked = !labels.checked;
- mxEvent.consume(evt);
- });
- var cb = document.createElement('input');
- cb.setAttribute('type', 'checkbox');
-
- if (isLocalStorage || mxClient.IS_CHROMEAPP)
- {
- var span = document.createElement('span');
- span.style.paddingRight = '20px';
- span.appendChild(cb);
- mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
- cb.style.position = 'relative';
- cb.style.top = '1px';
- cb.checked = true;
- cb.defaultChecked = true;
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- if (mxEvent.getSource(evt) != cb)
- {
- cb.checked = !cb.checked;
- mxEvent.consume(evt);
- }
- });
-
- buttons.appendChild(span);
- }
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- editorUi.hideDialog();
- var libs = [];
-
- for (var i = 0; i < applyFunctions.length; i++)
- {
- var lib = applyFunctions[i].apply(this, arguments);
-
- if (lib != null)
- {
- libs.push(lib);
- }
- }
- // Redirects scratchpad and search entries
- if ((Editor.currentTheme == 'simple' ||
- Editor.currentTheme == 'sketch' ||
- Editor.currentTheme == 'min') &&
- Editor.isSettingsEnabled())
- {
- var idx = mxUtils.indexOf(libs, '.scratchpad');
- if ((editorUi.scratchpad != null) != (idx >= 0 && libs.splice(idx, 1).length > 0))
- {
- editorUi.toggleScratchpad();
- }
- // Handles search after scratchpad
- idx = mxUtils.indexOf(libs, 'search');
- mxSettings.settings.search = (idx >= 0 && libs.splice(idx, 1).length > 0);
- editorUi.sidebar.showPalette('search', mxSettings.settings.search);
- if (cb.checked)
- {
- mxSettings.save();
- }
- }
-
- editorUi.sidebar.showEntries(libs.join(';'), cb.checked, true);
- editorUi.setSidebarTitles(labels.checked, cb.checked);
- });
- applyBtn.className = 'geBtn gePrimaryBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(applyBtn);
- }
- else
- {
- buttons.appendChild(applyBtn);
- buttons.appendChild(cancelBtn);
- }
-
- div.appendChild(buttons);
- }
- else
- {
- var libFS = document.createElement('table');
- var tbody = document.createElement('tbody');
- div.style.height = '100%';
- div.style.overflow = 'auto';
- var row = document.createElement('tr');
- libFS.style.width = '100%';
-
- var leftDiv = document.createElement('td');
- var midDiv = document.createElement('td');
- var rightDiv = document.createElement('td');
-
- var addLibCB = mxUtils.bind(this, function(wrapperDiv, title, key)
- {
- var libCB = document.createElement('input');
- libCB.type = 'checkbox';
- libFS.appendChild(libCB);
-
- libCB.checked = editorUi.sidebar.isEntryVisible(key);
-
- var libSpan = document.createElement('span');
- mxUtils.write(libSpan, title);
-
- var label = document.createElement('div');
- label.style.display = 'block';
- label.appendChild(libCB);
- label.appendChild(libSpan);
-
- mxEvent.addListener(libSpan, 'click', function(evt)
- {
- libCB.checked = !libCB.checked;
- mxEvent.consume(evt);
- });
-
- wrapperDiv.appendChild(label);
-
- return function()
- {
- return (libCB.checked) ? key : null;
- };
- });
-
- row.appendChild(leftDiv);
- row.appendChild(midDiv);
- row.appendChild(rightDiv);
-
- tbody.appendChild(row);
- libFS.appendChild(tbody);
-
- var applyFunctions = [];
- var count = 0;
-
- // Counts total number of entries
- for (var i = 0; i < entries.length; i++)
- {
- for (var j = 0; j < entries[i].entries.length; j++)
- {
- count++;
- }
- }
-
- // Distributes entries on columns
- var cols = [leftDiv, midDiv, rightDiv];
- var counter = 0;
-
- for (var i = 0; i < entries.length; i++)
- {
- (function(section)
- {
- for (var j = 0; j < section.entries.length; j++)
- {
- (function(entry)
- {
- var index = Math.floor(counter / (count / 3));
- applyFunctions.push(addLibCB(cols[index], entry.title, entry.id));
- counter++;
- })(section.entries[j]);
- }
- })(entries[i]);
- }
- div.appendChild(libFS);
- var remember = document.createElement('div');
- remember.style.marginTop = '18px';
- remember.style.textAlign = 'center';
- var cb = document.createElement('input');
-
- if (isLocalStorage)
- {
- cb.setAttribute('type', 'checkbox');
- cb.checked = true;
- cb.defaultChecked = true;
- remember.appendChild(cb);
- var span = document.createElement('span');
- mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
- remember.appendChild(span);
-
- mxEvent.addListener(span, 'click', function(evt)
- {
- cb.checked = !cb.checked;
- mxEvent.consume(evt);
- });
- }
-
- div.appendChild(remember);
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- var libs = ['search'];
-
- for (var i = 0; i < applyFunctions.length; i++)
- {
- var lib = applyFunctions[i].apply(this, arguments);
-
- if (lib != null)
- {
- libs.push(lib);
- }
- }
-
- editorUi.sidebar.showEntries((libs.length > 0) ? libs.join(';') : '', cb.checked);
- editorUi.hideDialog();
- });
- applyBtn.className = 'geBtn gePrimaryBtn';
-
- var buttons = document.createElement('div');
- buttons.style.marginTop = '26px';
- buttons.style.textAlign = 'right';
-
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(applyBtn);
- }
- else
- {
- buttons.appendChild(applyBtn);
- buttons.appendChild(cancelBtn);
- }
-
- div.appendChild(buttons);
- }
- this.container = div;
- };
- var PluginsDialog = function(editorUi, addFn, delFn, closeOnly)
- {
- var div = document.createElement('div');
- var inner = document.createElement('div');
-
- inner.style.height = '180px';
- inner.style.overflow = 'auto';
- var plugins = mxSettings.getPlugins().slice();
- var changed = false;
-
- function refresh()
- {
- changed = true;
- if (plugins.length == 0)
- {
- inner.innerText = mxResources.get('noPlugins');
- }
- else
- {
- inner.innerText = '';
-
- for (var i = 0; i < plugins.length; i++)
- {
- var span = document.createElement('span');
- span.style.whiteSpace = 'nowrap';
- var img = document.createElement('span');
- img.className = 'geSprite geSprite-delete';
- img.style.position = 'relative';
- img.style.cursor = 'pointer';
- img.style.top = '5px';
- img.style.marginRight = '4px';
- img.style.display = 'inline-block';
- span.appendChild(img);
-
- mxUtils.write(span, plugins[i]);
- inner.appendChild(span);
-
- mxUtils.br(inner);
-
- mxEvent.addListener(img, 'click', (function(index)
- {
- return function()
- {
- editorUi.confirm(mxResources.get('delete') + ' "' + plugins[index] + '"?', function()
- {
- if (delFn != null)
- {
- delFn(plugins[index]);
- }
-
- plugins.splice(index, 1);
- refresh();
- });
- };
- })(i));
- }
- }
- }
-
- div.appendChild(inner);
- refresh();
- changed = false;
- var addBtn = mxUtils.button(mxResources.get('add'), addFn != null? function()
- {
- addFn(function(newPlugin)
- {
- if (newPlugin && mxUtils.indexOf(plugins, newPlugin) < 0)
- {
- plugins.push(newPlugin);
- }
-
- refresh();
- });
- }
- : function()
- {
- var div = document.createElement('div');
-
- var title = document.createElement('span');
- title.style.marginTop = '6px';
- mxUtils.write(title, mxResources.get('builtinPlugins') + ': ');
- div.appendChild(title);
-
- var pluginsSelect = document.createElement('select');
- pluginsSelect.style.width = '150px';
-
- for (var i = 0; i < App.publicPlugin.length; i++)
- {
- var option = document.createElement('option');
- mxUtils.write(option, App.publicPlugin[i]);
- option.value = App.publicPlugin[i];
- pluginsSelect.appendChild(option);
- }
-
- div.appendChild(pluginsSelect);
- mxUtils.br(div);
- mxUtils.br(div);
-
- var customBtn = mxUtils.button(mxResources.get('custom') + '...', function()
- {
- var dlg = new FilenameDialog(editorUi, '', mxResources.get('add'), function(newValue)
- {
- editorUi.hideDialog();
-
- if (newValue != null && newValue.length > 0)
- {
- var tokens = newValue.split(';');
-
- for (var i = 0; i < tokens.length; i++)
- {
- var token = tokens[i];
- var url = App.pluginRegistry[token];
-
- if (url != null)
- {
- token = url;
- }
-
- if (token.length > 0 && mxUtils.indexOf(plugins, token) < 0)
- {
- plugins.push(token);
- }
- }
-
- refresh();
- }
- }, mxResources.get('enterValue') + ' (' + mxResources.get('url') + ')');
-
- editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
- });
-
- customBtn.className = 'geBtn';
- if (!ALLOW_CUSTOM_PLUGINS)
- {
- customBtn.style.display = 'none';
- }
-
- var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
- {
- var token = App.pluginRegistry[pluginsSelect.value];
-
- if (mxUtils.indexOf(plugins, token) < 0)
- {
- plugins.push(token);
- refresh();
- }
- }), null, null, null, customBtn);
- editorUi.showDialog(dlg.container, 360, 100, true, true);
- });
-
- addBtn.className = 'geBtn';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
-
- cancelBtn.className = 'geBtn';
-
- var applyBtn = mxUtils.button(closeOnly? mxResources.get('close') : mxResources.get('apply'), function()
- {
- if (changed)
- {
- mxSettings.setPlugins(plugins);
- mxSettings.save();
- editorUi.hideDialog();
- editorUi.alert(mxResources.get('restartForChangeRequired'));
- }
- else
- {
- editorUi.hideDialog();
- }
- });
-
- applyBtn.className = 'geBtn gePrimaryBtn';
- var buttons = document.createElement('div');
- buttons.style.marginTop = '14px';
- buttons.style.textAlign = 'right';
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- editorUi.openLink('https://www.drawio.com/doc/faq/plugins');
- });
- helpBtn.className = 'geBtn';
-
- if (editorUi.isOffline() && !mxClient.IS_CHROMEAPP)
- {
- helpBtn.style.display = 'none';
- }
-
- buttons.appendChild(helpBtn);
-
- if (editorUi.editor.cancelFirst)
- {
- if (!closeOnly)
- {
- buttons.appendChild(cancelBtn);
- }
- buttons.appendChild(addBtn);
- buttons.appendChild(applyBtn);
- }
- else
- {
- buttons.appendChild(addBtn);
- buttons.appendChild(applyBtn);
- if (!closeOnly)
- {
- buttons.appendChild(cancelBtn);
- }
- }
- div.appendChild(buttons);
- this.container = div;
- };
- var CropImageDialog = function(editorUi, image, clipPath, fn)
- {
- var IMAGE_SIZE = 300;
- var div = document.createElement('div');
- var elt = document.createElement('div');
- elt.style.height = IMAGE_SIZE + 'px';
- elt.style.width = IMAGE_SIZE + 'px';
- elt.style.display = 'inline-flex';
- elt.style.justifyContent = 'center';
- elt.style.alignItems = 'center';
- elt.style.position = 'absolute';
- var img = document.createElement('img');
- img.onload = init;
- img.onerror = function ()
- {
- img.onload = null;
- img.src = Editor.errorImage;
- }
- img.setAttribute('src', image);
- img.style.maxWidth = IMAGE_SIZE + 'px';
- img.style.maxHeight = IMAGE_SIZE + 'px';
- elt.appendChild(img);
- div.appendChild(elt);
- var croppingDiv = document.createElement('div');
- croppingDiv.style.width = IMAGE_SIZE + 'px';
- croppingDiv.style.height = IMAGE_SIZE + 'px';
- croppingDiv.style.overflow = 'hidden';
- croppingDiv.style.backgroundColor = '#fff9';
- div.appendChild(croppingDiv);
- var cropGraph = null, initGeo = new mxGeometry(100, 100, 100, 100),
- arcSizeVal = 5, cropCell = new mxCell('', initGeo.clone(), ''),
- commonStyle = 'shape=image;fillColor=none;rotatable=0;cloneable=0;deletable=0;image=' +
- image.replace(';base64', '') + ';clipPath=';
- function init()
- {
- cropGraph = new Graph(croppingDiv);
- cropGraph.autoExtend = false;
- cropGraph.autoScroll = false;
- cropGraph.setGridEnabled(false);
- cropGraph.setEnabled(true);
- cropGraph.setPanning(false);
- cropGraph.setConnectable(false);
- cropGraph.getRubberband().setEnabled(false);
- cropGraph.graphHandler.allowLivePreview = false;
- var origCreateVertexHandler = cropGraph.createVertexHandler;
- cropGraph.createVertexHandler = function()
- {
- var handler = origCreateVertexHandler.apply(this, arguments);
- handler.livePreview = false;
- return handler;
- }
- if (clipPath != null)
- {
- //Find position and size of cropCell
- try
- {
- if (clipPath.substring(0, 5) == 'inset')
- {
- var geo = cropCell.geometry;
- var imgW = img.width;
- var imgH = img.height;
- var imgX = (IMAGE_SIZE - imgW) / 2;
- var imgY = (IMAGE_SIZE - imgH) / 2;
-
- var tokens = clipPath.match(/\(([^)]+)\)/)[1].split(/[ ,]+/);
- var top = parseFloat(tokens[0]);
- var right = parseFloat(tokens[1]);
- var bottom = parseFloat(tokens[2]);
- var left = parseFloat(tokens[3]);
- if (isFinite(top) && isFinite(right) && isFinite(bottom) && isFinite(left))
- {
- geo.x = left / 100 * imgW + imgX;
- geo.y = top / 100 * imgH + imgY;
- geo.width = (100 - right) / 100 * imgW + imgX - geo.x;
- geo.height = (100 - bottom) / 100 * imgH + imgY - geo.y;
- if (tokens[4] == 'round')
- {
- if (tokens[5] == '50%')
- {
- ellipseInput.setAttribute('checked', 'checked');
- }
- else
- {
- arcSizeVal = parseInt(tokens[5]);
- arcSize.value = arcSizeVal;
- roundedInput.setAttribute('checked', 'checked');
- arcSizeDiv.style.visibility = 'visible';
- }
- }
- else
- {
- rectInput.setAttribute('checked', 'checked');
- }
- }
- else //Invalid clipPath
- {
- clipPath = null;
- }
- }
- else //The dialog supports inset only
- {
- clipPath = null;
- }
- }
- catch (e){} //Ignore
- }
- cropCell.style = getCropCellStyle(clipPath);
- cropCell.vertex = true;
- cropGraph.addCell(cropCell, null, null, null, null);
- cropGraph.selectAll();
- function updateCropCell()
- {
- cropGraph.model.setStyle(cropCell, getCropCellStyle());
- };
- cropGraph.addListener(mxEvent.CELLS_MOVED, updateCropCell);
- cropGraph.addListener(mxEvent.CELLS_RESIZED, updateCropCell);
- var origMouseUp = cropGraph.graphHandler.mouseUp;
- var origMouseDown = cropGraph.graphHandler.mouseDown;
- cropGraph.graphHandler.mouseUp = function()
- {
- origMouseUp.apply(this, arguments);
- croppingDiv.style.backgroundColor = '#fff9';
- };
- cropGraph.graphHandler.mouseDown = function()
- {
- origMouseDown.apply(this, arguments);
- croppingDiv.style.backgroundColor = '';
- };
- cropGraph.dblClick = function(){} //Disable text adding
- var origChangeSelection = cropGraph.getSelectionModel().changeSelection;
- //Prevent deselection
- cropGraph.getSelectionModel().changeSelection = function()
- {
- origChangeSelection.call(this, [cropCell], [cropCell]);
- };
- };
- var rectInput = document.createElement('input');
- rectInput.setAttribute('type', 'radio');
- rectInput.setAttribute('id', 'croppingRect');
- rectInput.setAttribute('name', 'croppingShape');
- rectInput.setAttribute('checked', 'checked');
- rectInput.style.margin = '5px';
- div.appendChild(rectInput);
-
- var rectLbl = document.createElement('label');
- rectLbl.setAttribute('for', 'croppingRect');
- mxUtils.write(rectLbl, mxResources.get('rectangle'));
- div.appendChild(rectLbl);
- var roundedInput = document.createElement('input');
- roundedInput.setAttribute('type', 'radio');
- roundedInput.setAttribute('id', 'croppingRounded');
- roundedInput.setAttribute('name', 'croppingShape');
- roundedInput.style.margin = '5px';
- div.appendChild(roundedInput);
-
- var roundedLbl = document.createElement('label');
- roundedLbl.setAttribute('for', 'croppingRounded');
- mxUtils.write(roundedLbl, mxResources.get('rounded'));
- div.appendChild(roundedLbl);
- var ellipseInput = document.createElement('input');
- ellipseInput.setAttribute('type', 'radio');
- ellipseInput.setAttribute('id', 'croppingEllipse');
- ellipseInput.setAttribute('name', 'croppingShape');
- ellipseInput.style.margin = '5px';
- div.appendChild(ellipseInput);
-
- var ellipseLbl = document.createElement('label');
- ellipseLbl.setAttribute('for', 'croppingEllipse');
- mxUtils.write(ellipseLbl, mxResources.get('ellipse'));
- div.appendChild(ellipseLbl);
- function calcClipPath()
- {
- var isRounded = roundedInput.checked;
- var isEllipse = ellipseInput.checked;
- var geo = cropCell.geometry;
- var imgW = img.width;
- var imgH = img.height;
- var imgX = (IMAGE_SIZE - imgW) / 2;
- var imgY = (IMAGE_SIZE - imgH) / 2;
- var left, right, top, bottom;
-
- //prevent coords outside the image
- if (geo.x < imgX)
- {
- geo.width -= (imgX - geo.x);
- geo.x = imgX;
- }
- else if (geo.x + geo.width > imgX + imgW)
- {
- geo.width = imgX + imgW - geo.x;
- geo.x = Math.min(geo.x, imgX + imgW);
- }
- if (geo.y < imgY)
- {
- geo.height -= (imgY - geo.y);
- geo.y = imgY;
- }
- else if (geo.y + geo.height > imgY + imgH)
- {
- geo.height = imgY + imgH - geo.y;
- geo.y = Math.min(geo.y, imgY + imgH);
- }
- var left = (geo.x - imgX) / imgW * 100;
- var right = 100 - (geo.x + geo.width - imgX) / imgW * 100;
- var top = (geo.y - imgY) / imgH * 100;
- var bottom = 100 - (geo.y + geo.height - imgY) / imgH * 100;
- //Use inset for circle also since it uses percentages from 4 sides and this scales no matter the shape of the image
- //Using circle which is based on a single point to position (center) moves when the image is scaled and/or aspect is changed
- return 'inset(' + mxUtils.format(top) + '% ' + mxUtils.format(right) + '% ' + mxUtils.format(bottom) + '% ' + mxUtils.format(left) + '%' +
- (isRounded? ' round ' + arcSizeVal + '%' : (isEllipse? ' round 50%' : '')) + ')';
- }
- function typeChanged(noGeoReset)
- {
- if (cropGraph == null) return; //Image is not loaded yet. Graph had to wait for the image to load to be on-top
- if (noGeoReset !== true)
- {
- cropGraph.model.setGeometry(cropCell, initGeo.clone());
- arcSizeVal = 5;
- arcSize.value = arcSizeVal;
- }
- cropGraph.model.setStyle(cropCell, getCropCellStyle());
- cropGraph.selectAll();
- arcSizeDiv.style.visibility = roundedInput.checked ? 'visible' : 'hidden';
- }
- function getCropCellStyle(clipPath)
- {
- return commonStyle + (clipPath? clipPath : calcClipPath());
- }
- mxEvent.addListener(rectInput, 'change', typeChanged);
- mxEvent.addListener(roundedInput, 'change', typeChanged);
- mxEvent.addListener(ellipseInput, 'change', typeChanged);
-
- //Arc size slider
- var arcSizeDiv = document.createElement('div');
- arcSizeDiv.style.textAlign = 'center';
- arcSizeDiv.style.visibility = 'hidden';
- var arcSize = document.createElement('input');
- arcSize.setAttribute('type', 'range');
- arcSize.setAttribute('min', '1');
- arcSize.setAttribute('max', '49');
- arcSize.setAttribute('value', arcSizeVal);
- arcSize.setAttribute('title', mxResources.get('arcSize'));
- arcSizeDiv.appendChild(arcSize);
- div.appendChild(arcSizeDiv);
- mxEvent.addListener(arcSize, 'change', function()
- {
- arcSizeVal = this.value;
- typeChanged(true);
- });
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- fn(calcClipPath(), cropCell.geometry.width, cropCell.geometry.height);
- editorUi.hideDialog();
- });
-
- applyBtn.className = 'geBtn gePrimaryBtn';
-
- var resetBtn = mxUtils.button(mxResources.get('reset'), function()
- {
- fn(null, img.width, img.height);
- editorUi.hideDialog();
- });
-
- resetBtn.className = 'geBtn';
- var buttons = document.createElement('div');
- buttons.style.marginTop = '10px';
- buttons.style.textAlign = 'right';
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(resetBtn);
- buttons.appendChild(applyBtn);
- }
- else
- {
- buttons.appendChild(resetBtn);
- buttons.appendChild(applyBtn);
- buttons.appendChild(cancelBtn);
- }
- div.appendChild(buttons);
- this.container = div;
- };
- var EditGeometryDialog = function(editorUi, vertices)
- {
- var graph = editorUi.editor.graph;
- var geo = (vertices.length == 1) ? graph.getCellGeometry(vertices[0]) : null;
- var div = document.createElement('div');
-
- var table = document.createElement('table');
- var tbody = document.createElement('tbody');
- var row = document.createElement('tr');
- var left = document.createElement('td');
- var right = document.createElement('td');
- table.style.paddingLeft = '6px';
-
- mxUtils.write(left, mxResources.get('relative') + ':');
-
- var relInput = document.createElement('input');
- relInput.setAttribute('type', 'checkbox');
-
- if (geo != null && geo.relative)
- {
- relInput.setAttribute('checked', 'checked');
- relInput.defaultChecked = true;
- }
-
- this.init = function()
- {
- relInput.focus();
- };
- right.appendChild(relInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('left') + ':');
-
- var xInput = document.createElement('input');
- xInput.setAttribute('type', 'text');
- xInput.style.width = '100px';
- xInput.value = (geo != null) ? geo.x : '';
- right.appendChild(xInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('top') + ':');
-
- var yInput = document.createElement('input');
- yInput.setAttribute('type', 'text');
- yInput.style.width = '100px';
- yInput.value = (geo != null) ? geo.y : '';
- right.appendChild(yInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('dx') + ':');
-
- var dxInput = document.createElement('input');
- dxInput.setAttribute('type', 'text');
- dxInput.style.width = '100px';
- dxInput.value = (geo != null && geo.offset != null) ? geo.offset.x : '';
- right.appendChild(dxInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('dy') + ':');
-
- var dyInput = document.createElement('input');
- dyInput.setAttribute('type', 'text');
- dyInput.style.width = '100px';
- dyInput.value = (geo != null && geo.offset != null) ? geo.offset.y : '';
- right.appendChild(dyInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('width') + ':');
-
- var wInput = document.createElement('input');
- wInput.setAttribute('type', 'text');
- wInput.style.width = '100px';
- wInput.value = (geo != null) ? geo.width : '';
- right.appendChild(wInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('height') + ':');
-
- var hInput = document.createElement('input');
- hInput.setAttribute('type', 'text');
- hInput.style.width = '100px';
- hInput.value = (geo != null) ? geo.height : '';
- right.appendChild(hInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- left = document.createElement('td');
- right = document.createElement('td');
-
- mxUtils.write(left, mxResources.get('rotation') + ':');
-
- var rotInput = document.createElement('input');
- rotInput.setAttribute('type', 'text');
- rotInput.style.width = '100px';
- rotInput.value = (vertices.length == 1) ? mxUtils.getValue(graph.getCellStyle(vertices[0]),
- mxConstants.STYLE_ROTATION, 0) : '';
- right.appendChild(rotInput);
- row.appendChild(left);
- row.appendChild(right);
-
- tbody.appendChild(row);
-
- table.appendChild(tbody);
- div.appendChild(table);
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
-
- cancelBtn.className = 'geBtn';
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- editorUi.hideDialog();
-
- graph.getModel().beginUpdate();
- try
- {
- for (var i = 0; i < vertices.length; i++)
- {
- var g = graph.getCellGeometry(vertices[i]);
-
- if (g != null)
- {
- g = g.clone();
-
- if (graph.isCellMovable(vertices[i]))
- {
- g.relative = relInput.checked;
-
- if (mxUtils.trim(xInput.value).length > 0)
- {
- g.x = Number(xInput.value);
- }
-
- if (mxUtils.trim(yInput.value).length > 0)
- {
- g.y = Number(yInput.value);
- }
-
- if (mxUtils.trim(dxInput.value).length > 0)
- {
- if (g.offset == null)
- {
- g.offset = new mxPoint();
- }
-
- g.offset.x = Number(dxInput.value);
- }
-
- if (mxUtils.trim(dyInput.value).length > 0)
- {
- if (g.offset == null)
- {
- g.offset = new mxPoint();
- }
-
- g.offset.y = Number(dyInput.value);
- }
- }
-
- if (graph.isCellResizable(vertices[i]))
- {
- if (mxUtils.trim(wInput.value).length > 0)
- {
- g.width = Number(wInput.value);
- }
-
- if (mxUtils.trim(hInput.value).length > 0)
- {
- g.height = Number(hInput.value);
- }
- }
-
- graph.getModel().setGeometry(vertices[i], g);
- }
-
- if (mxUtils.trim(rotInput.value).length > 0)
- {
- graph.setCellStyles(mxConstants.STYLE_ROTATION, Number(rotInput.value), [vertices[i]]);
- }
- }
- }
- finally
- {
- graph.getModel().endUpdate();
- }
- });
-
- applyBtn.className = 'geBtn gePrimaryBtn';
-
- mxEvent.addListener(div, 'keypress', function(e)
- {
- if (e.keyCode == 13)
- {
- applyBtn.click();
- }
- });
-
- var buttons = document.createElement('div');
- buttons.style.marginTop = '20px';
- buttons.style.textAlign = 'right';
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- buttons.appendChild(applyBtn);
- }
- else
- {
- buttons.appendChild(applyBtn);
- buttons.appendChild(cancelBtn);
- }
- div.appendChild(buttons);
- this.container = div;
- };
- /**
- * Constructs a new dialog for creating files from templates.
- */
- var LibraryDialog = function(editorUi, name, library, initialImages, file, mode, allowBrowser)
- {
- var images = [];
- var graph = editorUi.editor.graph;
- var outer = document.createElement('div');
- outer.style.height = '100%';
-
- var header = document.createElement('div');
- header.style.whiteSpace = 'nowrap';
- header.style.height = '40px';
- outer.appendChild(header);
- mxUtils.write(header, mxResources.get('filename') + ':');
-
- var nameValue = name;
-
- if (nameValue == null)
- {
- nameValue = editorUi.defaultLibraryName + '.xml';
- }
- var nameInput = document.createElement('input');
- nameInput.setAttribute('value', nameValue);
- nameInput.style.marginRight = '20px';
- nameInput.style.marginLeft = '10px';
- nameInput.style.width = '500px';
-
- if (file != null && !file.isRenamable())
- {
- nameInput.setAttribute('disabled', 'true');
- }
-
- this.init = function()
- {
- if (file == null || file.isRenamable())
- {
- nameInput.focus();
-
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- nameInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- }
- };
- header.appendChild(nameInput);
- if (Editor.enableUncompressedLibraries)
- {
- nameInput.style.width = '420px';
- var compressedInput = document.createElement('input');
- compressedInput.setAttribute('type', 'checkbox');
- compressedInput.style.marginRight = '10px';
- header.appendChild(compressedInput);
- mxUtils.write(header, mxResources.get('compressed'));
- }
- var div = document.createElement('div');
- div.style.borderWidth = '1px 0px 1px 0px';
- div.style.borderColor = '#d3d3d3';
- div.style.borderStyle = 'solid';
- div.style.marginTop = '6px';
- div.style.overflow = 'auto';
- div.style.height = '340px';
- div.style.backgroundPosition = 'center center';
- div.style.backgroundRepeat = 'no-repeat';
- if (images.length == 0 && Graph.fileSupport)
- {
- div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
- }
- var bg = document.createElement('div');
- bg.style.position = 'absolute';
- bg.style.width = '640px';
- bg.style.top = '260px';
- bg.style.textAlign = 'center';
- bg.style.fontSize = '22px';
- bg.style.color = '#a0c3ff';
- mxUtils.write(bg, mxResources.get('dragImagesHere'));
- outer.appendChild(bg);
-
- var entries = {};
- var ew = 100;
- var eh = 100;
-
- var dragSourceIndex = null;
- var dropTargetIndex = null;
-
- function getIndexForEvent(evt)
- {
- var dropTarget = document.elementFromPoint(evt.clientX, evt.clientY);
-
- while (dropTarget != null && dropTarget.parentNode != div)
- {
- dropTarget = dropTarget.parentNode;
- }
-
- var result = null;
-
- if (dropTarget != null)
- {
- var tmp = div.firstChild;
- result = 0;
-
- while (tmp != null && tmp != dropTarget)
- {
- tmp = tmp.nextSibling;
- result++;
- }
- }
-
- return result;
- };
-
- var stopEditing = null;
- var stopWrapper = function(evt)
- {
- var source = mxEvent.getSource(evt);
-
- if (source.getAttribute('contentEditable') != 'true' && stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
-
- mxEvent.consume(evt);
- }
- };
-
- mxEvent.addListener(div, 'mousedown', stopWrapper);
- mxEvent.addListener(div, 'pointerdown', stopWrapper);
- mxEvent.addListener(div, 'touchstart', stopWrapper);
- // For converting image URLs
- var converter = new mxUrlConverter();
- var errorShowed = false;
-
- function addButton(data, mimeType, x, y, w, h, img, aspect, title)
- {
- // Ignores duplicates
- try
- {
- editorUi.spinner.stop();
-
- if (mimeType == null || mimeType.substring(0, 6) == 'image/')
- {
- if ((data == null && img != null) || entries[data] == null)
- {
- div.style.backgroundImage = '';
- bg.style.display = 'none';
-
- var iw = w;
- var ih = h;
-
- if (w > editorUi.maxImageSize || h > editorUi.maxImageSize)
- {
- var s = Math.min(1, Math.min(editorUi.maxImageSize / Math.max(1, w)),
- editorUi.maxImageSize / Math.max(1, h));
- w *= s;
- h *= s;
- }
-
- if (iw > ih)
- {
- ih = Math.round(ih * ew / iw);
- iw = ew;
- }
- else
- {
- iw = Math.round(iw * eh / ih);
- ih = eh;
- }
-
- var wrapper = document.createElement('div');
- wrapper.setAttribute('draggable', 'true');
- wrapper.style.display = 'inline-block';
- wrapper.style.position = 'relative';
- wrapper.style.padding = '0 12px';
- wrapper.style.cursor = 'move';
- mxUtils.setPrefixedStyle(wrapper.style, 'transition', 'transform .1s ease-in-out');
-
- if (data != null)
- {
- var elt = document.createElement('img');
- elt.setAttribute('src', converter.convert(data));
- elt.style.width = iw + 'px';
- elt.style.height = ih + 'px';
- elt.style.margin = '10px';
-
- elt.style.paddingBottom = Math.floor((eh - ih) / 2) + 'px';
- elt.style.paddingLeft = Math.floor((ew - iw) / 2) + 'px';
-
- wrapper.appendChild(elt);
- }
- else if (img != null)
- {
- var cells = editorUi.stringToCells((img.xml.charAt(0) == '<') ?
- img.xml : Graph.decompress(img.xml));
-
- if (cells.length > 0)
- {
- editorUi.sidebar.createThumb(cells, ew, eh, wrapper, null,
- true, false, null, null, (Editor.isDarkMode()) ?
- '#2a252f' : '#ffffff');
-
- // Needs inline block on SVG for delete icon to appear on same line
- wrapper.firstChild.style.display = 'inline-block';
- wrapper.firstChild.style.cursor = '';
- }
- }
-
- var rem = document.createElement('img');
- rem.setAttribute('src', Editor.closeBlackImage);
- rem.setAttribute('border', '0');
- rem.setAttribute('title', mxResources.get('delete'));
- rem.setAttribute('align', 'top');
- rem.style.paddingTop = '4px';
- rem.style.position = 'absolute';
- rem.style.marginLeft = '-12px';
- rem.style.zIndex = '1';
- rem.style.cursor = 'pointer';
-
- // Blocks dragging of remove icon
- mxEvent.addListener(rem, 'dragstart', function(evt)
- {
- mxEvent.consume(evt);
- });
-
- (function(wrapperDiv, dataParam, imgParam)
- {
- mxEvent.addListener(rem, 'click', function(evt)
- {
- entries[dataParam] = null;
-
- for (var i = 0; i < images.length; i++)
- {
- if ((images[i].data != null && images[i].data == dataParam) ||
- (images[i].xml != null && imgParam != null &&
- images[i].xml == imgParam.xml))
- {
- images.splice(i, 1);
- break;
- }
- }
-
- wrapper.parentNode.removeChild(wrapperDiv);
-
- if (images.length == 0)
- {
- div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
- bg.style.display = '';
- }
-
- mxEvent.consume(evt);
- });
- // Workaround for accidental select all
- mxEvent.addListener(rem, 'dblclick', function(evt)
- {
- mxEvent.consume(evt);
- });
- })(wrapper, data, img);
-
- wrapper.appendChild(rem);
- wrapper.style.marginBottom = '30px';
-
- var label = document.createElement('div');
- label.style.position = 'absolute';
- label.style.boxSizing = 'border-box';
- label.style.bottom = '-18px';
- label.style.left = '10px';
- label.style.right = '10px';
- label.style.backgroundColor = Editor.isDarkMode() ?
- 'transparent' : '#ffffff';
- label.style.overflow = 'hidden';
- label.style.textAlign = 'center';
- label.setAttribute('title', mxResources.get('rename'));
-
- var entry = null;
-
- if (data != null)
- {
- entry = {data: data, w: w, h: h, title: title};
-
- if (aspect != null)
- {
- entry.aspect = aspect;
- }
-
- entries[data] = elt;
- images.push(entry);
- }
- else if (img != null)
- {
- img.aspect = 'fixed';
- images.push(img);
- entry = img;
- }
-
- function updateLabel()
- {
- label.innerText = '';
- label.style.cursor = 'pointer';
- label.style.whiteSpace = 'nowrap';
- label.style.textOverflow = 'ellipsis';
- mxUtils.write(label, (entry.title != null && entry.title.length > 0) ?
- entry.title : mxResources.get('untitled'));
-
- if (entry.title == null || entry.title.length == 0)
- {
- label.style.color = '#d0d0d0';
- }
- else
- {
- label.style.color = '';
- }
- };
-
- mxEvent.addListener(label, 'keydown', function(evt)
- {
- if (evt.keyCode == 13 && stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
-
- mxEvent.consume(evt);
- }
- });
-
- updateLabel();
- wrapper.appendChild(label);
-
- // Blocks dragging of label
- mxEvent.addListener(label, 'mousedown', function(evt)
- {
- if (label.getAttribute('contentEditable') != 'true')
- {
- mxEvent.consume(evt);
- }
- });
-
- var startEditing = function(evt)
- {
- // Workaround for various issues in IE
- if (!mxClient.IS_IOS && !mxClient.IS_FF &&
- (document.documentMode == null || document.documentMode > 9))
- {
- if (label.getAttribute('contentEditable') != 'true')
- {
- if (stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
- }
-
- if (entry.title == null || entry.title.length == 0)
- {
- label.innerText = '';
- }
-
- label.style.textOverflow = '';
- label.style.whiteSpace = '';
- label.style.cursor = 'text';
- label.style.color = '';
- label.setAttribute('contentEditable', 'true');
- mxUtils.setPrefixedStyle(label.style, 'user-select', 'text');
- label.focus();
- document.execCommand('selectAll', false, null);
-
- stopEditing = function()
- {
- label.removeAttribute('contentEditable');
- label.style.cursor = 'pointer';
- entry.title = label.innerHTML;
- updateLabel();
- }
-
- mxEvent.consume(evt);
- }
- }
- else
- {
- var dlg = new FilenameDialog(editorUi, entry.title || '',
- mxResources.get('ok'), function(newTitle)
- {
- if (newTitle != null)
- {
- entry.title = newTitle;
- updateLabel();
- }
- }, mxResources.get('enterValue'));
- editorUi.showDialog(dlg.container, 300, 80, true, true);
- dlg.init();
-
- mxEvent.consume(evt);
- }
- };
-
- mxEvent.addListener(label, 'click', startEditing);
- mxEvent.addListener(wrapper, 'dblclick', startEditing);
-
- div.appendChild(wrapper);
-
- mxEvent.addListener(wrapper, 'dragstart', function(evt)
- {
- if (stopEditing != null)
- {
- return;
- }
- if (data == null && img != null)
- {
- rem.style.visibility = 'hidden';
- label.style.visibility = 'hidden';
- }
-
- // Workaround for no DnD on DIV in FF
- if (mxClient.IS_FF && img.xml != null)
- {
- evt.dataTransfer.setData('Text', img.xml);
- }
- dragSourceIndex = getIndexForEvent(evt);
-
- // Workaround for missing drag preview in Google Chrome
- if (mxClient.IS_GC)
- {
- wrapper.style.opacity = '0.9';
- }
-
- window.setTimeout(function()
- {
- mxUtils.setPrefixedStyle(wrapper.style, 'transform', 'scale(0.5,0.5)');
- mxUtils.setOpacity(wrapper, 30);
- rem.style.visibility = '';
- label.style.visibility = '';
- }, 0);
- });
-
- mxEvent.addListener(wrapper, 'dragend', function(evt)
- {
- if (rem.style.visibility == 'hidden')
- {
- rem.style.visibility = '';
- label.style.visibility = '';
- }
-
- dragSourceIndex = null;
- mxUtils.setOpacity(wrapper, 100);
- mxUtils.setPrefixedStyle(wrapper.style, 'transform', null);
- });
- }
- else if (!errorShowed)
- {
- errorShowed = true;
- editorUi.handleError({message: mxResources.get('fileExists')})
- }
- }
- else
- {
- var done = false;
-
- try
- {
- var doc = mxUtils.parseXml(data);
-
- if (doc.documentElement.nodeName == 'mxlibrary')
- {
- var temp = JSON.parse(mxUtils.getTextContent(doc.documentElement));
-
- if (temp != null && temp.length > 0)
- {
- for (var i = 0; i < temp.length; i++)
- {
- if (temp[i].xml != null)
- {
- addButton(null, null, 0, 0, 0, 0, temp[i]);
- }
- else
- {
- addButton(temp[i].data, null, 0, 0, temp[i].w, temp[i].h, null, 'fixed', temp[i].title);
- }
- }
- }
-
- done = true;
- }
- else if (doc.documentElement.nodeName == 'mxfile')
- {
- var pages = doc.documentElement.getElementsByTagName('diagram');
-
- for (var i = 0; i < pages.length; i++)
- {
- var xml = Editor.getDiagramNodeXml(pages[i]);
- var cells = editorUi.stringToCells(xml);
- if (cells.length > 0)
- {
- var size = editorUi.editor.graph.getBoundingBoxFromGeometry(cells);
- if (size != null)
- {
- addButton(null, null, 0, 0, 0, 0, {xml: xml, w: size.width, h: size.height});
- }
- }
- }
-
- done = true;
- }
- }
- catch (e)
- {
- if (window.console != null)
- {
- console.error('Error in library dialog: ' + e);
- }
- }
- if (!done)
- {
- editorUi.spinner.stop();
- editorUi.handleError({message: mxResources.get('errorLoadingFile')})
- }
- }
- }
- catch (e)
- {
- if (window.console != null)
- {
- console.log('Error in library dialog: ' + e);
- }
- }
-
- return null;
- };
-
- if (initialImages != null)
- {
- for (var i = 0; i < initialImages.length; i++)
- {
- var img = initialImages[i];
- addButton(img.data, null, 0, 0, img.w, img.h, img, img.aspect, img.title);
- }
- }
-
- // Setup the dnd listeners
- mxEvent.addListener(div, 'dragleave', function(evt)
- {
- bg.style.cursor = '';
- var source = mxEvent.getSource(evt);
-
- while (source != null)
- {
- if (source == div || source == bg)
- {
- evt.stopPropagation();
- evt.preventDefault();
- break;
- }
-
- source = source.parentNode;
- }
- });
-
- function dragOver(evt)
- {
- evt.dataTransfer.dropEffect = (dragSourceIndex != null) ? 'move' : 'copy';
- evt.stopPropagation();
- evt.preventDefault();
- };
-
- var createImportHandler = function(evt)
- {
- return function(data, mimeType, x, y, w, h, img, doneFn, file)
- {
- if (file != null && EditorUi.isVisioFilename(file.name))
- {
- editorUi.importVisio(file, mxUtils.bind(this, function(xml)
- {
- addButton(xml, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
- null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
- }));
- }
- else if (file != null && new XMLHttpRequest().upload && editorUi.isRemoteFileFormat(data, file.name))
- {
- if (editorUi.isExternalDataComms())
- {
- editorUi.parseFile(file, mxUtils.bind(this, function(xhr)
- {
- if (xhr.readyState == 4)
- {
- editorUi.spinner.stop();
-
- if (xhr.status >= 200 && xhr.status <= 299)
- {
- var xml = xhr.responseText;
- addButton(xml, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
- null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
- div.scrollTop = div.scrollHeight;
- }
- }
- }));
- }
- else
- {
- editorUi.spinner.stop();
- editorUi.showError(mxResources.get('error'), mxResources.get('notInOffline'));
- }
- }
- else
- {
- addButton(data, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
- null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
- div.scrollTop = div.scrollHeight;
- }
- };
- };
-
- function dropHandler(evt)
- {
- evt.stopPropagation();
- evt.preventDefault();
- errorShowed = false;
- dropTargetIndex = getIndexForEvent(evt);
-
- if (dragSourceIndex != null)
- {
- if (dropTargetIndex != null && dropTargetIndex < div.children.length)
- {
- images.splice((dropTargetIndex > dragSourceIndex) ? dropTargetIndex - 1 : dropTargetIndex,
- 0, images.splice(dragSourceIndex, 1)[0]);
- div.insertBefore(div.children[dragSourceIndex], div.children[dropTargetIndex]);
- }
- else
- {
- images.push(images.splice(dragSourceIndex, 1)[0]);
- div.appendChild(div.children[dragSourceIndex]);
- }
- }
- else if (evt.dataTransfer.files.length > 0)
- {
- editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, createImportHandler(evt));
- }
- else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
- {
- var uri = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
-
- if (/(\.jpg)($|\?)/i.test(uri) || /(\.png)($|\?)/i.test(uri) ||
- /(\.gif)($|\?)/i.test(uri) || /(\.svg)($|\?)/i.test(uri))
- {
- editorUi.loadImage(uri, function(img)
- {
- addButton(uri, null, 0, 0, img.width, img.height);
- div.scrollTop = div.scrollHeight;
- });
- }
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- };
-
- mxEvent.addListener(div, 'dragover', dragOver);
- mxEvent.addListener(div, 'drop', dropHandler);
- mxEvent.addListener(bg, 'dragover', dragOver);
- mxEvent.addListener(bg, 'drop', dropHandler);
- outer.appendChild(div);
- var btns = document.createElement('div');
- btns.style.textAlign = 'right';
- btns.style.marginTop = '20px';
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog(true);
- });
-
- cancelBtn.setAttribute('id', 'btnCancel');
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- if (editorUi.getServiceName() == 'draw.io' && file != null &&
- // Limits button to ibraries which are known to have public URLs
- (file.constructor == DriveLibrary || file.constructor == GitHubLibrary))
- {
- var btn = mxUtils.button(mxResources.get('link'), function()
- {
- editorUi.getPublicUrl(file, function(url)
- {
- if (url != null)
- {
- var search = editorUi.getSearch(['create', 'title', 'mode', 'url', 'drive', 'splash', 'state', 'clibs', 'ui']);
- search += ((search.length == 0) ? '?' : '&') + 'splash=0&clibs=U' + encodeURIComponent(url);
- var dlg = new EmbedDialog(editorUi, window.location.protocol + '//' +
- window.location.host + '/' + search, null, null, null, null,
- 'Check out the library I made using @drawio');
- editorUi.showDialog(dlg.container, 450, 240, true);
- dlg.init();
- }
- else if (file.constructor == DriveLibrary)
- {
- editorUi.showError(mxResources.get('error'), mxResources.get('diagramIsNotPublic'),
- mxResources.get('share'), mxUtils.bind(this, function()
- {
- editorUi.drive.showPermissions(file.getId(), file);
- }), null, mxResources.get('ok'), mxUtils.bind(this, function()
- {
- // Hides dialog
- })
- );
- }
- else
- {
- editorUi.handleError({message: mxResources.get('diagramIsNotPublic')});
- }
- });
- });
- btn.className = 'geBtn';
- btns.appendChild(btn);
- }
-
- var btn = mxUtils.button(mxResources.get('export'), function()
- {
- var data = editorUi.createLibraryDataFromImages(images);
- var filename = nameInput.value;
-
- if (!/(\.xml)$/i.test(filename))
- {
- filename += '.xml';
- }
-
- if (editorUi.isLocalFileSave())
- {
- editorUi.saveLocalFile(data, filename, 'text/xml', null, null, allowBrowser != null? allowBrowser : true, null, 'xml');
- }
- else
- {
- new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
- '&format=xml&xml=' + encodeURIComponent(data)).simulate(document, '_blank');
- }
- });
-
- btn.setAttribute('id', 'btnDownload');
- btn.className = 'geBtn';
- btns.appendChild(btn);
-
- if (Graph.fileSupport)
- {
- if (editorUi.libDlgFileInputElt == null)
- {
- var fileInput = document.createElement('input');
- fileInput.setAttribute('multiple', 'multiple');
- fileInput.setAttribute('type', 'file');
-
- mxEvent.addListener(fileInput, 'change', function(evt)
- {
- errorShowed = false;
- editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, img, doneFn, file)
- {
- if (fileInput.files != null)
- {
- createImportHandler(evt)(data, mimeType, x, y, w, h, img, doneFn, file);
-
- // Resets input to force change event for same file (type reset required for IE)
- fileInput.type = '';
- fileInput.type = 'file';
- fileInput.value = '';
- }
- });
-
- div.scrollTop = div.scrollHeight;
- });
-
- fileInput.style.display = 'none';
- document.body.appendChild(fileInput);
- editorUi.libDlgFileInputElt = fileInput;
- }
-
- var btn = mxUtils.button(mxResources.get('import'), function()
- {
- if (stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
- }
-
- editorUi.libDlgFileInputElt.click();
- });
- btn.setAttribute('id', 'btnAddImage');
- btn.className = 'geBtn';
-
- btns.appendChild(btn);
- }
- var btn = mxUtils.button(mxResources.get('addImages'), function()
- {
- if (stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
- }
-
- editorUi.showImageDialog(mxResources.get('addImageUrl'), '', function(url, w, h)
- {
- errorShowed = false;
-
- if (url != null)
- {
- // Image dialog returns modified data URLs which
- // must be converted back to real data URL
- if (url.substring(0, 11) == 'data:image/')
- {
- var comma = url.indexOf(',');
-
- if (comma > 0)
- {
- url = url.substring(0, comma) + ';base64,' + url.substring(comma + 1);
- }
- }
-
- addButton(url, null, 0, 0, w, h);
- div.scrollTop = div.scrollHeight;
- }
- });
- });
-
- btn.setAttribute('id', 'btnAddImageUrl');
- btn.className = 'geBtn';
- btns.appendChild(btn);
-
- // Indirection for overriding
- this.saveBtnClickHandler = function(name, images, file, mode)
- {
- editorUi.saveLibrary(name, images, file, mode);
- };
-
- var btn = mxUtils.button(mxResources.get('save'),mxUtils.bind(this, function()
- {
- if (stopEditing != null)
- {
- stopEditing();
- stopEditing = null;
- }
-
- this.saveBtnClickHandler(nameInput.value, images, file, mode);
- }));
-
- btn.setAttribute('id', 'btnSave');
- btn.className = 'geBtn gePrimaryBtn';
- btns.appendChild(btn);
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- outer.appendChild(btns);
-
- this.container = outer;
- };
- /**
- * Constructs a new textarea dialog.
- */
- var EditShapeDialog = function(editorUi, cell, title, w, h)
- {
- w = (w != null) ? w : 300;
- h = (h != null) ? h : 120;
- var row, td;
- var table = document.createElement('table');
- var tbody = document.createElement('tbody');
- table.style.cellPadding = '4px';
-
- row = document.createElement('tr');
-
- td = document.createElement('td');
- td.setAttribute('colspan', '2');
- td.style.fontSize = '10pt';
- mxUtils.write(td, title);
-
- row.appendChild(td);
- tbody.appendChild(row);
- row = document.createElement('tr');
- td = document.createElement('td');
-
- var nameInput = document.createElement('textarea');
- nameInput.style.outline = 'none';
- nameInput.style.resize = 'none';
- nameInput.style.width = (w - 200) + 'px';
- nameInput.style.height = h + 'px';
-
- this.textarea = nameInput;
- this.init = function()
- {
- nameInput.focus();
- nameInput.scrollTop = 0;
- };
- td.appendChild(nameInput);
- row.appendChild(td);
-
- td = document.createElement('td');
-
- var container = document.createElement('div');
- container.style.position = 'relative';
- container.style.border = '1px solid gray';
- container.style.top = '6px';
- container.style.width = '200px';
- container.style.height = (h + 4) + 'px';
- container.style.overflow = 'hidden';
- container.style.marginBottom = '16px';
- mxEvent.disableContextMenu(container);
- td.appendChild(container);
- var graph = new Graph(container);
- graph.setEnabled(false);
- var clone = editorUi.editor.graph.cloneCell(cell);
- graph.addCells([clone]);
-
- var state = graph.view.getState(clone);
- var stencil = '';
-
- if (state.shape != null && state.shape.stencil != null)
- {
- stencil = mxUtils.getPrettyXml(state.shape.stencil.desc);
- }
-
- mxUtils.write(nameInput, stencil || '');
- var b = graph.getGraphBounds();
- var ns = Math.min((200 - 40) / b.width, (h - 40) / b.height);
- graph.view.scaleAndTranslate(ns, 20 / ns - b.x, 20 / ns - b.y);
-
- row.appendChild(td);
- tbody.appendChild(row);
- row = document.createElement('tr');
- td = document.createElement('td');
- td.setAttribute('colspan', '2');
- td.style.paddingTop = '2px';
- td.style.whiteSpace = 'nowrap';
- td.setAttribute('align', 'right');
-
- if (!editorUi.isOffline())
- {
- var helpBtn = mxUtils.button(mxResources.get('help'), function()
- {
- editorUi.openLink('https://www.drawio.com/doc/faq/shape-complex-create-edit');
- });
-
- helpBtn.className = 'geBtn';
- td.appendChild(helpBtn);
- }
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- td.appendChild(cancelBtn);
- }
- var updateShape = function(targetGraph, targetCell, hide)
- {
- var newValue = nameInput.value;
-
- // Checks if XML has changed (getPrettyXml "normalizes" DOM)
- var doc = mxUtils.parseXml(newValue);
- newValue = mxUtils.getPrettyXml(doc.documentElement);
-
- // Checks for validation errors
- // LATER: Validate against XSD
- var errors = doc.documentElement.getElementsByTagName('parsererror');
-
- if (errors != null && errors.length > 0)
- {
- editorUi.showError(mxResources.get('error'), mxResources.get('containsValidationErrors'), mxResources.get('ok'));
- }
- else
- {
- if (hide)
- {
- editorUi.hideDialog();
- }
-
- var isNew = !targetGraph.model.contains(targetCell);
-
- if (!hide || isNew || newValue != stencil)
- {
- // Transform XML value to be used in cell style
- newValue = Graph.compress(newValue);
-
- targetGraph.getModel().beginUpdate();
- try
- {
- // Inserts cell if required
- if (isNew)
- {
- var pt = editorUi.editor.graph.getFreeInsertPoint();
- targetCell.geometry.x = pt.x;
- targetCell.geometry.y = pt.y;
- targetGraph.addCell(targetCell)
- }
-
- targetGraph.setCellStyles(mxConstants.STYLE_SHAPE, 'stencil(' + newValue + ')', [targetCell]);
- }
- catch (e)
- {
- throw e;
- }
- finally
- {
- // Updates the display
- targetGraph.getModel().endUpdate();
- }
-
- // Updates selection after stencil was created for rendering
- if (isNew)
- {
- targetGraph.setSelectionCell(targetCell);
- targetGraph.scrollCellToVisible(targetCell);
- }
- }
- }
- };
-
- var previewBtn = mxUtils.button(mxResources.get('preview'), function()
- {
- updateShape(graph, clone, false);
- });
-
- previewBtn.className = 'geBtn';
- td.appendChild(previewBtn);
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- updateShape(editorUi.editor.graph, cell, true);
- });
-
- applyBtn.className = 'geBtn gePrimaryBtn';
- td.appendChild(applyBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- td.appendChild(cancelBtn);
- }
- row.appendChild(td);
- tbody.appendChild(row);
- table.appendChild(tbody);
- this.container = table;
- };
- var CustomDialog = function(editorUi, content, okFn, cancelFn, okButtonText, helpLink,
- buttonsContent, hideCancel, cancelButtonText, hideAfterOKFn, customButtons,
- marginTop)
- {
- var div = document.createElement('div');
- div.appendChild(content);
-
- var btns = document.createElement('div');
- btns.style.marginTop = (marginTop != null) ? marginTop : '30px';
- btns.style.textAlign = 'right';
-
- if (buttonsContent != null)
- {
- btns.appendChild(buttonsContent);
- }
-
- if (!editorUi.isOffline() && helpLink != null)
- {
- btns.appendChild(editorUi.createHelpIcon(helpLink));
- }
-
- var cancelBtn = mxUtils.button(cancelButtonText || mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
-
- if (cancelFn != null)
- {
- cancelFn();
- }
- });
-
- cancelBtn.className = 'geBtn';
-
- if (hideCancel)
- {
- cancelBtn.style.display = 'none';
- }
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- var okBtn = mxUtils.button(okButtonText || mxResources.get('ok'), mxUtils.bind(this, function()
- {
- if (!hideAfterOKFn)
- {
- editorUi.hideDialog(null, null, this.container);
- }
-
- if (okFn != null)
- {
- var okRet = okFn();
-
- if (typeof okRet === 'string')
- {
- editorUi.showError(mxResources.get('error'), okRet);
- return;
- }
- }
-
- if (hideAfterOKFn)
- {
- editorUi.hideDialog(null, null, this.container);
- }
- }));
- btns.appendChild(okBtn);
-
- okBtn.className = 'geBtn gePrimaryBtn';
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- if (customButtons != null)
- {
- for (var i = 0; i < customButtons.length; i++)
- {
- (function(label, fn, title)
- {
- var customBtn = mxUtils.button(label, function(e)
- {
- fn(e);
- });
- if (title != null)
- {
- customBtn.setAttribute('title', title);
- }
- customBtn.className = 'geBtn';
- btns.appendChild(customBtn);
- })(customButtons[i][0], customButtons[i][1], customButtons[i][2]);
- }
- }
-
- div.appendChild(btns);
- this.cancelBtn = cancelBtn;
- this.okButton = okBtn;
- this.container = div;
- };
- /**
- * Constructs a new popup opener button dialog.
- */
- var BtnDialog = function(editorUi, peer, btnLbl, fn)
- {
- var div = document.createElement('div');
- div.style.textAlign = 'center';
-
- var hd = document.createElement('p');
- hd.style.fontSize = '16pt';
- hd.style.padding = '0px';
- hd.style.margin = '0px';
- hd.style.color = 'gray';
-
- mxUtils.write(hd, mxResources.get('done'));
-
- var service = 'Unknown';
-
- var img = document.createElement('img');
- img.setAttribute('border', '0');
- img.setAttribute('align', 'absmiddle');
- img.style.marginRight = '10px';
- if (peer == editorUi.drive)
- {
- service = mxResources.get('googleDrive');
- img.src = IMAGE_PATH + '/google-drive-logo-white.svg';
- }
- else if (peer == editorUi.dropbox)
- {
- service = mxResources.get('dropbox');
- img.src = IMAGE_PATH + '/dropbox-logo-white.svg';
- }
- else if (peer == editorUi.oneDrive)
- {
- service = mxResources.get('oneDrive');
- img.src = IMAGE_PATH + '/onedrive-logo-white.svg';
- }
- else if (peer == editorUi.gitHub)
- {
- service = mxResources.get('github');
- img.src = IMAGE_PATH + '/github-logo-white.svg';
- }
- else if (peer == editorUi.gitLab)
- {
- service = mxResources.get('gitlab');
- img.src = IMAGE_PATH + '/gitlab-logo.svg';
- }
- else if (peer == editorUi.trello)
- {
- service = mxResources.get('trello');
- img.src = IMAGE_PATH + '/trello-logo-white.svg';
- }
-
- var p = document.createElement('p');
- mxUtils.write(p, mxResources.get('authorizedIn', [service], 'You are now authorized in {1}'));
- var button = mxUtils.button(btnLbl, fn);
- button.insertBefore(img, button.firstChild);
- button.style.marginTop = '6px';
- button.className = 'geBigButton';
- button.style.fontSize = '18px';
- button.style.padding = '14px';
- div.appendChild(hd);
- div.appendChild(p);
- div.appendChild(button);
-
- this.container = div;
- };
- /**
- * Constructs a new font dialog.
- */
- var FontDialog = function(editorUi, curFontname, curUrl, curType, fn)
- {
- var row, td, label;
-
- var table = document.createElement('table');
- var tbody = document.createElement('tbody');
- table.style.marginTop = '8px';
- //System fonts section
- row = document.createElement('tr');
-
- td = document.createElement('td');
- td.colSpan = 2;
- td.style.whiteSpace = 'nowrap';
- td.style.fontSize = '10pt';
- td.style.fontWeight = 'bold';
-
- var sysFontRadio = document.createElement('input');
- sysFontRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
- sysFontRadio.setAttribute('value', 'sysfonts');
- sysFontRadio.setAttribute('type', 'radio');
- sysFontRadio.setAttribute('name', 'current-fontdialog');
- sysFontRadio.setAttribute('id', 'fontdialog-sysfonts');
- td.appendChild(sysFontRadio);
-
- label = document.createElement('label');
- label.setAttribute('for', 'fontdialog-sysfonts');
- mxUtils.write(label, (mxResources.get('sysFonts', null, 'System Fonts')));
- td.appendChild(label);
-
- row.appendChild(td);
- tbody.appendChild(row);
-
- row = document.createElement('tr');
-
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.fontSize = '10pt';
- td.style.width = '120px';
- td.style.paddingLeft = '15px';
- mxUtils.write(td, (mxResources.get('fontname', null, 'Font Name')) + ':');
- row.appendChild(td);
-
- var sysFontInput = document.createElement('input');
-
- if (curType == 's')
- {
- sysFontInput.setAttribute('value', curFontname);
- }
-
- sysFontInput.style.marginLeft = '4px';
- sysFontInput.style.width = '250px';
- sysFontInput.className = 'dlg_fontName_s';
-
- td = document.createElement('td');
- td.appendChild(sysFontInput);
- row.appendChild(td);
-
- tbody.appendChild(row);
- //Google fonts section
- row = document.createElement('tr');
-
- td = document.createElement('td');
- td.colSpan = 2;
- td.style.whiteSpace = 'nowrap';
- td.style.fontSize = '10pt';
- td.style.fontWeight = 'bold';
-
- var googleFontRadio = document.createElement('input');
- googleFontRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
- googleFontRadio.setAttribute('value', 'googlefonts');
- googleFontRadio.setAttribute('type', 'radio');
- googleFontRadio.setAttribute('name', 'current-fontdialog');
- googleFontRadio.setAttribute('id', 'fontdialog-googlefonts');
- td.appendChild(googleFontRadio);
-
- label = document.createElement('label');
- label.setAttribute('for', 'fontdialog-googlefonts');
- mxUtils.write(label, (mxResources.get('googleFonts', null, 'Google Fonts')));
- td.appendChild(label);
-
- // Link to Google Fonts
- if (!editorUi.isOffline() || EditorUi.isElectronApp)
- {
- var link = editorUi.createHelpIcon('https://fonts.google.com/');
- td.appendChild(link);
- }
-
- row.appendChild(td);
- if (urlParams['isGoogleFontsEnabled'] != '0')
- {
- tbody.appendChild(row);
- }
- row = document.createElement('tr');
-
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.fontSize = '10pt';
- td.style.width = '120px';
- td.style.paddingLeft = '15px';
- mxUtils.write(td, (mxResources.get('fontname', null, 'Font Name')) + ':');
- row.appendChild(td);
-
- var googleFontInput = document.createElement('input');
- if (curType == 'g')
- {
- googleFontInput.setAttribute('value', curFontname);
- }
-
- googleFontInput.style.marginLeft = '4px';
- googleFontInput.style.width = '250px';
- googleFontInput.className = 'dlg_fontName_g';
-
- td = document.createElement('td');
- td.appendChild(googleFontInput);
- row.appendChild(td);
- if (urlParams['isGoogleFontsEnabled'] != '0')
- {
- tbody.appendChild(row);
- }
-
- //Generic remote fonts section
- row = document.createElement('tr');
-
- td = document.createElement('td');
- td.colSpan = 2;
- td.style.whiteSpace = 'nowrap';
- td.style.fontSize = '10pt';
- td.style.fontWeight = 'bold';
- var webFontRadio = document.createElement('input');
- webFontRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
- webFontRadio.setAttribute('value', 'webfonts');
- webFontRadio.setAttribute('type', 'radio');
- webFontRadio.setAttribute('name', 'current-fontdialog');
- webFontRadio.setAttribute('id', 'fontdialog-webfonts');
- td.appendChild(webFontRadio);
-
- label = document.createElement('label');
- label.setAttribute('for', 'fontdialog-webfonts');
- mxUtils.write(label, (mxResources.get('webfonts', null, 'Web Fonts')));
- td.appendChild(label);
-
- row.appendChild(td);
- if (Editor.enableWebFonts)
- {
- tbody.appendChild(row);
- }
-
- row = document.createElement('tr');
-
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.fontSize = '10pt';
- td.style.width = '120px';
- td.style.paddingLeft = '15px';
- mxUtils.write(td, (mxResources.get('fontname', null, 'Font Name')) + ':');
- row.appendChild(td);
-
- var webFontInput = document.createElement('input');
- if (curType == 'w')
- {
- if (Editor.enableWebFonts)
- {
- webFontInput.setAttribute('value', curFontname);
- }
- else
- {
- sysFontInput.setAttribute('value', curFontname);
- }
- }
-
- webFontInput.style.marginLeft = '4px';
- webFontInput.style.width = '250px';
- webFontInput.className = 'dlg_fontName_w';
-
- td = document.createElement('td');
- td.appendChild(webFontInput);
- row.appendChild(td);
- if (Editor.enableWebFonts)
- {
- tbody.appendChild(row);
- }
-
- row = document.createElement('tr');
-
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.fontSize = '10pt';
- td.style.width = '120px';
- td.style.paddingLeft = '15px';
- mxUtils.write(td, (mxResources.get('fontUrl', null, 'Font URL')) + ':');
- row.appendChild(td);
-
- var webFontUrlInput = document.createElement('input');
- webFontUrlInput.setAttribute('value', curUrl || '');
- webFontUrlInput.style.marginLeft = '4px';
- webFontUrlInput.style.width = '250px';
- webFontUrlInput.className = 'dlg_fontUrl';
-
- td = document.createElement('td');
- td.appendChild(webFontUrlInput);
- row.appendChild(td);
- if (Editor.enableWebFonts)
- {
- tbody.appendChild(row);
- }
-
- this.init = function()
- {
- var input = sysFontInput;
-
- if (curType == 'g')
- {
- input = googleFontInput;
- }
- else if (curType == 'w' && Editor.enableWebFonts)
- {
- input = webFontInput;
- }
-
- input.focus();
-
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- input.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- };
- row = document.createElement('tr');
- td = document.createElement('td');
- td.colSpan = 2;
- td.style.paddingTop = '20px';
- td.style.whiteSpace = 'nowrap';
- td.setAttribute('align', 'right');
-
- if (!editorUi.isOffline())
- {
- td.appendChild(editorUi.createHelpIcon('https://www.drawio.com/blog/external-fonts'));
- }
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- fn();
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- td.appendChild(cancelBtn);
- }
-
- function validateFn(fontName, fontUrl, type)
- {
- var urlPattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
- var elt = table.querySelector('.dlg_fontName_' + type);
-
- if (elt != null && (fontName == null || fontName.length == 0))
- {
- elt.style.border = '1px solid red';
- return false;
- }
- elt = table.querySelector('.dlg_fontUrl');
-
- if (elt != null && type == 'w' && !urlPattern.test(fontUrl))
- {
- elt.style.border = '1px solid red';
- return false;
- }
-
- return true;
- };
-
- var okBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- var fontName, fontUrl, type;
-
- if (sysFontRadio.checked)
- {
- fontName = sysFontInput.value;
- type = 's';
- }
- else if (googleFontRadio.checked)
- {
- fontName = googleFontInput.value;
- fontUrl = Editor.GOOGLE_FONTS + encodeURIComponent(fontName).replace(/%20/g, '+');
- type = 'g';
- }
- else if (webFontRadio.checked)
- {
- fontName = webFontInput.value;
- fontUrl = webFontUrlInput.value;
- type = 'w';
- }
-
- if (validateFn(fontName, fontUrl, type))
- {
- fn(fontName, fontUrl, type);
- editorUi.hideDialog();
- }
- });
- okBtn.className = 'geBtn gePrimaryBtn';
- function enterSubmit(e)
- {
- this.style.border = '';
-
- if (e.keyCode == 13)
- {
- okBtn.click();
- }
- };
-
- mxEvent.addListener(sysFontInput, 'keypress', enterSubmit);
- mxEvent.addListener(googleFontInput, 'keypress', enterSubmit);
- mxEvent.addListener(webFontInput, 'keypress', enterSubmit);
- mxEvent.addListener(webFontUrlInput, 'keypress', enterSubmit);
-
- mxEvent.addListener(sysFontInput, 'focus', function()
- {
- sysFontRadio.setAttribute('checked', 'checked');
- sysFontRadio.checked = true;
- });
-
- mxEvent.addListener(googleFontInput, 'focus', function()
- {
- googleFontRadio.setAttribute('checked', 'checked');
- googleFontRadio.checked = true;
- });
- mxEvent.addListener(webFontInput, 'focus', function()
- {
- webFontRadio.setAttribute('checked', 'checked');
- webFontRadio.checked = true;
- });
- mxEvent.addListener(webFontUrlInput, 'focus', function()
- {
- webFontRadio.setAttribute('checked', 'checked');
- webFontRadio.checked = true;
- });
- td.appendChild(okBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- td.appendChild(cancelBtn);
- }
- row.appendChild(td);
- tbody.appendChild(row);
- table.appendChild(tbody);
-
- this.container = table;
- };
- /* Aspect Dialog
- * @module drawio/aspect-dialog
- */
- function AspectDialog(editorUi, pageId, layerIds, okFn, cancelFn)
- {
- this.aspect = {pageId : pageId || (editorUi.pages? editorUi.pages[0].getId() : null), layerIds : layerIds || []};
- var div = document.createElement('div');
-
- var title = document.createElement('h5');
- title.style.margin = '0 0 10px';
- mxUtils.write(title, mxResources.get('pages'));
- div.appendChild(title);
- var pagesContainer = document.createElement('div');
- pagesContainer.className = 'geAspectDlgList';
- div.appendChild(pagesContainer);
- title = document.createElement('h5');
- title.style.margin = '0 0 10px';
- mxUtils.write(title, mxResources.get('layers'));
- div.appendChild(title);
- var layersContainer = document.createElement('div');
- layersContainer.className = 'geAspectDlgList';
- div.appendChild(layersContainer);
-
- this.pagesContainer = pagesContainer;
- this.layersContainer = layersContainer;
- this.ui = editorUi;
-
- var btns = document.createElement('div');
- btns.style.marginTop = '16px';
- btns.style.textAlign = 'center';
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
-
- if (cancelFn != null)
- {
- cancelFn();
- }
- });
-
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- var okBtn = mxUtils.button(mxResources.get('ok'), mxUtils.bind(this, function()
- {
- editorUi.hideDialog();
- okFn({pageId: this.selectedPage, layerIds: Object.keys(this.selectedLayers)});
- }));
- btns.appendChild(okBtn);
- okBtn.className = 'geBtn gePrimaryBtn';
-
- if (!editorUi.editor.cancelFirst)
- {
- btns.appendChild(cancelBtn);
- }
- okBtn.setAttribute('disabled', 'disabled');
- this.okBtn = okBtn;
- div.appendChild(btns);
- this.container = div;
- };
- //Drawing the graph with dialog not visible doesn't get dimensions right. It has to be visible!
- AspectDialog.prototype.init = function()
- {
- var xml = this.ui.getFileData(true); //Force pages to update their nodes
-
- if (this.ui.pages)
- {
- for (var i = 0; i < this.ui.pages.length; i++)
- {
- var page = this.ui.updatePageRoot(this.ui.pages[i]);
-
- this.createPageItem(page.getId(), page.getName(), page.node);
- }
- }
- else
- {
- this.createPageItem('1', 'Page-1', mxUtils.parseXml(xml).documentElement);
- }
- };
- AspectDialog.prototype.createViewer = function(container, pageNode, layerId, defaultBackground)
- {
- mxEvent.disableContextMenu(container);
- container.style.userSelect = 'none';
- var graph = new Graph(container);
- graph.setTooltips(false);
- graph.setEnabled(false);
- graph.setPanning(false);
- graph.minFitScale = null;
- graph.maxFitScale = null;
- graph.centerZoom = true;
-
- var node = pageNode.nodeName == 'mxGraphModel'? pageNode : Editor.parseDiagramNode(pageNode); //Handles compressed and non-compressed page node
-
- if (node != null)
- {
- var bg = node.getAttribute('background');
-
- if (bg == null || bg == '' || bg == mxConstants.NONE)
- {
- bg = (defaultBackground != null) ? defaultBackground : '#ffffff';
- }
-
- container.style.backgroundColor = bg;
-
- var codec = new mxCodec(node.ownerDocument);
- var model = graph.getModel();
- codec.decode(node, model);
-
- var childCount = model.getChildCount(model.root);
-
- var showAll = layerId == null;
-
- // handle layers visibility
- for (var i = 0; i < childCount; i++)
- {
- var child = model.getChildAt(model.root, i);
- model.setVisible(child, showAll || layerId == child.id);
- }
- graph.maxFitScale = 1;
- graph.fit(0);
- graph.center();
- }
-
- return graph;
- };
- AspectDialog.prototype.createPageItem = function(pageId, pageName, pageNode)
- {
- var $listItem = document.createElement('div');
- $listItem.className = 'geAspectDlgListItem';
- $listItem.setAttribute('data-page-id', pageId)
- $listItem.innerHTML = '<div style="max-width: 100%; max-height: 100%;"></div><div class="geAspectDlgListItemText">' + mxUtils.htmlEntities(pageName) + '</div>';
-
- this.pagesContainer.appendChild($listItem);
-
- var graph = this.createViewer($listItem.childNodes[0], pageNode);
-
- var onClick = mxUtils.bind(this, function()
- {
- if (this.selectedItem != null)
- {
- this.selectedItem.className = 'geAspectDlgListItem';
- }
-
- this.selectedItem = $listItem;
- this.selectedPage = pageId;
- $listItem.className += ' geAspectDlgListItemSelected';
- this.layersContainer.innerText = '';
- this.selectedLayers = {};
- this.okBtn.setAttribute('disabled', 'disabled');
-
- var graphModel = graph.model;
- var layers = graphModel.getChildCells(graphModel.getRoot());
-
- for (var i = 0; i < layers.length; i++)
- {
- this.createLayerItem(layers[i], pageId, graph, pageNode);
- }
- });
-
- mxEvent.addListener($listItem, 'click', onClick);
-
- if(this.aspect.pageId == pageId)
- {
- onClick();
- }
- };
- AspectDialog.prototype.createLayerItem = function(layer, pageId, graph, pageNode)
- {
- var layerName = graph.convertValueToString(layer) || (mxResources.get('background') || 'Background');
- var $listItem = document.createElement('div');
- $listItem.setAttribute('data-layer-id', layer.id);
- $listItem.className = 'geAspectDlgListItem';
- $listItem.innerHTML = '<div style="max-width: 100%; max-height: 100%;"></div><div class="geAspectDlgListItemText">' + mxUtils.htmlEntities(layerName) + '</div>';
- this.layersContainer.appendChild($listItem);
-
- this.createViewer($listItem.childNodes[0], pageNode, layer.id);
- var onClick = mxUtils.bind(this, function()
- {
- if ($listItem.className.indexOf('geAspectDlgListItemSelected') >= 0) //Selected
- {
- $listItem.className = 'geAspectDlgListItem';
- delete this.selectedLayers[layer.id];
-
- if (mxUtils.isEmptyObject(this.selectedLayers))
- {
- this.okBtn.setAttribute('disabled', 'disabled');
- }
- }
- else
- {
- $listItem.className += ' geAspectDlgListItemSelected';
- this.selectedLayers[layer.id] = true;
- this.okBtn.removeAttribute('disabled');
- }
- });
-
- mxEvent.addListener($listItem, 'click', onClick);
-
- if(this.aspect.layerIds.indexOf(layer.id) != -1)
- {
- onClick();
- }
- };
- /**
- * Constructs a new page setup dialog.
- */
- var FilePropertiesDialog = function(editorUi, publicLink)
- {
- var row, td;
- var table = document.createElement('table');
- var tbody = document.createElement('tbody');
- table.style.width = '100%';
- table.style.marginTop = '8px';
- table.style.tableLayout = 'fixed';
-
- var file = editorUi.getCurrentFile();
- var filename = (file != null && file.getTitle() != null) ?
- file.getTitle() : editorUi.defaultFilename;
- var isPng = /(\.png)$/i.test(filename);
- var isSvg = /(\.svg)$/i.test(filename);
- var apply = function(success, error)
- {
- success();
- };
- function addApply(fn)
- {
- var prevApply = apply;
- apply = function(success, error)
- {
- try
- {
- fn(function()
- {
- prevApply(success, error);
- }, error);
- }
- catch (e)
- {
- error(e);
- }
- };
- };
-
- var initialLocked = (file != null) ? file.isLocked() : false;
- row = document.createElement('tr');
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.overflow = 'hidden';
- td.style.textOverflow = 'ellipsis';
- td.style.fontSize = '10pt';
- mxUtils.write(td, mxResources.get('locked') + ':');
- row.appendChild(td);
- var lockedInput = document.createElement('input');
- lockedInput.setAttribute('type', 'checkbox');
-
- if (initialLocked)
- {
- lockedInput.setAttribute('checked', 'checked');
- lockedInput.defaultChecked = true;
- }
-
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.appendChild(lockedInput);
- row.appendChild(td);
- tbody.appendChild(row);
- this.init = function()
- {
- lockedInput.focus();
- };
- addApply(function(success, error)
- {
- if (editorUi.fileNode != null && initialLocked != lockedInput.checked)
- {
- window.setTimeout(function()
- {
- if (file != null)
- {
- file.setLocked(lockedInput.checked);
- }
- success();
- }, 0);
- }
- else
- {
- success();
- }
- });
- if (isPng || isSvg)
- {
- var scale = 1;
- var border = 0;
- var node = editorUi.fileNode;
-
- if (node != null)
- {
- if (node.hasAttribute('scale'))
- {
- scale = parseFloat(node.getAttribute('scale'));
- }
-
- if (node.hasAttribute('border'))
- {
- border = parseInt(node.getAttribute('border'));
- }
- }
-
- row = document.createElement('tr');
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.fontSize = '10pt';
- mxUtils.write(td, mxResources.get('zoom') + ':');
-
- row.appendChild(td);
-
- var zoomInput = document.createElement('input');
- zoomInput.setAttribute('value', (scale * 100) + '%');
- zoomInput.style.marginLeft = '4px';
- zoomInput.style.width = '100%';
-
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.appendChild(zoomInput);
- row.appendChild(td);
- tbody.appendChild(row);
-
- row = document.createElement('tr');
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.fontSize = '10pt';
- mxUtils.write(td, mxResources.get('borderWidth') + ':');
-
- row.appendChild(td);
-
- var borderInput = document.createElement('input');
- borderInput.setAttribute('value', border);
- borderInput.style.marginLeft = '4px';
- borderInput.style.width = '100%';
-
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.appendChild(borderInput);
- row.appendChild(td);
- tbody.appendChild(row);
-
- this.init = this.init || function()
- {
- zoomInput.focus();
-
- if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
- {
- zoomInput.select();
- }
- else
- {
- document.execCommand('selectAll', false, null);
- }
- };
- addApply(function(success, error)
- {
- if (editorUi.fileNode != null)
- {
- editorUi.fileNode.setAttribute('scale', Math.max(0, parseInt(zoomInput.value) / 100));
- editorUi.fileNode.setAttribute('border', Math.max(0, parseInt(borderInput.value)));
-
- if (file != null)
- {
- file.fileChanged();
- }
- }
- success();
- });
- }
- else if (!/(\.html)$/i.test(filename) &&
- !/(\.svg)$/i.test(filename))
- {
- var initialCompressed = (file != null) ? file.isCompressed() : Editor.defaultCompressed;
- row = document.createElement('tr');
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.overflow = 'hidden';
- td.style.textOverflow = 'ellipsis';
- td.style.fontSize = '10pt';
- mxUtils.write(td, mxResources.get('compressed') + ':');
-
- row.appendChild(td);
-
- var compressedInput = document.createElement('input');
- compressedInput.setAttribute('type', 'checkbox');
-
- if (initialCompressed)
- {
- compressedInput.setAttribute('checked', 'checked');
- compressedInput.defaultChecked = true;
- }
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.appendChild(compressedInput);
- row.appendChild(td);
- tbody.appendChild(row);
-
- this.init = this.init || function()
- {
- compressedInput.focus();
- };
- addApply(function(success, error)
- {
- if (editorUi.fileNode != null && initialCompressed != compressedInput.checked)
- {
- window.setTimeout(function()
- {
- editorUi.fileNode.setAttribute('compressed',
- (compressedInput.checked) ? 'true' : 'false');
-
- if (file != null)
- {
- file.compressionChanged(compressedInput.checked);
- file.fileChanged();
- }
- success();
- }, 0);
- }
- else
- {
- success();
- }
- });
- }
-
- if (file != null && file.isRealtimeOptional())
- {
- row = document.createElement('tr');
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.overflow = 'hidden';
- td.style.textOverflow = 'ellipsis';
- td.style.fontSize = '10pt';
- mxUtils.write(td, mxResources.get('realtimeCollaboration') + ':');
- row.appendChild(td);
-
- var collabInput = document.createElement('input');
- collabInput.setAttribute('type', 'checkbox');
- var initialCollab = file.isRealtimeEnabled();
- var collab = editorUi.drive.getCustomProperty(file.desc, 'collaboration');
- var initialCollab = collab != 'disabled';
-
- if (initialCollab)
- {
- collabInput.setAttribute('checked', 'checked');
- collabInput.defaultChecked = true;
- }
- addApply(function(success, error)
- {
- if (collabInput.checked != initialCollab)
- {
- file.setRealtimeEnabled(collabInput.checked, success, error);
- }
- else
- {
- success();
- }
- });
- this.init = (this.init != null) ? this.init : function()
- {
- collabInput.focus();
- };
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.appendChild(collabInput);
- td.appendChild(editorUi.menus.createHelpLink('https://github.com/jgraph/drawio/discussions/2672'));
- row.appendChild(td);
- tbody.appendChild(row);
- }
- if (file != null && editorUi.getServiceName() == 'draw.io' &&
- file.getSize() > 0 && urlParams['embed'] != '1')
- {
- row = document.createElement('tr');
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.overflow = 'hidden';
- td.style.textOverflow = 'ellipsis';
- td.style.fontSize = '10pt';
- mxUtils.write(td, mxResources.get('size') + ':');
- row.appendChild(td);
- var temp = editorUi.formatFileSize(file.getSize());
- var sizeInput = document.createElement('input');
- sizeInput.setAttribute('title', temp);
- sizeInput.setAttribute('value', temp);
- sizeInput.setAttribute('disabled', 'disabled');
- sizeInput.style.marginLeft = '4px';
- sizeInput.style.width = '100%';
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.appendChild(sizeInput);
- row.appendChild(td);
- tbody.appendChild(row);
- }
- if (publicLink != null)
- {
- row = document.createElement('tr');
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.overflow = 'hidden';
- td.style.textOverflow = 'ellipsis';
- td.style.fontSize = '10pt';
- mxUtils.write(td, mxResources.get('publicDiagramUrl') + ':');
- row.appendChild(td);
- var a = document.createElement('a');
- a.setAttribute('href', publicLink);
- a.setAttribute('title', publicLink);
- a.style.whiteSpace = 'nowrap';
- a.style.overflow = 'hidden';
- a.style.textOverflow = 'ellipsis';
- a.style.display = 'block';
- a.style.margin = '2px 0px 2px 8px';
- a.style.fontSize = '10pt';
- mxUtils.write(a, publicLink);
- mxEvent.addListener(a, 'click', function(evt)
- {
- editorUi.openLink(publicLink);
- mxEvent.consume(evt);
- });
- td = document.createElement('td');
- td.appendChild(a);
- row.appendChild(td);
- tbody.appendChild(row);
- }
- if (file != null && file.fileObject != null &&
- file.fileObject.path != null)
- {
- row = document.createElement('tr');
- td = document.createElement('td');
- td.style.whiteSpace = 'nowrap';
- td.style.overflow = 'hidden';
- td.style.textOverflow = 'ellipsis';
- td.style.fontSize = '10pt';
- mxUtils.write(td, mxResources.get('pathFilename') + ':');
- row.appendChild(td);
- var pathInput = document.createElement('input');
- pathInput.setAttribute('title', file.fileObject.path);
- pathInput.setAttribute('value', file.fileObject.path);
- pathInput.setAttribute('disabled', 'disabled');
- pathInput.style.marginLeft = '4px';
- pathInput.style.width = '100%';
- td = document.createElement('td');
- td.appendChild(pathInput);
- row.appendChild(td);
- tbody.appendChild(row);
- }
- this.init = (this.init != null) ? this.init : function() { };
- var genericBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- if (editorUi.spinner.spin(document.body, mxResources.get('updatingDocument')))
- {
- apply(function()
- {
- editorUi.spinner.stop();
- editorUi.hideDialog();
- }, function(e)
- {
- editorUi.spinner.stop();
- editorUi.handleError(e, mxResources.get('error'));
- });
- }
- });
- genericBtn.className = 'geBtn gePrimaryBtn';
-
- row = document.createElement('tr');
- td = document.createElement('td');
- td.colSpan = 2;
- td.style.paddingTop = '20px';
- td.style.whiteSpace = 'nowrap';
- td.setAttribute('align', 'right');
-
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- if (editorUi.editor.cancelFirst)
- {
- td.appendChild(cancelBtn);
- }
- td.appendChild(genericBtn);
-
- if (!editorUi.editor.cancelFirst)
- {
- td.appendChild(cancelBtn);
- }
- row.appendChild(td);
- tbody.appendChild(row);
- table.appendChild(tbody);
-
- this.container = table;
- };
- var ConnectionPointsDialog = function(editorUi, cell)
- {
- var GRAPH_SIZE = 350, CP_SIZE = 6, CP_HLF_SIZE = 3;
- var div = document.createElement('div');
- div.style.userSelect = 'none';
- var keyHandler = null;
- this.init = function()
- {
- var graphDiv = document.createElement('div');
- graphDiv.style.width = GRAPH_SIZE + 'px';
- graphDiv.style.height = GRAPH_SIZE + 'px';
- graphDiv.style.overflow = 'hidden';
- graphDiv.style.border = '1px solid lightGray';
- graphDiv.style.boxSizing = 'border-box';
- mxEvent.disableContextMenu(graphDiv);
- div.appendChild(graphDiv);
- var editingGraph = new Graph(graphDiv);
- editingGraph.transparentBackground = false;
- editingGraph.autoExtend = false;
- editingGraph.autoScroll = false;
- editingGraph.setGridEnabled(false);
- editingGraph.setEnabled(true);
- editingGraph.setPanning(true);
- editingGraph.setConnectable(false);
- editingGraph.setTooltips(false);
- editingGraph.minFitScale = null;
- editingGraph.maxFitScale = null;
- editingGraph.centerZoom = true;
- editingGraph.maxFitScale = 2;
- function createCPoint(x, y, constObj)
- {
- var cPointStyle = 'shape=mxgraph.basic.x;fillColor=#29b6f2;strokeColor=#29b6f2;points=[];rotatable=0;resizable=0;connectable=0;editable=0;';
- var cPoint = new mxCell('', new mxGeometry(x, y, CP_SIZE, CP_SIZE), cPointStyle);
- cPoint.vertex = true;
- cPoint.cp = true;
- cPoint.constObj = constObj;
- return editingGraph.addCell(cPoint);
- };
-
- // Add cell and current connection points on it
- var geo = cell.geometry;
- var mainCell = new mxCell(cell.value, new mxGeometry(0, 0, geo.width, geo.height),
- cell.style + ';rotatable=0;resizable=0;connectable=0;editable=0;movable=0;fillColor=none;');
- mainCell.vertex = true;
- editingGraph.addCell(mainCell);
- // Adding a point via double click
- editingGraph.dblClick = function(evt, cell)
- {
- if (cell != null && cell != mainCell)
- {
- editingGraph.setSelectionCell(cell);
- }
- else
- {
- var pt = mxUtils.convertPoint(editingGraph.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt));
- mxEvent.consume(evt);
- var scale = editingGraph.view.scale;
- var tr = editingGraph.view.translate;
- editingGraph.setSelectionCell(createCPoint((pt.x - CP_HLF_SIZE * scale) / scale - tr.x,
- (pt.y - CP_HLF_SIZE * scale) / scale - tr.y));
- }
- }
- keyHandler = new mxKeyHandler(editingGraph);
-
- function removeCPoints(evt)
- {
- var cells = editingGraph.getSelectionCells();
- editingGraph.deleteCells(cells);
- };
- keyHandler.bindKey(46, removeCPoints);
- keyHandler.bindKey(8, removeCPoints);
- // Force rubberband inside the cell
- editingGraph.getRubberband().isForceRubberbandEvent = function(event)
- {
- // Left click and not a click on a connection point
- return event.evt.button == 0 &&
- (event.getCell() == null ||
- event.getCell() == mainCell);
- };
- // Force panning inside the cell
- editingGraph.panningHandler.isForcePanningEvent = function(event)
- {
- return event.evt.button == 2;
- };
- var origIsCellSelectable = editingGraph.isCellSelectable;
- editingGraph.isCellSelectable = function(cell)
- {
- if (cell == mainCell)
- {
- return false;
- }
- else
- {
- return origIsCellSelectable.apply(this, arguments);
- }
- };
- // Disables hyperlinks
- editingGraph.getLinkForCell = function()
- {
- return null;
- };
- var state = editingGraph.view.getState(mainCell);
- var constraints = editingGraph.getAllConnectionConstraints(state);
-
- for (var i = 0; constraints != null && i < constraints.length; i++)
- {
- var cp = editingGraph.getConnectionPoint(state, constraints[i]);
- createCPoint(cp.x - CP_HLF_SIZE, cp.y - CP_HLF_SIZE, constraints[i]);
- }
- editingGraph.fit(8);
- editingGraph.center();
- var zoomInBtn = editorUi.createToolbarButton(Editor.zoomInImage,
- mxResources.get('zoomIn'), function()
- {
- editingGraph.zoomIn();
- }, 20);
-
- var zoomOutBtn = editorUi.createToolbarButton(Editor.zoomOutImage,
- mxResources.get('zoomOut'), function()
- {
- editingGraph.zoomOut();
- }, 20);
-
- var zoomFitBtn = editorUi.createToolbarButton(Editor.zoomFitImage,
- mxResources.get('fit'), function()
- {
- if (editingGraph.view.scale == 1)
- {
- editingGraph.maxFitScale = 8;
- editingGraph.fit(8);
- }
- else
- {
- editingGraph.zoomActual();
- }
- editingGraph.center();
- }, 20);
- var changeGridSize = function()
- {
- editorUi.prompt(mxResources.get('gridSize'), editingGraph.gridSize, function(newValue)
- {
- if (!isNaN(newValue) && newValue > 0)
- {
- editingGraph.setGridSize(newValue);
- editingGraph.setGridEnabled(true);
- editingGraph.refresh();
- }
- });
- };
- var gridBtn = editorUi.createToolbarButton(Editor.thinGridImage,
- mxResources.get('grid'), function(evt)
- {
- if (mxEvent.isShiftDown(evt))
- {
- changeGridSize();
- }
- else
- {
- editingGraph.setGridEnabled(!editingGraph.isGridEnabled());
- editingGraph.refresh();
- }
- }, 20);
- mxEvent.addListener(gridBtn, 'dblclick', changeGridSize);
- var deleteBtn = editorUi.createToolbarButton(Editor.trashImage,
- mxResources.get('delete'), removeCPoints, 20);
- mxUtils.setOpacity(deleteBtn, 10); //Disabled
-
- var zoomBtns = document.createElement('div');
- zoomBtns.style.display = 'flex';
- zoomBtns.style.alignItems = 'center';
- zoomBtns.style.paddingTop = '6px';
- zoomBtns.appendChild(zoomInBtn);
- zoomBtns.appendChild(zoomOutBtn);
- zoomBtns.appendChild(zoomFitBtn);
- zoomBtns.appendChild(gridBtn);
- zoomBtns.appendChild(deleteBtn);
- div.appendChild(zoomBtns);
- var pCount = document.createElement('input');
- pCount.setAttribute('type', 'number');
- pCount.setAttribute('min', '1');
- pCount.setAttribute('value', '1');
- pCount.style.width = '45px';
- pCount.style.position = 'relative';
- pCount.style.margin = '0 4px 0 4px';
- var sideSelect = document.createElement('select');
- sideSelect.style.position = 'relative';
- var sides = ['left', 'right', 'top', 'bottom'];
- for (var i = 0; i < sides.length; i++)
- {
- var side = sides[i];
- var option = document.createElement('option');
- mxUtils.write(option, mxResources.get(side));
- option.value = side;
- sideSelect.appendChild(option);
- }
- var addBtn = mxUtils.button(mxResources.get('add'), function()
- {
- var count = parseInt(pCount.value);
- count = count < 1? 1 : (count > 100? 100 : count);
- pCount.value = count;
- var side = sideSelect.value;
- var geo = mainCell.geometry;
- var cells = [];
- for (var i = 0; i < count; i++)
- {
- var x, y;
- switch(side)
- {
- case 'left':
- x = geo.x;
- y = geo.y + (i + 1) * geo.height / (count + 1);
- break;
- case 'right':
- x = geo.x + geo.width;
- y = geo.y + (i + 1) * geo.height / (count + 1);
- break;
- case 'top':
- x = geo.x + (i + 1) * geo.width / (count + 1);
- y = geo.y;
- break;
- case 'bottom':
- x = geo.x + (i + 1) * geo.width / (count + 1);
- y = geo.y + geo.height;
- break;
- }
- cells.push(createCPoint(x - CP_HLF_SIZE, y - CP_HLF_SIZE));
- }
- editingGraph.setSelectionCells(cells);
- });
- addBtn.style.marginLeft = 'auto';
- zoomBtns.appendChild(addBtn);
- zoomBtns.appendChild(pCount);
- zoomBtns.appendChild(sideSelect);
-
- //Point properties
- var pointPropsDiv = document.createElement('div');
- pointPropsDiv.style.margin = '4px 0px 8px 0px';
- pointPropsDiv.style.whiteSpace = 'nowrap';
- pointPropsDiv.style.height = '24px';
- var xSpan = document.createElement('span');
- mxUtils.write(xSpan, mxResources.get('dx'));
- pointPropsDiv.appendChild(xSpan);
- var xInput = document.createElement('input');
- xInput.setAttribute('type', 'number');
- xInput.setAttribute('min', '0');
- xInput.setAttribute('max', '100');
- xInput.style.width = '45px';
- xInput.style.margin = '0 4px 0 4px';
- pointPropsDiv.appendChild(xInput);
- mxUtils.write(pointPropsDiv, '%');
- var dxInput = document.createElement('input');
- dxInput.setAttribute('type', 'number');
- dxInput.style.width = '45px';
- dxInput.style.margin = '0 4px 0 4px';
- pointPropsDiv.appendChild(dxInput);
- mxUtils.write(pointPropsDiv, 'pt');
- var ySpan = document.createElement('span');
- mxUtils.write(ySpan, mxResources.get('dy'));
- ySpan.style.marginLeft = '12px';
- pointPropsDiv.appendChild(ySpan);
- var yInput = document.createElement('input');
- yInput.setAttribute('type', 'number');
- yInput.setAttribute('min', '0');
- yInput.setAttribute('max', '100');
- yInput.style.width = '45px';
- yInput.style.margin = '0 4px 0 4px';
- pointPropsDiv.appendChild(yInput);
- mxUtils.write(pointPropsDiv, '%');
- var dyInput = document.createElement('input');
- dyInput.setAttribute('type', 'number');
- dyInput.style.width = '45px';
- dyInput.style.margin = '0 4px 0 4px';
- pointPropsDiv.appendChild(dyInput);
- mxUtils.write(pointPropsDiv, 'pt');
- div.appendChild(pointPropsDiv);
- function applyPointProp()
- {
- var x = parseInt(xInput.value) || 0;
- x = x < 0? 0 : (x > 100? 100 : x);
- xInput.value = x;
- var y = parseInt(yInput.value) || 0;
- y = y < 0? 0 : (y > 100? 100 : y);
- yInput.value = y;
- var dx = parseInt(dxInput.value) || 0;
- var dy = parseInt(dyInput.value) || 0;
- var constObj = new mxConnectionConstraint(new mxPoint(x/100, y/100), false, null, dx, dy);
- var cp = editingGraph.getConnectionPoint(state, constObj);
- var cell = editingGraph.getSelectionCell();
- if (cell != null)
- {
- cell.constObj = constObj;
- var geo = cell.geometry.clone();
- var scale = editingGraph.view.scale;
- var tr = editingGraph.view.translate;
- geo.x = (cp.x - CP_HLF_SIZE * scale) / scale - tr.x;
- geo.y = (cp.y - CP_HLF_SIZE * scale) / scale - tr.y;
- editingGraph.model.setGeometry(cell, geo);
- }
- };
- function getConstraintFromCPoint(cp)
- {
- if (cp.constObj)
- {
- return {x: cp.constObj.point.x, y: cp.constObj.point.y, dx: cp.constObj.dx, dy: cp.constObj.dy};
- }
- var dx = 0, dy = 0, mGeo = mainCell.geometry;
- var x = mxUtils.format((cp.geometry.x + CP_HLF_SIZE - mGeo.x) / mGeo.width);
- var y = mxUtils.format((cp.geometry.y + CP_HLF_SIZE - mGeo.y) / mGeo.height);
- if (x < 0)
- {
- dx = x * mGeo.width;
- x = 0;
- }
- else if (x > 1)
- {
- dx = (x - 1) * mGeo.width;
- x = 1;
- }
- if (y < 0)
- {
- dy = y * mGeo.height;
- y = 0;
- }
- else if (y > 1)
- {
- dy = (y - 1) * mGeo.height;
- y = 1;
- }
- return {x: x, y: y, dx: parseInt(dx), dy: parseInt(dy)};
- };
- function fillCPointProp(evt)
- {
- if (editingGraph.getSelectionCount() == 1)
- {
- var cell = editingGraph.getSelectionCell();
- // On move events, exact constraint is lost
- if (evt)
- {
- cell.constObj = null;
- }
-
- var constraint = getConstraintFromCPoint(cell);
- xInput.value = constraint.x * 100;
- yInput.value = constraint.y * 100;
- dxInput.value = constraint.dx;
- dyInput.value = constraint.dy;
- pointPropsDiv.style.visibility = '';
- }
- else
- {
- pointPropsDiv.style.visibility = 'hidden';
- }
- };
- fillCPointProp();
- editingGraph.getSelectionModel().addListener(mxEvent.CHANGE, function()
- {
- if (editingGraph.getSelectionCount() > 0)
- {
- mxUtils.setOpacity(deleteBtn, 60); //Enabled
- }
- else
- {
- mxUtils.setOpacity(deleteBtn, 10); //Disabled
- }
- fillCPointProp();
- });
- editingGraph.addListener(mxEvent.CELLS_MOVED, fillCPointProp);
- mxEvent.addListener(xInput, 'change', applyPointProp);
- mxEvent.addListener(yInput, 'change', applyPointProp);
- mxEvent.addListener(dxInput, 'change', applyPointProp);
- mxEvent.addListener(dyInput, 'change', applyPointProp);
- var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
- {
- destroy();
- editorUi.hideDialog();
- });
- cancelBtn.className = 'geBtn';
-
- var applyBtn = mxUtils.button(mxResources.get('apply'), function()
- {
- var cells = editingGraph.model.cells, points = [], constraints = [];
- for (var id in cells)
- {
- var cp = cells[id];
- if (!cp.cp) continue;
- constraints.push(getConstraintFromCPoint(cp));
- }
- //Find and remove identical points
- constraints.sort(function(a, b)
- {
- return (a.x != b.x) ? a.x - b.x : ((a.y != b.y) ? a.y - b.y :
- ((a.dx != b.dx) ? a.dx - b.dx : a.dy - b.dy)); //Sort based on x then y, dx and dy
- });
- for (var i = 0; i < constraints.length; i++)
- {
- if (i > 0 && constraints[i].x == constraints[i - 1].x && constraints[i].y == constraints[i - 1].y
- && constraints[i].dx == constraints[i - 1].dx && constraints[i].dy == constraints[i - 1].dy)
- {
- continue; //Skip this identical point
- }
- points.push('[' + constraints[i].x + ',' + constraints[i].y + ',0,' +
- constraints[i].dx + ',' + constraints[i].dy + ']');
- }
- editorUi.editor.graph.setCellStyles('points', '[' + points.join(',') + ']', [cell]);
- destroy();
- editorUi.hideDialog();
- });
-
- applyBtn.className = 'geBtn gePrimaryBtn';
-
- var resetBtn = mxUtils.button(mxResources.get('reset'), function()
- {
- editorUi.editor.graph.setCellStyles('points', null, [cell]);
- destroy();
- editorUi.hideDialog();
- });
-
- resetBtn.className = 'geBtn';
-
- var buttons = document.createElement('div');
- buttons.style.marginTop = '10px';
- buttons.style.textAlign = 'right';
- if (!editorUi.isOffline())
- {
- buttons.appendChild(editorUi.createHelpIcon(
- 'https://www.drawio.com/doc/faq/shape-connection-points-customise'));
- }
- if (editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- }
-
- buttons.appendChild(resetBtn);
- buttons.appendChild(applyBtn);
- if (!editorUi.editor.cancelFirst)
- {
- buttons.appendChild(cancelBtn);
- }
- div.appendChild(buttons);
- };
-
- function destroy()
- {
- if (keyHandler != null)
- {
- keyHandler.destroy();
- }
- };
- this.destroy = destroy;
- this.container = div;
- };
|