Editor.js 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. (function()
  6. {
  7. /**
  8. * Specifies the app name. Default is document.title.
  9. */
  10. Editor.prototype.appName = 'draw.io';
  11. /**
  12. * Used in the GraphViewer lightbox.
  13. */
  14. Editor.closeImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAApVBMVEUAAAD////k5OT///8AAAB1dXXMzMz9/f39/f37+/v5+fn+/v7///9iYmJaWlqFhYWnp6ejo6OHh4f////////////////7+/v5+fnx8fH///8AAAD///8bGxv7+/v5+fkoKCghISFDQ0MYGBjh4eHY2Njb29tQUFBvb29HR0c/Pz82NjYrKyu/v78SEhLu7u7s7OzV1dVVVVU7OzsVFRXAv78QEBBzqehMAAAAG3RSTlMAA/7p/vz5xZlrTiPL/v78+/v7+OXd2TYQDs8L70ZbAAABKUlEQVQoz3VS13LCMBBUXHChd8iukDslQChJ/v/TchaG4cXS+OSb1c7trU7V60OpdRz2ZtNZL4zXNlcN8BEtSG6+NxIXkeRPoBuQ1cjvZ31/VJFB10ISli6diYfH8iYO3WUNCcNlB0gTrXOtkxTo0O1aKKiBBMhhv2MNBQKoiA5wxlZo0JDzD3AYKbWacyj3fs01wxey0pyEP+R8pWKWXoqtIZ0DDg5pbki9krEKOa6LVDQsdoXEsi46Zqh69KFz7B1u7Hb2yDV8firXDKBlZ4UFiswKGRhXTS93/ECK7yxnJ3+S3y/ThpO+cfSD017nqa18aasabU0/t7d+tk0/1oMEJ1NaD67iwdF68OabFSLn+eHb0+vjy+uk8br9fdrftH0O2menfd7+AQfYM/lNjoDHAAAAAElFTkSuQmCC' : IMAGE_PATH + '/delete.png';
  15. /**
  16. *
  17. */
  18. Editor.plusImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/plus.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MDdCMTdENjVCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MDdCMTdENjZCOEM4MTFFNDlCRjVBNDdCODU5NjNBNUMiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowN0IxN0Q2M0I4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowN0IxN0Q2NEI4QzgxMUU0OUJGNUE0N0I4NTk2M0E1QyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PtjrjmgAAAAtSURBVHjaYvz//z8DMigvLwcLdHZ2MiKLMzEQCaivkLGsrOw/dU0cAr4GCDAARQsQbTFrv10AAAAASUVORK5CYII=';
  19. /**
  20. *
  21. */
  22. Editor.spinImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/spin.gif' : 'data:image/gif;base64,R0lGODlhDAAMAPUxAEVriVp7lmCAmmGBm2OCnGmHn3OPpneSqYKbr4OcsIScsI2kto6kt46lt5KnuZmtvpquvpuvv56ywaCzwqK1xKu7yay9yq+/zLHAzbfF0bjG0bzJ1LzK1MDN18jT28nT3M3X3tHa4dTc49Xd5Njf5dng5t3k6d/l6uDm6uru8e7x8/Dz9fT29/b4+Pj5+fj5+vr6+v///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkKADEAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAADAAMAAAGR8CYcEgsOgYAIax4CCQuQldrCBEsiK8VS2hoFGOrlJDA+cZQwkLnqyoJFZKviSS0ICrE0ec0jDAwIiUeGyBFGhMPFBkhZo1BACH5BAkKAC4ALAAAAAAMAAwAhVB0kFR3k1V4k2CAmmWEnW6Lo3KOpXeSqH2XrIOcsISdsImhtIqhtJCmuJGnuZuwv52wwJ+ywZ+ywqm6yLHBzbLCzrXEz7fF0LnH0rrI0r7L1b/M1sXR2cfT28rV3czW3s/Z4Nfe5Nvi6ODm6uLn6+Ln7OLo7OXq7efs7+zw8u/y9PDy9PX3+Pr7+////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZDQJdwSCxGDAIAoVFkFBwYSyIwGE4OkCJxIdG6WkJEx8sSKj7elfBB0a5SQg1EQ0SVVMPKhDM6iUIkRR4ZFxsgJl6JQQAh+QQJCgAxACwAAAAADAAMAIVGa4lcfZdjgpxkg51nhp5ui6N3kqh5lKqFnbGHn7KIoLOQp7iRp7mSqLmTqbqarr6br7+fssGitcOitcSuvsuuv8uwwMyzw861xNC5x9K6x9K/zNbDztjE0NnG0drJ1NzQ2eDS2+LT2+LV3ePZ4Oba4ebb4ufc4+jm6+7t8PLt8PPt8fPx8/Xx9PX09vf19/j3+Pn///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CYcEgsUhQFggFSjCQmnE1jcBhqGBXiIuAQSi7FGEIgfIzCFoCXFCZiPO0hKBMiwl7ET6eUYqlWLkUnISImKC1xbUEAIfkECQoAMgAsAAAAAAwADACFTnKPT3KPVHaTYoKcb4yjcY6leZSpf5mtgZuvh5+yiqG0i6K1jqW3kae5nrHBnrLBn7LCoLPCobTDqbrIqrvIs8LOtMPPtcPPtcTPuMbRucfSvcrUvsvVwMzWxdHaydTcytXdzNbezdff0drh2ODl2+Ln3eTp4Obq4ujs5Ont5uvu6O3w6u7w6u7x7/L09vj5+vr7+vv7////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABkdAmXBILHIcicOCUqxELKKPxKAYgiYd4oMAEWo8RVmjIMScwhmBcJMKXwLCECmMGAhPI1QRwBiaSixCMDFhLSorLi8wYYxCQQAh+QQJCgAxACwAAAAADAAMAIVZepVggJphgZtnhp5vjKN2kah3kqmBmq+KobSLorWNpLaRp7mWq7ybr7+gs8KitcSktsWnuManucexwM2ywc63xtG6yNO9ytS+ytW/zNbDz9jH0tvL1d3N197S2+LU3OPU3ePV3eTX3+Xa4efb4ufd5Onl6u7r7vHs7/Lt8PLw8/Xy9Pby9fb09ff2+Pn3+Pn6+vr///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGSMCYcEgseiwSR+RS7GA4JFGF8RiWNiEiJTERgkjFGAQh/KTCGoJwpApnBkITKrwoCFWnFlEhaAxXLC9CBwAGRS4wQgELYY1CQQAh+QQJCgAzACwAAAAADAAMAIVMcI5SdZFhgZtti6JwjaR4k6mAma6Cm6+KobSLorWLo7WNo7aPpredsMCescGitMOitcSmuMaqu8ixwc2zws63xdC4xtG5x9K9ytXAzdfCztjF0NnF0drK1d3M1t7P2N/P2eDT2+LX3+Xe5Onh5+vi5+vj6Ozk6e3n7O/o7O/q7vHs7/Lt8PPu8fPx8/X3+Pn6+vv7+/v8/Pz///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRcCZcEgsmkIbTOZTLIlGqZNnchm2SCgiJ6IRqljFmQUiXIVnoITQde4chC9Y+LEQxmTFRkFSNFAqDAMIRQoCAAEEDmeLQQAh+QQJCgAwACwAAAAADAAMAIVXeZRefplff5lhgZtph59yjqV2kaeAmq6FnbGFnrGLorWNpLaQp7mRqLmYrb2essGgs8Klt8apusitvcquv8u2xNC7yNO8ydS8ytTAzdfBzdfM1t7N197Q2eDU3OPX3+XZ4ObZ4ebc4+jf5erg5erg5uvp7fDu8fPv8vTz9fb09vf19/j3+Pn4+fn5+vr6+/v///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRUCYcEgspkwjEKhUVJ1QsBNp0xm2VixiSOMRvlxFGAcTJook5eEHIhQcwpWIkAFQECkNy9AQWFwyEAkPRQ4FAwQIE2llQQAh+QQJCgAvACwAAAAADAAMAIVNcY5SdZFigptph6BvjKN0kKd8lquAmq+EnbGGn7KHn7ONpLaOpbearr+csMCdscCescGhtMOnuMauvsuzws60w862xdC9ytW/y9a/zNbCztjG0drH0tvK1N3M1t7N19/U3ePb4uff5urj6Ozk6e3l6u7m6u7o7PDq7vDt8PPv8vTw8vTw8/X19vf6+vv///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CXcEgsvlytVUplJLJIpSEDUESFTELBwSgCCQEV42kjDFiMo4uQsDB2MkLHoEHUTD7DRAHC8VAiZ0QSCgYIDxhNiUEAOw==';
  23. /**
  24. * Used in the GraphViewer lightbox.
  25. */
  26. Editor.tweetImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAARlJREFUeNpi/P//PwM1ABMDlQDVDGKAeo0biMXwKOMD4ilA/AiInwDxfCBWBeIgINYDmwE1yB2Ir0Alsbl6JchONPwNiC8CsTPIDJjXuIBYG4gPAnE8EDMjGaQCxGFYLOAEYlYg/o3sNSkgfo1k2ykgLgRiIyAOwOIaGE6CmwE1SA6IZ0BNR1f8GY9BXugG2UMN+YtHEzr+Aw0OFINYgHgdCYaA8HUgZkM3CASEoYb9ItKgapQkhGQQKC0dJdKQx1CLsRoEArpAvAuI3+Ix5B8Q+2AkaiyZVgGId+MwBBQhKVhzB9QgKyDuAOJ90BSLzZBzQOyCK5uxQNnXoGlJHogfIOU7UCI9C8SbgHgjEP/ElRkZB115BBBgAPbkvQ/azcC0AAAAAElFTkSuQmCC' : IMAGE_PATH + '/tweet.png';
  27. /**
  28. * Used in the GraphViewer lightbox.
  29. */
  30. Editor.facebookImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAARVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADc6ur3AAAAFnRSTlMAYmRg2KVCC/oPq0uAcVQtHtvZuoYh/a7JUAAAAGJJREFUGNOlzkkOgCAMQNEvagvigBP3P6pRNoCJG/+myVu0RdsqxcQqQ/NFVkKQgqwDzoJ2WKajoB66atcAa0GjX0D8lJHwNGfknYJzY77LDtDZ+L74j0z26pZI2yYlMN9TL17xEd+fl1D+AAAAAElFTkSuQmCC' : IMAGE_PATH + '/facebook.png';
  31. /**
  32. * Blank 1x1 pixel transparent PNG image.
  33. */
  34. Editor.blankImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==';
  35. /**
  36. * Default value for custom libraries in mxSettings.
  37. */
  38. Editor.defaultCustomLibraries = [];
  39. /**
  40. * Default value for the CSV import dialog.
  41. */
  42. Editor.defaultCsvValue = '##\n' +
  43. '## Example CSV import. Use ## for comments and # for configuration. Paste CSV below.\n' +
  44. '## The following names are reserved and should not be used (or ignored):\n' +
  45. '## id, tooltip, placeholder(s), link and label (see below)\n' +
  46. '##\n' +
  47. '#\n' +
  48. '## Node label with placeholders and HTML.\n' +
  49. '## Default is \'%name_of_first_column%\'.\n' +
  50. '#\n' +
  51. '# label: %name%<br><i style="color:gray;">%position%</i><br><a href="mailto:%email%">Email</a>\n' +
  52. '#\n' +
  53. '## Node style (placeholders are replaced once).\n' +
  54. '## Default is the current style for nodes.\n' +
  55. '#\n' +
  56. '# style: label;image=%image%;whiteSpace=wrap;html=1;rounded=1;fillColor=%fill%;strokeColor=%stroke%;\n' +
  57. '#\n' +
  58. '## Uses the given column name as the identity for cells (updates existing cells).\n' +
  59. '## Default is no identity (empty value or -).\n' +
  60. '#\n' +
  61. '# identity: -\n' +
  62. '#\n' +
  63. '## Connections between rows ("from": source colum, "to": target column).\n' +
  64. '## Label, style and invert are optional. Defaults are \'\', current style and false.\n' +
  65. '## The target column may contain a comma-separated list of values.\n' +
  66. '## Multiple connect entries are allowed.\n' +
  67. '#\n' +
  68. '# connect: {"from": "manager", "to": "name", "invert": true, "label": "manages", \\\n' +
  69. '# "style": "curved=1;endArrow=blockThin;endFill=1;fontSize=11;"}\n' +
  70. '# connect: {"from": "refs", "to": "id", "style": "curved=1;fontSize=11;"}\n' +
  71. '#\n' +
  72. '## Node width. Possible value are px or auto. Default is auto.\n' +
  73. '#\n' +
  74. '# width: auto\n' +
  75. '#\n' +
  76. '## Node height. Possible value are px or auto. Default is auto.\n' +
  77. '#\n' +
  78. '# height: auto\n' +
  79. '#\n' +
  80. '## Padding for autosize. Default is 0.\n' +
  81. '#\n' +
  82. '# padding: -26\n' +
  83. '#\n' +
  84. '## Comma-separated list of ignored columns for metadata. (These can be\n' +
  85. '## used for connections and styles but will not be added as metadata.)\n' +
  86. '#\n' +
  87. '# ignore: id,image,fill,stroke\n' +
  88. '#\n' +
  89. '## Column to be renamed to link attribute (used as link).\n' +
  90. '#\n' +
  91. '# link: url\n' +
  92. '#\n' +
  93. '## Spacing between nodes. Default is 40.\n' +
  94. '#\n' +
  95. '# nodespacing: 40\n' +
  96. '#\n' +
  97. '## Spacing between parallel edges. Default is 40.\n' +
  98. '#\n' +
  99. '# edgespacing: 40\n' +
  100. '#\n' +
  101. '## Name of layout. Possible values are auto, none, verticaltree, horizontaltree,\n' +
  102. '## verticalflow, horizontalflow, organic, circle. Default is auto.\n' +
  103. '#\n' +
  104. '# layout: auto\n' +
  105. '#\n' +
  106. '## ---- CSV below this line. First line are column names. ----\n' +
  107. 'name,position,id,location,manager,email,fill,stroke,refs,url,image\n' +
  108. 'Evan Miller,CFO,emi,Office 1,,me@example.com,#dae8fc,#6c8ebf,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-9-2-128.png\n' +
  109. 'Edward Morrison,Brand Manager,emo,Office 2,Evan Miller,me@example.com,#d5e8d4,#82b366,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-10-3-128.png\n' +
  110. 'Ron Donovan,System Admin,rdo,Office 3,Evan Miller,me@example.com,#d5e8d4,#82b366,"emo,tva",https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-2-128.png\n' +
  111. 'Tessa Valet,HR Director,tva,Office 4,Evan Miller,me@example.com,#d5e8d4,#82b366,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-3-128.png\n';
  112. /**
  113. * Global configuration of the Editor
  114. * see https://desk.draw.io/solution/articles/16000058316
  115. *
  116. * For defaultVertexStyle, defaultEdgeStyle and defaultLibraries, this must be called before
  117. * mxSettings.load via global config variable window.mxLoadSettings = false.
  118. */
  119. Editor.configure = function(config)
  120. {
  121. if (config != null)
  122. {
  123. Menus.prototype.defaultFonts = config.defaultFonts || Menus.prototype.defaultFonts;
  124. ColorDialog.prototype.presetColors = config.presetColors || ColorDialog.prototype.presetColors;
  125. ColorDialog.prototype.defaultColors = config.defaultColors || ColorDialog.prototype.defaultColors;
  126. StyleFormatPanel.prototype.defaultColorSchemes = config.defaultColorSchemes || StyleFormatPanel.prototype.defaultColorSchemes;
  127. // Custom CSS injected directly into the page
  128. if (config.css != null)
  129. {
  130. var s = document.createElement('style');
  131. s.setAttribute('type', 'text/css');
  132. s.appendChild(document.createTextNode(config.css));
  133. var t = document.getElementsByTagName('script')[0];
  134. t.parentNode.insertBefore(s, t);
  135. }
  136. // Overrides default libraries
  137. if (config.defaultLibraries != null)
  138. {
  139. Sidebar.prototype.defaultEntries = config.defaultLibraries;
  140. }
  141. // Overrides default custom libraries
  142. if (config.defaultCustomLibraries != null)
  143. {
  144. Editor.defaultCustomLibraries = config.defaultCustomLibraries;
  145. }
  146. // Overrides default vertex style
  147. if (config.defaultVertexStyle != null)
  148. {
  149. Graph.prototype.defaultVertexStyle = config.defaultVertexStyle;
  150. }
  151. // Overrides default edge style
  152. if (config.defaultEdgeStyle != null)
  153. {
  154. Graph.prototype.defaultEdgeStyle = config.defaultEdgeStyle;
  155. }
  156. if (config.emptyDiagramXml)
  157. {
  158. EditorUi.prototype.emptyDiagramXml = config.emptyDiagramXml;
  159. }
  160. if (config.thumbWidth)
  161. {
  162. Sidebar.prototype.thumbWidth = config.thumbWidth;
  163. }
  164. if (config.thumbHeight)
  165. {
  166. Sidebar.prototype.thumbHeight = config.thumbHeight;
  167. }
  168. if (config.emptyLibraryXml)
  169. {
  170. EditorUi.prototype.emptyLibraryXml = config.emptyLibraryXml;
  171. }
  172. if (config.sidebarWidth)
  173. {
  174. EditorUi.prototype.hsplitPosition = config.sidebarWidth;
  175. }
  176. if (config.fontCss)
  177. {
  178. var s = document.createElement('style');
  179. s.setAttribute('type', 'text/css');
  180. s.appendChild(document.createTextNode(config.fontCss));
  181. var t = document.getElementsByTagName('script')[0];
  182. t.parentNode.insertBefore(s, t);
  183. Editor.prototype.fontCss = config.fontCss;
  184. }
  185. if (config.plugins != null)
  186. {
  187. // Required for callback
  188. App.initPluginCallback();
  189. for (var i = 0; i < config.plugins.length; i++)
  190. {
  191. mxscript(config.plugins[i]);
  192. }
  193. }
  194. }
  195. };
  196. /**
  197. * Executes the first step for connecting to Google Drive.
  198. */
  199. Editor.prototype.editButtonLink = (urlParams['edit'] != null) ? decodeURIComponent(urlParams['edit']) : null;
  200. /**
  201. *
  202. */
  203. if (urlParams['dev'] == '1')
  204. {
  205. Editor.prototype.editBlankUrl = Editor.prototype.editBlankUrl + '&dev=1';
  206. Editor.prototype.editBlankFallbackUrl = Editor.prototype.editBlankFallbackUrl + '&dev=1';
  207. }
  208. /**
  209. * Adds support for old stylesheets and compressed files
  210. */
  211. var editorSetGraphXml = Editor.prototype.setGraphXml;
  212. Editor.prototype.setGraphXml = function(node)
  213. {
  214. node = (node != null && node.nodeName != 'mxlibrary') ? this.extractGraphModel(node) : null;
  215. if (node != null)
  216. {
  217. // Checks input for parser errors
  218. var errs = node.getElementsByTagName('parsererror');
  219. if (errs != null && errs.length > 0)
  220. {
  221. var elt = errs[0];
  222. var divs = elt.getElementsByTagName('div');
  223. if (divs != null && divs.length > 0)
  224. {
  225. elt = divs[0];
  226. }
  227. throw {message: mxUtils.getTextContent(elt)};
  228. }
  229. else if (node.nodeName == 'mxGraphModel')
  230. {
  231. var style = node.getAttribute('style') || 'default-style2';
  232. // Decodes the style if required
  233. if (urlParams['embed'] != '1' && (style == null || style == ''))
  234. {
  235. var node2 = (this.graph.themes != null) ?
  236. this.graph.themes['default-old'] :
  237. mxUtils.load(STYLE_PATH + '/default-old.xml').getDocumentElement();
  238. if (node2 != null)
  239. {
  240. var dec2 = new mxCodec(node2.ownerDocument);
  241. dec2.decode(node2, this.graph.getStylesheet());
  242. }
  243. }
  244. else if (style != this.graph.currentStyle)
  245. {
  246. var node2 = (this.graph.themes != null) ?
  247. this.graph.themes[style] :
  248. mxUtils.load(STYLE_PATH + '/' + style + '.xml').getDocumentElement()
  249. if (node2 != null)
  250. {
  251. var dec2 = new mxCodec(node2.ownerDocument);
  252. dec2.decode(node2, this.graph.getStylesheet());
  253. }
  254. }
  255. this.graph.currentStyle = style;
  256. this.graph.mathEnabled = (urlParams['math'] == '1' || node.getAttribute('math') == '1');
  257. var bgImg = node.getAttribute('backgroundImage');
  258. if (bgImg != null)
  259. {
  260. bgImg = JSON.parse(bgImg);
  261. this.graph.setBackgroundImage(new mxImage(bgImg.src, bgImg.width, bgImg.height));
  262. }
  263. else
  264. {
  265. this.graph.setBackgroundImage(null);
  266. }
  267. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  268. this.graph.setShadowVisible(node.getAttribute('shadow') == '1', false);
  269. }
  270. // Calls updateGraphComponents
  271. editorSetGraphXml.apply(this, arguments);
  272. }
  273. else
  274. {
  275. throw {
  276. message: mxResources.get('notADiagramFile') || 'Invalid data',
  277. toString: function() { return this.message; }
  278. };
  279. }
  280. };
  281. /**
  282. * Adds persistent style to file
  283. */
  284. var editorGetGraphXml = Editor.prototype.getGraphXml;
  285. Editor.prototype.getGraphXml = function(ignoreSelection)
  286. {
  287. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  288. var node = editorGetGraphXml.apply(this, arguments);
  289. // Adds the current style
  290. if (this.graph.currentStyle != null && this.graph.currentStyle != 'default-style2')
  291. {
  292. node.setAttribute('style', this.graph.currentStyle);
  293. }
  294. // Adds the background image
  295. if (this.graph.backgroundImage != null)
  296. {
  297. node.setAttribute('backgroundImage', JSON.stringify(this.graph.backgroundImage));
  298. }
  299. node.setAttribute('math', (this.graph.mathEnabled) ? '1' : '0');
  300. node.setAttribute('shadow', (this.graph.shadowVisible) ? '1' : '0');
  301. return node;
  302. };
  303. /**
  304. * Helper function to extract the graph model XML node.
  305. */
  306. Editor.prototype.isDataSvg = function(svg)
  307. {
  308. try
  309. {
  310. var svgRoot = mxUtils.parseXml(svg).documentElement;
  311. var tmp = svgRoot.getAttribute('content');
  312. if (tmp != null)
  313. {
  314. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  315. {
  316. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  317. }
  318. if (tmp != null && tmp.charAt(0) == '%')
  319. {
  320. tmp = decodeURIComponent(tmp);
  321. }
  322. if (tmp != null && tmp.length > 0)
  323. {
  324. var node = mxUtils.parseXml(tmp).documentElement;
  325. return node.nodeName == 'mxfile' || node.nodeName == 'mxGraphModel';
  326. }
  327. }
  328. }
  329. catch (e)
  330. {
  331. // ignore
  332. }
  333. return false;
  334. };
  335. /**
  336. * Helper function to extract the graph model XML node.
  337. */
  338. Editor.prototype.extractGraphModel = function(node, allowMxFile)
  339. {
  340. if (node != null && typeof(pako) !== 'undefined')
  341. {
  342. var tmp = node.ownerDocument.getElementsByTagName('div');
  343. var divs = [];
  344. if (tmp != null && tmp.length > 0)
  345. {
  346. for (var i = 0; i < tmp.length; i++)
  347. {
  348. if (tmp[i].getAttribute('class') == 'mxgraph')
  349. {
  350. divs.push(tmp[i]);
  351. break;
  352. }
  353. }
  354. }
  355. if (divs.length > 0)
  356. {
  357. var data = divs[0].getAttribute('data-mxgraph');
  358. if (data != null)
  359. {
  360. var config = JSON.parse(data);
  361. if (config != null && config.xml != null)
  362. {
  363. var doc2 = mxUtils.parseXml(config.xml);
  364. node = doc2.documentElement;
  365. }
  366. }
  367. else
  368. {
  369. var divs2 = divs[0].getElementsByTagName('div');
  370. if (divs2.length > 0)
  371. {
  372. var data = mxUtils.getTextContent(divs2[0]);
  373. data = this.graph.decompress(data);
  374. if (data.length > 0)
  375. {
  376. var doc2 = mxUtils.parseXml(data);
  377. node = doc2.documentElement;
  378. }
  379. }
  380. }
  381. }
  382. }
  383. if (node != null && node.nodeName == 'svg')
  384. {
  385. var tmp = node.getAttribute('content');
  386. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  387. {
  388. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  389. }
  390. if (tmp != null && tmp.charAt(0) == '%')
  391. {
  392. tmp = decodeURIComponent(tmp);
  393. }
  394. if (tmp != null && tmp.length > 0)
  395. {
  396. node = mxUtils.parseXml(tmp).documentElement;
  397. }
  398. else
  399. {
  400. throw {message: mxResources.get('notADiagramFile')};
  401. }
  402. }
  403. if (node != null && !allowMxFile)
  404. {
  405. var diagramNode = null;
  406. if (node.nodeName == 'diagram')
  407. {
  408. diagramNode = node;
  409. }
  410. else if (node.nodeName == 'mxfile')
  411. {
  412. var diagrams = node.getElementsByTagName('diagram');
  413. if (diagrams.length > 0)
  414. {
  415. diagramNode = diagrams[Math.max(0, Math.min(diagrams.length - 1, urlParams['page'] || 0))];
  416. }
  417. }
  418. if (diagramNode != null)
  419. {
  420. var tmp = this.graph.decompress(mxUtils.getTextContent(diagramNode));
  421. if (tmp != null && tmp.length > 0)
  422. {
  423. node = mxUtils.parseXml(tmp).documentElement;
  424. }
  425. }
  426. }
  427. if (node != null && node.nodeName != 'mxGraphModel' && (!allowMxFile || node.nodeName != 'mxfile'))
  428. {
  429. node = null;
  430. }
  431. return node;
  432. };
  433. /**
  434. * Overrides reset graph.
  435. */
  436. var editorResetGraph = Editor.prototype.resetGraph;
  437. Editor.prototype.resetGraph = function()
  438. {
  439. this.graph.mathEnabled = (urlParams['math'] == '1');
  440. this.graph.view.x0 = null;
  441. this.graph.view.y0 = null;
  442. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  443. editorResetGraph.apply(this, arguments);
  444. };
  445. /**
  446. * Math support.
  447. */
  448. Editor.prototype.originalNoForeignObject = mxClient.NO_FO;
  449. var editorUpdateGraphComponents = Editor.prototype.updateGraphComponents;
  450. Editor.prototype.updateGraphComponents = function()
  451. {
  452. editorUpdateGraphComponents.apply(this, arguments);
  453. mxClient.NO_FO = (this.graph.mathEnabled && Editor.MathJaxRender != null) ? true : this.originalNoForeignObject;
  454. };
  455. /**
  456. * Initializes math typesetting and loads respective code.
  457. */
  458. Editor.initMath = function(src, config)
  459. {
  460. src = (src != null) ? src : 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_HTMLorMML';
  461. Editor.mathJaxQueue = [];
  462. Editor.doMathJaxRender = function(container)
  463. {
  464. MathJax.Hub.Queue(['Typeset', MathJax.Hub, container]);
  465. };
  466. // Disables global typesetting and messages on startup, adds queue for
  467. // asynchronous rendering while MathJax is loading
  468. window.MathJax =
  469. {
  470. skipStartupTypeset: true,
  471. showMathMenu: false,
  472. messageStyle: 'none',
  473. AuthorInit: function ()
  474. {
  475. // Specification recommends using SVG over HTML-CSS if browser is known
  476. // Check if too inconsistent with image export and print output
  477. MathJax.Hub.Config(config || {
  478. jax: ['input/TeX', 'input/MathML', 'input/AsciiMath', 'output/HTML-CSS'],
  479. extensions: ['tex2jax.js', 'mml2jax.js', 'asciimath2jax.js'],
  480. TeX: {
  481. extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
  482. },
  483. // Ignores math in in-place editor
  484. tex2jax: {
  485. ignoreClass: 'mxCellEditor'
  486. },
  487. asciimath2jax: {
  488. ignoreClass: 'mxCellEditor'
  489. }
  490. });
  491. MathJax.Hub.Register.StartupHook('Begin', function()
  492. {
  493. for (var i = 0; i < Editor.mathJaxQueue.length; i++)
  494. {
  495. Editor.doMathJaxRender(Editor.mathJaxQueue[i]);
  496. }
  497. });
  498. }
  499. };
  500. // Adds global enqueue method for async rendering
  501. Editor.MathJaxRender = function(container)
  502. {
  503. // Initial rendering when MathJax finished loading
  504. if (typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  505. {
  506. Editor.doMathJaxRender(container);
  507. }
  508. else
  509. {
  510. Editor.mathJaxQueue.push(container);
  511. }
  512. };
  513. // Adds global clear queue method
  514. Editor.MathJaxClear = function()
  515. {
  516. Editor.mathJaxQueue = [];
  517. };
  518. // Updates typeset after changes
  519. var editorInit = Editor.prototype.init;
  520. Editor.prototype.init = function()
  521. {
  522. editorInit.apply(this, arguments);
  523. this.graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  524. {
  525. if (this.graph.mathEnabled)
  526. {
  527. Editor.MathJaxRender(this.graph.container);
  528. }
  529. }));
  530. };
  531. var tags = document.getElementsByTagName('script');
  532. if (tags != null && tags.length > 0)
  533. {
  534. var script = document.createElement('script');
  535. script.type = 'text/javascript';
  536. script.src = src;
  537. tags[0].parentNode.appendChild(script);
  538. }
  539. };
  540. /**
  541. * Return array of string values, or NULL if CSV string not well formed.
  542. */
  543. Editor.prototype.csvToArray = function(text)
  544. {
  545. var re_valid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;
  546. var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;
  547. // Return NULL if input string is not well formed CSV string.
  548. if (!re_valid.test(text)) return null;
  549. var a = []; // Initialize array to receive values.
  550. text.replace(re_value, // "Walk" the string using replace with callback.
  551. function(m0, m1, m2, m3) {
  552. // Remove backslash from \' in single quoted values.
  553. if (m1 !== undefined) a.push(m1.replace(/\\'/g, "'"));
  554. // Remove backslash from \" in double quoted values.
  555. else if (m2 !== undefined) a.push(m2.replace(/\\"/g, '"'));
  556. else if (m3 !== undefined) a.push(m3);
  557. return ''; // Return empty string.
  558. });
  559. // Handle special case of empty last value.
  560. if (/,\s*$/.test(text)) a.push('');
  561. return a;
  562. };
  563. /**
  564. * Adds persistence for recent colors
  565. */
  566. if (window.ColorDialog)
  567. {
  568. var colorDialogAddRecentColor = ColorDialog.addRecentColor;
  569. ColorDialog.addRecentColor = function(color, max)
  570. {
  571. colorDialogAddRecentColor.apply(this, arguments);
  572. mxSettings.setRecentColors(ColorDialog.recentColors);
  573. mxSettings.save();
  574. };
  575. var colorDialogResetRecentColors = ColorDialog.resetRecentColors;
  576. ColorDialog.resetRecentColors = function()
  577. {
  578. colorDialogResetRecentColors.apply(this, arguments);
  579. mxSettings.setRecentColors(ColorDialog.recentColors);
  580. mxSettings.save();
  581. };
  582. }
  583. // Overridden to add edit shape option
  584. if (window.StyleFormatPanel != null)
  585. {
  586. var formatInit = Format.prototype.init;
  587. Format.prototype.init = function()
  588. {
  589. formatInit.apply(this, arguments);
  590. var ui = this.editorUi;
  591. ui.editor.addListener('fileLoaded', this.update);
  592. };
  593. var formatRefresh = Format.prototype.refresh;
  594. Format.prototype.refresh = function()
  595. {
  596. var ui = this.editorUi;
  597. if (ui.getCurrentFile() != null || urlParams['embed'] == '1')
  598. {
  599. formatRefresh.apply(this, arguments);
  600. }
  601. else
  602. {
  603. this.clear();
  604. }
  605. };
  606. /**
  607. * Adds autosave and math typesetting options.
  608. */
  609. var diagramFormatPanelAddOptions = DiagramFormatPanel.prototype.addOptions;
  610. DiagramFormatPanel.prototype.addOptions = function(div)
  611. {
  612. div = diagramFormatPanelAddOptions.apply(this, arguments);
  613. var ui = this.editorUi;
  614. var editor = ui.editor;
  615. var graph = editor.graph;
  616. if (graph.isEnabled())
  617. {
  618. var file = ui.getCurrentFile();
  619. if (file != null && file.isAutosaveOptional())
  620. {
  621. var opt = this.createOption(mxResources.get('autosave'), function()
  622. {
  623. return ui.editor.autosave;
  624. }, function(checked)
  625. {
  626. ui.editor.setAutosave(checked);
  627. },
  628. {
  629. install: function(apply)
  630. {
  631. this.listener = function()
  632. {
  633. apply(ui.editor.autosave);
  634. };
  635. ui.editor.addListener('autosaveChanged', this.listener);
  636. },
  637. destroy: function()
  638. {
  639. ui.editor.removeListener(this.listener);
  640. }
  641. });
  642. div.appendChild(opt);
  643. }
  644. }
  645. return div;
  646. };
  647. /**
  648. * Configures global color schemes.
  649. */
  650. StyleFormatPanel.prototype.defaultColorSchemes = [[null, {fill: '#f5f5f5', stroke: '#666666'},
  651. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  652. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  653. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  654. [null,
  655. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  656. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  657. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  658. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  659. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  660. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  661. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  662. [null, {fill: '#eeeeee', stroke: '#36393d'},
  663. {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  664. {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  665. {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]];
  666. /**
  667. * Adds predefiend styles.
  668. */
  669. var StyleFormatPanelInit = StyleFormatPanel.prototype.init;
  670. StyleFormatPanel.prototype.init = function()
  671. {
  672. // TODO: Update sstate in Format
  673. var sstate = this.format.createSelectionState();
  674. if (sstate.style.shape != 'image')
  675. {
  676. this.container.appendChild(this.addStyles(this.createPanel()));
  677. }
  678. StyleFormatPanelInit.apply(this, arguments);
  679. };
  680. /**
  681. * Overridden to add copy and paste style.
  682. */
  683. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  684. StyleFormatPanel.prototype.addStyleOps = function(div)
  685. {
  686. var btn = mxUtils.button(mxResources.get('copyStyle'), mxUtils.bind(this, function(evt)
  687. {
  688. this.editorUi.actions.get('copyStyle').funct();
  689. }));
  690. btn.setAttribute('title', mxResources.get('copyStyle') + ' (' + this.editorUi.actions.get('copyStyle').shortcut + ')');
  691. btn.style.marginBottom = '2px';
  692. btn.style.width = '100px';
  693. btn.style.marginRight = '2px';
  694. div.appendChild(btn);
  695. var btn = mxUtils.button(mxResources.get('pasteStyle'), mxUtils.bind(this, function(evt)
  696. {
  697. this.editorUi.actions.get('pasteStyle').funct();
  698. }));
  699. btn.setAttribute('title', mxResources.get('pasteStyle') + ' (' + this.editorUi.actions.get('pasteStyle').shortcut + ')');
  700. btn.style.marginBottom = '2px';
  701. btn.style.width = '100px';
  702. div.appendChild(btn);
  703. mxUtils.br(div);
  704. return styleFormatPanelAddStyleOps.apply(this, arguments);
  705. };
  706. /**
  707. * Creates the buttons for the predefined styles.
  708. */
  709. StyleFormatPanel.prototype.addStyles = function(div)
  710. {
  711. var graph = this.editorUi.editor.graph;
  712. var picker = document.createElement('div');
  713. picker.style.whiteSpace = 'normal';
  714. picker.style.paddingLeft = '24px';
  715. picker.style.paddingRight = '20px';
  716. div.style.paddingLeft = '16px';
  717. div.style.paddingBottom = '6px';
  718. div.style.position = 'relative';
  719. div.appendChild(picker);
  720. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-turquoise',
  721. 'plain-orange', 'plain-yellow', 'plain-red', 'plain-pink', 'plain-purple', 'gray',
  722. 'blue', 'green', 'turquoise', 'orange', 'yellow', 'red', 'pink', 'purple'];
  723. function updateScheme(colorsets)
  724. {
  725. function addButton(colorset)
  726. {
  727. var btn = mxUtils.button('', function(evt)
  728. {
  729. graph.getModel().beginUpdate();
  730. try
  731. {
  732. var cells = graph.getSelectionCells();
  733. for (var i = 0; i < cells.length; i++)
  734. {
  735. var style = graph.getModel().getStyle(cells[i]);
  736. for (var j = 0; j < stylenames.length; j++)
  737. {
  738. style = mxUtils.removeStylename(style, stylenames[j]);
  739. }
  740. if (colorset != null)
  741. {
  742. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill']);
  743. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke']);
  744. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient']);
  745. }
  746. else
  747. {
  748. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  749. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, '#000000');
  750. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, null);
  751. }
  752. graph.getModel().setStyle(cells[i], style);
  753. }
  754. }
  755. finally
  756. {
  757. graph.getModel().endUpdate();
  758. }
  759. })
  760. btn.style.width = '36px';
  761. btn.style.height = '30px';
  762. btn.style.margin = '0px 6px 6px 0px';
  763. if (colorset != null)
  764. {
  765. if (colorset['gradient'] != null)
  766. {
  767. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  768. {
  769. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  770. 'StartColorStr=\'' + colorset['fill'] +
  771. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  772. }
  773. else
  774. {
  775. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  776. colorset['gradient'] + ' 100%)';
  777. }
  778. }
  779. else
  780. {
  781. btn.style.backgroundColor = colorset['fill'];
  782. }
  783. btn.style.border = '1px solid ' + colorset['stroke'];
  784. }
  785. else
  786. {
  787. btn.style.backgroundColor = '#ffffff';
  788. btn.style.border = '1px solid #000000';
  789. }
  790. picker.appendChild(btn);
  791. };
  792. picker.innerHTML = '';
  793. for (var i = 0; i < colorsets.length; i++)
  794. {
  795. if (i > 0 && mxUtils.mod(i, 4) == 0)
  796. {
  797. mxUtils.br(picker);
  798. }
  799. addButton(colorsets[i]);
  800. }
  801. };
  802. if (this.editorUi.currentScheme == null)
  803. {
  804. this.editorUi.currentScheme = 0;
  805. }
  806. var left = document.createElement('div');
  807. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  808. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  809. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  810. {
  811. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme - 1, this.defaultColorSchemes.length);
  812. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  813. }));
  814. var right = document.createElement('div');
  815. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  816. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  817. if (this.defaultColorSchemes.length > 1)
  818. {
  819. div.appendChild(left);
  820. div.appendChild(right);
  821. }
  822. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  823. {
  824. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme + 1, this.defaultColorSchemes.length);
  825. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  826. }));
  827. // Hover state
  828. function addHoverState(elt)
  829. {
  830. mxEvent.addListener(elt, 'mouseenter', function()
  831. {
  832. elt.style.opacity = '1';
  833. });
  834. mxEvent.addListener(elt, 'mouseleave', function()
  835. {
  836. elt.style.opacity = '0.5';
  837. });
  838. };
  839. addHoverState(left);
  840. addHoverState(right);
  841. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  842. return div;
  843. };
  844. StyleFormatPanel.prototype.addEditOps = function(div)
  845. {
  846. var ss = this.format.getSelectionState();
  847. var btn = null;
  848. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  849. {
  850. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  851. {
  852. this.editorUi.actions.get('editStyle').funct();
  853. }));
  854. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  855. btn.style.width = '202px';
  856. btn.style.marginBottom = '2px';
  857. div.appendChild(btn);
  858. }
  859. var graph = this.editorUi.editor.graph;
  860. var state = graph.view.getState(graph.getSelectionCell());
  861. if (graph.getSelectionCount() == 1 && state != null && state.shape != null && state.shape.stencil != null)
  862. {
  863. var btn2 = mxUtils.button(mxResources.get('editShape'), mxUtils.bind(this, function(evt)
  864. {
  865. this.editorUi.actions.get('editShape').funct();
  866. }));
  867. btn2.setAttribute('title', mxResources.get('editShape'));
  868. btn2.style.marginBottom = '2px';
  869. if (btn == null)
  870. {
  871. btn2.style.width = '202px';
  872. }
  873. else
  874. {
  875. btn.style.width = '100px';
  876. btn2.style.width = '100px';
  877. btn2.style.marginLeft = '2px';
  878. }
  879. div.appendChild(btn2);
  880. }
  881. else if (ss.image)
  882. {
  883. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  884. {
  885. this.editorUi.actions.get('image').funct();
  886. }));
  887. btn2.setAttribute('title', mxResources.get('editImage'));
  888. btn2.style.marginBottom = '2px';
  889. if (btn == null)
  890. {
  891. btn2.style.width = '202px';
  892. }
  893. else
  894. {
  895. btn.style.width = '100px';
  896. btn2.style.width = '100px';
  897. btn2.style.marginLeft = '2px';
  898. }
  899. div.appendChild(btn2);
  900. }
  901. return div;
  902. };
  903. }
  904. /**
  905. * Changes the default stylename so that it matches the old named style
  906. * if one was specified in the XML.
  907. */
  908. Graph.prototype.defaultThemeName = 'default-style2';
  909. /**
  910. * Contains the last XML that was pasted.
  911. */
  912. Graph.prototype.lastPasteXml = null;
  913. /**
  914. * Contains the number of times the last XML was pasted.
  915. */
  916. Graph.prototype.pasteCounter = 0;
  917. /**
  918. * Graph Overrides
  919. */
  920. Graph.prototype.defaultScrollbars = urlParams['sb'] != '0';
  921. /**
  922. * Specifies if the page should be visible for new files. Default is true.
  923. */
  924. Graph.prototype.defaultPageVisible = urlParams['pv'] != '0';
  925. /**
  926. * Specifies if the page should be visible for new files. Default is true.
  927. */
  928. Graph.prototype.shadowId = 'dropShadow';
  929. /**
  930. * Enables move of bends/segments without selecting.
  931. */
  932. Graph.prototype.edgeMode = urlParams['edge'] != 'move';
  933. /**
  934. * Adds rack child layout style.
  935. */
  936. var graphInit = Graph.prototype.init;
  937. Graph.prototype.init = function()
  938. {
  939. graphInit.apply(this, arguments);
  940. // Override insert location for current mouse point
  941. var mouseEvent = null;
  942. function setMouseEvent(evt)
  943. {
  944. mouseEvent = evt;
  945. // Workaround for member not found in IE8-
  946. if (mxClient.IS_QUIRKS || document.documentMode == 7 || document.documentMode == 8)
  947. {
  948. mouseEvent = mxUtils.clone(evt);
  949. }
  950. };
  951. mxEvent.addListener(this.container, 'mouseenter', setMouseEvent);
  952. mxEvent.addListener(this.container, 'mousemove', setMouseEvent);
  953. mxEvent.addListener(this.container, 'mouseleave', function(evt)
  954. {
  955. mouseEvent = null;
  956. });
  957. // Extends getInsertPoint to use the current mouse location
  958. this.isMouseInsertPoint = function()
  959. {
  960. return mouseEvent != null;
  961. };
  962. var getInsertPoint = this.getInsertPoint;
  963. this.getInsertPoint = function()
  964. {
  965. if (mouseEvent != null)
  966. {
  967. return this.getPointForEvent(mouseEvent);
  968. }
  969. return getInsertPoint.apply(this, arguments);
  970. };
  971. var layoutManagerGetLayout = this.layoutManager.getLayout;
  972. this.layoutManager.getLayout = function(cell)
  973. {
  974. var state = this.graph.view.getState(cell);
  975. var style = (state != null) ? state.style : this.graph.getCellStyle(cell);
  976. // mxRackContainer may be undefined as it is dynamically loaded at render time
  977. if (typeof(mxRackContainer) != 'undefined' && style['childLayout'] == 'rack')
  978. {
  979. var rackLayout = new mxStackLayout(this.graph, false);
  980. rackLayout.setChildGeometry = function(child, geo)
  981. {
  982. var unitSize = 20;
  983. geo.height = Math.max(geo.height, unitSize);
  984. if (geo.height / unitSize > 1)
  985. {
  986. var mod = geo.height % unitSize;
  987. geo.height += mod > unitSize / 2 ? (unitSize - mod) : -mod;
  988. }
  989. this.graph.getModel().setGeometry(child, geo);
  990. };
  991. rackLayout.fill = true;
  992. rackLayout.unitSize = mxRackContainer.unitSize | 20;
  993. rackLayout.marginLeft = style['marginLeft'] || 0;
  994. rackLayout.marginRight = style['marginRight'] || 0;
  995. rackLayout.marginTop = style['marginTop'] || 0;
  996. rackLayout.marginBottom = style['marginBottom'] || 0;
  997. rackLayout.resizeParent = false;
  998. return rackLayout;
  999. }
  1000. return layoutManagerGetLayout.apply(this, arguments);
  1001. }
  1002. };
  1003. /**
  1004. * Sets default style (used in editor.get/setGraphXml below)
  1005. */
  1006. var graphLoadStylesheet = Graph.prototype.loadStylesheet;
  1007. Graph.prototype.loadStylesheet = function()
  1008. {
  1009. graphLoadStylesheet.apply(this, arguments);
  1010. this.currentStyle = 'default-style2';
  1011. };
  1012. /**
  1013. * Adds support for page links.
  1014. */
  1015. Graph.prototype.isPageLink = function(href)
  1016. {
  1017. return href != null && href.substring(0, 10) == 'data:page/';
  1018. };
  1019. /**
  1020. * Adds a shadow filter to the given svg root.
  1021. */
  1022. Graph.prototype.addSvgShadow = function(svgRoot, group, createOnly)
  1023. {
  1024. createOnly = (createOnly != null) ? createOnly : false;
  1025. var svgDoc = svgRoot.ownerDocument;
  1026. var filter = (svgDoc.createElementNS != null) ?
  1027. svgDoc.createElementNS(mxConstants.NS_SVG, 'filter') : svgDoc.createElement('filter');
  1028. filter.setAttribute('id', this.shadowId);
  1029. var blur = (svgDoc.createElementNS != null) ?
  1030. svgDoc.createElementNS(mxConstants.NS_SVG, 'feGaussianBlur') : svgDoc.createElement('feGaussianBlur');
  1031. blur.setAttribute('in', 'SourceAlpha');
  1032. blur.setAttribute('stdDeviation', '1.7');
  1033. blur.setAttribute('result', 'blur');
  1034. filter.appendChild(blur);
  1035. var offset = (svgDoc.createElementNS != null) ?
  1036. svgDoc.createElementNS(mxConstants.NS_SVG, 'feOffset') : svgDoc.createElement('feOffset');
  1037. offset.setAttribute('in', 'blur');
  1038. offset.setAttribute('dx', '3');
  1039. offset.setAttribute('dy', '3');
  1040. offset.setAttribute('result', 'offsetBlur');
  1041. filter.appendChild(offset);
  1042. var flood = (svgDoc.createElementNS != null) ?
  1043. svgDoc.createElementNS(mxConstants.NS_SVG, 'feFlood') : svgDoc.createElement('feFlood');
  1044. flood.setAttribute('flood-color', '#3D4574');
  1045. flood.setAttribute('flood-opacity', '0.4');
  1046. flood.setAttribute('result', 'offsetColor');
  1047. filter.appendChild(flood);
  1048. var composite = (svgDoc.createElementNS != null) ?
  1049. svgDoc.createElementNS(mxConstants.NS_SVG, 'feComposite') : svgDoc.createElement('feComposite');
  1050. composite.setAttribute('in', 'offsetColor');
  1051. composite.setAttribute('in2', 'offsetBlur');
  1052. composite.setAttribute('operator', 'in');
  1053. composite.setAttribute('result', 'offsetBlur');
  1054. filter.appendChild(composite);
  1055. var feBlend = (svgDoc.createElementNS != null) ?
  1056. svgDoc.createElementNS(mxConstants.NS_SVG, 'feBlend') : svgDoc.createElement('feBlend');
  1057. feBlend.setAttribute('in', 'SourceGraphic');
  1058. feBlend.setAttribute('in2', 'offsetBlur');
  1059. filter.appendChild(feBlend);
  1060. // Creates defs element if not available
  1061. var defs = svgRoot.getElementsByTagName('defs');
  1062. var defsElt = null;
  1063. if (defs.length == 0)
  1064. {
  1065. defsElt = (svgDoc.createElementNS != null) ?
  1066. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  1067. if (svgRoot.firstChild != null)
  1068. {
  1069. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  1070. }
  1071. else
  1072. {
  1073. svgRoot.appendChild(defsElt);
  1074. }
  1075. }
  1076. else
  1077. {
  1078. defsElt = defs[0];
  1079. }
  1080. defsElt.appendChild(filter);
  1081. if (!createOnly)
  1082. {
  1083. (group || svgRoot.getElementsByTagName('g')[0]).setAttribute('filter', 'url(#' + this.shadowId + ')');
  1084. if (!isNaN(parseInt(svgRoot.getAttribute('width'))))
  1085. {
  1086. svgRoot.setAttribute('width', parseInt(svgRoot.getAttribute('width')) + 6);
  1087. svgRoot.setAttribute('height', parseInt(svgRoot.getAttribute('height')) + 6);
  1088. }
  1089. }
  1090. return filter;
  1091. };
  1092. /**
  1093. * Loads the stylesheet for this graph.
  1094. */
  1095. Graph.prototype.setShadowVisible = function(value, fireEvent)
  1096. {
  1097. if (mxClient.IS_SVG)
  1098. {
  1099. fireEvent = (fireEvent != null) ? fireEvent : true;
  1100. this.shadowVisible = value;
  1101. if (this.shadowVisible)
  1102. {
  1103. this.view.getDrawPane().setAttribute('filter', 'url(#' + this.shadowId + ')');
  1104. }
  1105. else
  1106. {
  1107. this.view.getDrawPane().removeAttribute('filter');
  1108. }
  1109. if (fireEvent)
  1110. {
  1111. this.fireEvent(new mxEventObject('shadowVisibleChanged'));
  1112. }
  1113. }
  1114. };
  1115. /**
  1116. * Selects first unlocked layer if one exists
  1117. */
  1118. Graph.prototype.selectUnlockedLayer = function()
  1119. {
  1120. if (this.defaultParent == null)
  1121. {
  1122. var childCount = this.model.getChildCount(this.model.root);
  1123. var cell = null;
  1124. var index = 0;
  1125. do
  1126. {
  1127. cell = this.model.getChildAt(this.model.root, index);
  1128. } while (index++ < childCount && mxUtils.getValue(this.getCellStyle(cell), 'locked', '0') == '1')
  1129. if (cell != null)
  1130. {
  1131. this.setDefaultParent(cell);
  1132. }
  1133. }
  1134. };
  1135. /**
  1136. * Specifies special libraries that are loaded via dynamic JS. Add cases
  1137. * where the filename cannot be worked out from the package name. The
  1138. * standard scheme for this mapping is stencils/packagename.xml. If there
  1139. * are multiple XML files, any JS files or any anomalies in the filename or
  1140. * directory that contains the file, then an entry must be added here and
  1141. * in EmbedServlet2 for the loading of the shapes to work.
  1142. */
  1143. // Required to avoid 404 for mockup.xml since naming of mxgraph.mockup.anchor does not contain
  1144. // buttons even though it is defined in the mxMockupButtons.js file. This could only be fixed
  1145. // with aliases for existing shapes or aliases for basenames, but this is essentially the same.
  1146. mxStencilRegistry.libraries['mockup'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1147. mxStencilRegistry.libraries['arrows2'] = [SHAPES_PATH + '/mxArrows.js'];
  1148. mxStencilRegistry.libraries['atlassian'] = [STENCIL_PATH + '/atlassian.xml'];
  1149. mxStencilRegistry.libraries['bpmn'] = [SHAPES_PATH + '/bpmn/mxBpmnShape2.js', STENCIL_PATH + '/bpmn.xml'];
  1150. mxStencilRegistry.libraries['er'] = [SHAPES_PATH + '/er/mxER.js'];
  1151. mxStencilRegistry.libraries['ios'] = [SHAPES_PATH + '/mockup/mxMockupiOS.js'];
  1152. mxStencilRegistry.libraries['rackGeneral'] = [SHAPES_PATH + '/rack/mxRack.js', STENCIL_PATH + '/rack/general.xml'];
  1153. mxStencilRegistry.libraries['rackF5'] = [STENCIL_PATH + '/rack/f5.xml'];
  1154. mxStencilRegistry.libraries['lean_mapping'] = [SHAPES_PATH + '/mxLeanMap.js', STENCIL_PATH + '/lean_mapping.xml'];
  1155. mxStencilRegistry.libraries['basic'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/basic.xml'];
  1156. mxStencilRegistry.libraries['ios7icons'] = [STENCIL_PATH + '/ios7/icons.xml'];
  1157. mxStencilRegistry.libraries['ios7ui'] = [SHAPES_PATH + '/ios7/mxIOS7Ui.js', STENCIL_PATH + '/ios7/misc.xml'];
  1158. mxStencilRegistry.libraries['android'] = [SHAPES_PATH + '/mxAndroid.js', STENCIL_PATH + '/android/android.xml'];
  1159. mxStencilRegistry.libraries['electrical/transmission'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/transmission.xml'];
  1160. mxStencilRegistry.libraries['mockup/buttons'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1161. mxStencilRegistry.libraries['mockup/containers'] = [SHAPES_PATH + '/mockup/mxMockupContainers.js'];
  1162. mxStencilRegistry.libraries['mockup/forms'] = [SHAPES_PATH + '/mockup/mxMockupForms.js'];
  1163. mxStencilRegistry.libraries['mockup/graphics'] = [SHAPES_PATH + '/mockup/mxMockupGraphics.js', STENCIL_PATH + '/mockup/misc.xml'];
  1164. mxStencilRegistry.libraries['mockup/markup'] = [SHAPES_PATH + '/mockup/mxMockupMarkup.js'];
  1165. mxStencilRegistry.libraries['mockup/misc'] = [SHAPES_PATH + '/mockup/mxMockupMisc.js', STENCIL_PATH + '/mockup/misc.xml'];
  1166. mxStencilRegistry.libraries['mockup/navigation'] = [SHAPES_PATH + '/mockup/mxMockupNavigation.js', STENCIL_PATH + '/mockup/misc.xml'];
  1167. mxStencilRegistry.libraries['mockup/text'] = [SHAPES_PATH + '/mockup/mxMockupText.js'];
  1168. mxStencilRegistry.libraries['floorplan'] = [SHAPES_PATH + '/mxFloorplan.js', STENCIL_PATH + '/floorplan.xml'];
  1169. mxStencilRegistry.libraries['bootstrap'] = [SHAPES_PATH + '/mxBootstrap.js', STENCIL_PATH + '/bootstrap.xml'];
  1170. mxStencilRegistry.libraries['gmdl'] = [SHAPES_PATH + '/mxGmdl.js', STENCIL_PATH + '/gmdl.xml'];
  1171. mxStencilRegistry.libraries['cabinets'] = [SHAPES_PATH + '/mxCabinets.js', STENCIL_PATH + '/cabinets.xml'];
  1172. mxStencilRegistry.libraries['archimate'] = [SHAPES_PATH + '/mxArchiMate.js'];
  1173. mxStencilRegistry.libraries['archimate3'] = [SHAPES_PATH + '/mxArchiMate3.js'];
  1174. mxStencilRegistry.libraries['sysml'] = [SHAPES_PATH + '/mxSysML.js'];
  1175. mxStencilRegistry.libraries['eip'] = [SHAPES_PATH + '/mxEip.js', STENCIL_PATH + '/eip.xml'];
  1176. mxStencilRegistry.libraries['networks'] = [SHAPES_PATH + '/mxNetworks.js', STENCIL_PATH + '/networks.xml'];
  1177. mxStencilRegistry.libraries['aws3d'] = [SHAPES_PATH + '/mxAWS3D.js', STENCIL_PATH + '/aws3d.xml'];
  1178. mxStencilRegistry.libraries['pid2inst'] = [SHAPES_PATH + '/pid2/mxPidInstruments.js'];
  1179. mxStencilRegistry.libraries['pid2misc'] = [SHAPES_PATH + '/pid2/mxPidMisc.js', STENCIL_PATH + '/pid/misc.xml'];
  1180. mxStencilRegistry.libraries['pid2valves'] = [SHAPES_PATH + '/pid2/mxPidValves.js'];
  1181. mxStencilRegistry.libraries['pidFlowSensors'] = [STENCIL_PATH + '/pid/flow_sensors.xml'];
  1182. // Triggers dynamic loading for markers
  1183. mxMarker.getPackageForType = function(type)
  1184. {
  1185. var name = null;
  1186. if (type != null && type.length > 0)
  1187. {
  1188. if (type.substring(0, 2) == 'ER')
  1189. {
  1190. name = 'mxgraph.er';
  1191. }
  1192. else if (type.substring(0, 5) == 'sysML')
  1193. {
  1194. name = 'mxgraph.sysml';
  1195. }
  1196. }
  1197. return name;
  1198. };
  1199. var mxMarkerCreateMarker = mxMarker.createMarker;
  1200. mxMarker.createMarker = function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1201. {
  1202. if (type != null)
  1203. {
  1204. var f = mxMarker.markers[type];
  1205. if (f == null)
  1206. {
  1207. var name = this.getPackageForType(type);
  1208. if (name != null)
  1209. {
  1210. mxStencilRegistry.getStencil(name);
  1211. }
  1212. }
  1213. }
  1214. return mxMarkerCreateMarker.apply(this, arguments);
  1215. };
  1216. /**
  1217. * Constructs a new print dialog.
  1218. */
  1219. PrintDialog.prototype.create = function(editorUi, titleText)
  1220. {
  1221. var graph = editorUi.editor.graph;
  1222. var div = document.createElement('div');
  1223. var title = document.createElement('h3');
  1224. title.style.width = '100%';
  1225. title.style.textAlign = 'center';
  1226. title.style.marginTop = '0px';
  1227. mxUtils.write(title, titleText || mxResources.get('print'));
  1228. div.appendChild(title);
  1229. var pageCount = 1;
  1230. var currentPage = 1;
  1231. // Pages
  1232. var pagesSection = document.createElement('div');
  1233. pagesSection.style.cssText = 'border-bottom:1px solid lightGray;padding-bottom:12px;margin-bottom:12px;';
  1234. var allPagesRadio = document.createElement('input');
  1235. allPagesRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  1236. allPagesRadio.setAttribute('value', 'all');
  1237. allPagesRadio.setAttribute('type', 'radio');
  1238. allPagesRadio.setAttribute('name', 'pages-printdialog');
  1239. pagesSection.appendChild(allPagesRadio);
  1240. var span = document.createElement('span');
  1241. mxUtils.write(span, mxResources.get('printAllPages'));
  1242. pagesSection.appendChild(span);
  1243. mxUtils.br(pagesSection);
  1244. // Pages ... to ...
  1245. var pagesRadio = allPagesRadio.cloneNode(true);
  1246. allPagesRadio.setAttribute('checked', 'checked');
  1247. pagesRadio.setAttribute('value', 'range');
  1248. pagesSection.appendChild(pagesRadio);
  1249. var span = document.createElement('span');
  1250. mxUtils.write(span, mxResources.get('pages') + ':');
  1251. pagesSection.appendChild(span);
  1252. var pagesFromInput = document.createElement('input');
  1253. pagesFromInput.style.cssText = 'margin:0 8px 0 8px;'
  1254. pagesFromInput.setAttribute('value', '1');
  1255. pagesFromInput.setAttribute('type', 'number');
  1256. pagesFromInput.setAttribute('min', '1');
  1257. pagesFromInput.style.width = '50px';
  1258. pagesSection.appendChild(pagesFromInput);
  1259. var span = document.createElement('span');
  1260. mxUtils.write(span, mxResources.get('to'));
  1261. pagesSection.appendChild(span);
  1262. var pagesToInput = pagesFromInput.cloneNode(true);
  1263. pagesSection.appendChild(pagesToInput);
  1264. mxEvent.addListener(pagesFromInput, 'focus', function()
  1265. {
  1266. pagesRadio.checked = true;
  1267. });
  1268. mxEvent.addListener(pagesToInput, 'focus', function()
  1269. {
  1270. pagesRadio.checked = true;
  1271. });
  1272. function validatePageRange()
  1273. {
  1274. pagesToInput.value = Math.max(1, Math.min(pageCount, Math.max(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  1275. pagesFromInput.value = Math.max(1, Math.min(pageCount, Math.min(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  1276. };
  1277. mxEvent.addListener(pagesFromInput, 'change', validatePageRange);
  1278. mxEvent.addListener(pagesToInput, 'change', validatePageRange);
  1279. if (editorUi.pages != null)
  1280. {
  1281. pageCount = editorUi.pages.length;
  1282. if (editorUi.currentPage != null)
  1283. {
  1284. for (var i = 0; i < editorUi.pages.length; i++)
  1285. {
  1286. if (editorUi.currentPage == editorUi.pages[i])
  1287. {
  1288. currentPage = i + 1;
  1289. pagesFromInput.value = currentPage;
  1290. pagesToInput.value = currentPage;
  1291. break;
  1292. }
  1293. }
  1294. }
  1295. }
  1296. pagesFromInput.setAttribute('max', pageCount);
  1297. pagesToInput.setAttribute('max', pageCount);
  1298. if (pageCount > 1)
  1299. {
  1300. div.appendChild(pagesSection);
  1301. }
  1302. // Adjust to ...
  1303. var adjustSection = document.createElement('div');
  1304. adjustSection.style.marginBottom = '10px';
  1305. var adjustRadio = document.createElement('input');
  1306. adjustRadio.style.marginRight = '8px';
  1307. adjustRadio.setAttribute('value', 'adjust');
  1308. adjustRadio.setAttribute('type', 'radio');
  1309. adjustRadio.setAttribute('name', 'printZoom');
  1310. adjustSection.appendChild(adjustRadio);
  1311. var span = document.createElement('span');
  1312. mxUtils.write(span, mxResources.get('adjustTo'));
  1313. adjustSection.appendChild(span);
  1314. var zoomInput = document.createElement('input');
  1315. zoomInput.style.cssText = 'margin:0 8px 0 8px;';
  1316. zoomInput.setAttribute('value', '100 %');
  1317. zoomInput.style.width = '50px';
  1318. adjustSection.appendChild(zoomInput);
  1319. mxEvent.addListener(zoomInput, 'focus', function()
  1320. {
  1321. adjustRadio.checked = true;
  1322. });
  1323. div.appendChild(adjustSection);
  1324. // Fit to ...
  1325. var fitSection = pagesSection.cloneNode(false);
  1326. var fitRadio = adjustRadio.cloneNode(true);
  1327. fitRadio.setAttribute('value', 'fit');
  1328. adjustRadio.setAttribute('checked', 'checked');
  1329. var spanFitRadio = document.createElement('div');
  1330. spanFitRadio.style.cssText = 'display:inline-block;height:100%;vertical-align:top;padding-top:2px;';
  1331. spanFitRadio.appendChild(fitRadio);
  1332. fitSection.appendChild(spanFitRadio);
  1333. var table = document.createElement('table');
  1334. table.style.display = 'inline-block';
  1335. var tbody = document.createElement('tbody');
  1336. var row1 = document.createElement('tr');
  1337. var row2 = row1.cloneNode(true);
  1338. var td1 = document.createElement('td');
  1339. var td2 = td1.cloneNode(true);
  1340. var td3 = td1.cloneNode(true);
  1341. var td4 = td1.cloneNode(true);
  1342. var td5 = td1.cloneNode(true);
  1343. var td6 = td1.cloneNode(true);
  1344. td1.style.textAlign = 'right';
  1345. td4.style.textAlign = 'right';
  1346. mxUtils.write(td1, mxResources.get('fitTo'));
  1347. var sheetsAcrossInput = document.createElement('input');
  1348. sheetsAcrossInput.style.cssText = 'margin:0 8px 0 8px;';
  1349. sheetsAcrossInput.setAttribute('value', '1');
  1350. sheetsAcrossInput.setAttribute('min', '1');
  1351. sheetsAcrossInput.setAttribute('type', 'number');
  1352. sheetsAcrossInput.style.width = '40px';
  1353. td2.appendChild(sheetsAcrossInput);
  1354. var span = document.createElement('span');
  1355. mxUtils.write(span, mxResources.get('fitToSheetsAcross'));
  1356. td3.appendChild(span);
  1357. mxUtils.write(td4, mxResources.get('fitToBy'));
  1358. var sheetsDownInput = sheetsAcrossInput.cloneNode(true);
  1359. td5.appendChild(sheetsDownInput);
  1360. mxEvent.addListener(sheetsAcrossInput, 'focus', function()
  1361. {
  1362. fitRadio.checked = true;
  1363. });
  1364. mxEvent.addListener(sheetsDownInput, 'focus', function()
  1365. {
  1366. fitRadio.checked = true;
  1367. });
  1368. var span = document.createElement('span');
  1369. mxUtils.write(span, mxResources.get('fitToSheetsDown'));
  1370. td6.appendChild(span);
  1371. row1.appendChild(td1);
  1372. row1.appendChild(td2);
  1373. row1.appendChild(td3);
  1374. row2.appendChild(td4);
  1375. row2.appendChild(td5);
  1376. row2.appendChild(td6);
  1377. tbody.appendChild(row1);
  1378. tbody.appendChild(row2);
  1379. table.appendChild(tbody);
  1380. fitSection.appendChild(table);
  1381. div.appendChild(fitSection);
  1382. // Page scale ...
  1383. var pageScaleSection = document.createElement('div');
  1384. var span = document.createElement('div');
  1385. span.style.fontWeight = 'bold';
  1386. span.style.marginBottom = '12px';
  1387. mxUtils.write(span, mxResources.get('paperSize'));
  1388. pageScaleSection.appendChild(span);
  1389. var span = document.createElement('div');
  1390. span.style.marginBottom = '12px';
  1391. var accessor = PageSetupDialog.addPageFormatPanel(span, 'printdialog',
  1392. editorUi.editor.graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT);
  1393. pageScaleSection.appendChild(span);
  1394. var span = document.createElement('span');
  1395. mxUtils.write(span, mxResources.get('pageScale'));
  1396. pageScaleSection.appendChild(span);
  1397. var pageScaleInput = document.createElement('input');
  1398. pageScaleInput.style.cssText = 'margin:0 8px 0 8px;';
  1399. pageScaleInput.setAttribute('value', '100 %');
  1400. pageScaleInput.style.width = '60px';
  1401. pageScaleSection.appendChild(pageScaleInput);
  1402. div.appendChild(pageScaleSection);
  1403. // Buttons
  1404. var buttons = document.createElement('div');
  1405. buttons.style.cssText = 'text-align:right;margin:62px 0 0 0;';
  1406. // Overall scale for print-out to account for print borders in dialogs etc
  1407. function preview(print)
  1408. {
  1409. var printScale = parseInt(pageScaleInput.value) / 100;
  1410. if (isNaN(printScale))
  1411. {
  1412. printScale = 1;
  1413. pageScaleInput.value = '100 %';
  1414. }
  1415. // Workaround to match available paper size in actual print output
  1416. printScale *= 0.75;
  1417. function printGraph(thisGraph, pv, forcePageBreaks)
  1418. {
  1419. // Negative coordinates are cropped or shifted if page visible
  1420. var gb = thisGraph.getGraphBounds();
  1421. var border = 0;
  1422. var x0 = 0;
  1423. var y0 = 0;
  1424. var pf = accessor.get();
  1425. var scale = 1 / thisGraph.pageScale;
  1426. var autoOrigin = fitRadio.checked;
  1427. if (autoOrigin)
  1428. {
  1429. var h = parseInt(sheetsAcrossInput.value);
  1430. var v = parseInt(sheetsDownInput.value);
  1431. scale = Math.min((pf.height * v) / (gb.height / thisGraph.view.scale),
  1432. (pf.width * h) / (gb.width / thisGraph.view.scale));
  1433. }
  1434. else
  1435. {
  1436. scale = parseInt(zoomInput.value) / (100 * thisGraph.pageScale);
  1437. if (isNaN(scale))
  1438. {
  1439. printScale = 1 / thisGraph.pageScale;
  1440. zoomInput.value = '100 %';
  1441. }
  1442. }
  1443. // Applies print scale
  1444. pf = mxRectangle.fromRectangle(pf);
  1445. pf.width = Math.ceil(pf.width * printScale);
  1446. pf.height = Math.ceil(pf.height * printScale);
  1447. scale *= printScale;
  1448. // Starts at first visible page
  1449. if (!autoOrigin && thisGraph.pageVisible)
  1450. {
  1451. var layout = thisGraph.getPageLayout();
  1452. x0 -= layout.x * pf.width;
  1453. y0 -= layout.y * pf.height;
  1454. }
  1455. else
  1456. {
  1457. autoOrigin = true;
  1458. }
  1459. if (pv == null)
  1460. {
  1461. pv = PrintDialog.createPrintPreview(thisGraph, scale, pf, border, x0, y0, autoOrigin);
  1462. pv.pageSelector = false;
  1463. pv.mathEnabled = false;
  1464. var writeHead = pv.writeHead;
  1465. // Overridden to add custom fonts
  1466. pv.writeHead = function(doc)
  1467. {
  1468. writeHead.apply(this, arguments);
  1469. if (editorUi.editor.fontCss != null)
  1470. {
  1471. doc.writeln('<style type="text/css">');
  1472. doc.writeln(editorUi.editor.fontCss);
  1473. doc.writeln('</style>');
  1474. }
  1475. };
  1476. if (typeof(MathJax) !== 'undefined')
  1477. {
  1478. // Adds class to ignore if math is disabled
  1479. var printPreviewRenderPage = pv.renderPage;
  1480. pv.renderPage = function(w, h, dx, dy, content, pageNumber)
  1481. {
  1482. var result = printPreviewRenderPage.apply(this, arguments);
  1483. if (this.graph.mathEnabled)
  1484. {
  1485. this.mathEnabled = true;
  1486. }
  1487. else
  1488. {
  1489. result.className = 'geDisableMathJax';
  1490. }
  1491. return result;
  1492. };
  1493. }
  1494. pv.open(null, null, forcePageBreaks, true);
  1495. }
  1496. else
  1497. {
  1498. var bg = thisGraph.background;
  1499. if (bg == null || bg == '' || bg == mxConstants.NONE)
  1500. {
  1501. bg = '#ffffff';
  1502. }
  1503. pv.backgroundColor = bg;
  1504. pv.autoOrigin = autoOrigin;
  1505. pv.appendGraph(thisGraph, scale, x0, y0, forcePageBreaks, true);
  1506. }
  1507. return pv;
  1508. };
  1509. var pagesFrom = pagesFromInput.value;
  1510. var pagesTo = pagesToInput.value;
  1511. var ignorePages = !allPagesRadio.checked;
  1512. var pv = null;
  1513. if (ignorePages)
  1514. {
  1515. ignorePages = pagesFrom == currentPage && pagesTo == currentPage;
  1516. }
  1517. if (!ignorePages && editorUi.pages != null && editorUi.pages.length)
  1518. {
  1519. var i0 = 0;
  1520. var imax = editorUi.pages.length - 1;
  1521. if (!allPagesRadio.checked)
  1522. {
  1523. i0 = parseInt(pagesFrom) - 1;
  1524. imax = parseInt(pagesTo) - 1;
  1525. }
  1526. for (var i = i0; i <= imax; i++)
  1527. {
  1528. var page = editorUi.pages[i];
  1529. var tempGraph = (page == editorUi.currentPage) ? graph : null;
  1530. if (tempGraph == null)
  1531. {
  1532. tempGraph = editorUi.createTemporaryGraph(graph.getStylesheet());
  1533. // Restores graph settings that are relevant for printing
  1534. var pageVisible = true;
  1535. var mathEnabled = false;
  1536. var bg = null;
  1537. var bgImage = null;
  1538. if (page.viewState == null && page.mapping == null)
  1539. {
  1540. // Workaround to extract view state from XML node
  1541. // This changes the state of the page and parses
  1542. // the XML for the graph model even if not needed.
  1543. if (page.root == null)
  1544. {
  1545. editorUi.updatePageRoot(page);
  1546. }
  1547. }
  1548. if (page.viewState != null)
  1549. {
  1550. pageVisible = page.viewState.pageVisible;
  1551. mathEnabled = page.viewState.mathEnabled;
  1552. bg = page.viewState.background;
  1553. bgImage = page.viewState.backgroundImage;
  1554. }
  1555. else if (page.mapping != null && page.mapping.diagramMap != null)
  1556. {
  1557. // Default pageVisible in realtime is true
  1558. mathEnabled = page.mapping.diagramMap.get('mathEnabled') != '0';
  1559. bg = page.mapping.diagramMap.get('background');
  1560. var temp = page.mapping.diagramMap.get('backgroundImage');
  1561. bgImage = (temp != null && temp.length > 0) ? JSON.parse(temp) : null;
  1562. }
  1563. tempGraph.background = bg;
  1564. tempGraph.backgroundImage = (bgImage != null) ? new mxImage(bgImage.src, bgImage.width, bgImage.height) : null;
  1565. tempGraph.pageVisible = pageVisible;
  1566. tempGraph.mathEnabled = mathEnabled;
  1567. // Redirects placeholders to current page
  1568. var graphGetGlobalVariable = tempGraph.getGlobalVariable;
  1569. tempGraph.getGlobalVariable = function(name)
  1570. {
  1571. if (name == 'page')
  1572. {
  1573. return page.getName();
  1574. }
  1575. else if (name == 'pagenumber')
  1576. {
  1577. return i + 1;
  1578. }
  1579. return graphGetGlobalVariable.apply(this, arguments);
  1580. };
  1581. document.body.appendChild(tempGraph.container);
  1582. editorUi.updatePageRoot(page);
  1583. tempGraph.model.setRoot(page.root);
  1584. }
  1585. pv = printGraph(tempGraph, pv, i != imax);
  1586. if (tempGraph != graph)
  1587. {
  1588. tempGraph.container.parentNode.removeChild(tempGraph.container);
  1589. }
  1590. }
  1591. }
  1592. else
  1593. {
  1594. pv = printGraph(graph);
  1595. }
  1596. if (pv.mathEnabled)
  1597. {
  1598. var doc = pv.wnd.document;
  1599. doc.writeln('<script type="text/x-mathjax-config">');
  1600. doc.writeln('MathJax.Hub.Config({');
  1601. doc.writeln('messageStyle: "none",');
  1602. doc.writeln('jax: ["input/TeX", "input/MathML", "input/AsciiMath", "output/HTML-CSS"],');
  1603. doc.writeln('extensions: ["tex2jax.js", "mml2jax.js", "asciimath2jax.js"],');
  1604. doc.writeln('TeX: {');
  1605. doc.writeln('extensions: ["AMSmath.js", "AMSsymbols.js", "noErrors.js", "noUndefined.js"]');
  1606. doc.writeln('},');
  1607. // Ignores math in in-place editor
  1608. doc.writeln('tex2jax: {');
  1609. doc.writeln(' ignoreClass: "geDisableMathJax"');
  1610. doc.writeln('},');
  1611. doc.writeln('asciimath2jax: {');
  1612. doc.writeln(' ignoreClass: "geDisableMathJax"');
  1613. doc.writeln('}');
  1614. doc.writeln('});');
  1615. // Adds asynchronous printing when MathJax finished rendering
  1616. if (print)
  1617. {
  1618. doc.writeln('MathJax.Hub.Queue(function () {');
  1619. doc.writeln('window.print();');
  1620. doc.writeln('});');
  1621. }
  1622. doc.writeln('</script>');
  1623. doc.writeln('<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>');
  1624. }
  1625. pv.closeDocument();
  1626. if (!pv.mathEnabled && print)
  1627. {
  1628. PrintDialog.printPreview(pv);
  1629. }
  1630. };
  1631. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1632. {
  1633. editorUi.hideDialog();
  1634. });
  1635. cancelBtn.className = 'geBtn';
  1636. if (editorUi.editor.cancelFirst)
  1637. {
  1638. buttons.appendChild(cancelBtn);
  1639. }
  1640. if (!editorUi.isOffline())
  1641. {
  1642. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  1643. {
  1644. window.open('https://desk.draw.io/support/solutions/articles/16000048947');
  1645. });
  1646. helpBtn.className = 'geBtn';
  1647. buttons.appendChild(helpBtn);
  1648. }
  1649. if (PrintDialog.previewEnabled)
  1650. {
  1651. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  1652. {
  1653. editorUi.hideDialog();
  1654. preview(false);
  1655. });
  1656. previewBtn.className = 'geBtn';
  1657. buttons.appendChild(previewBtn);
  1658. }
  1659. var printBtn = mxUtils.button(mxResources.get((!PrintDialog.previewEnabled) ? 'ok' : 'print'), function()
  1660. {
  1661. editorUi.hideDialog();
  1662. preview(true);
  1663. });
  1664. printBtn.className = 'geBtn gePrimaryBtn';
  1665. buttons.appendChild(printBtn);
  1666. if (!editorUi.editor.cancelFirst)
  1667. {
  1668. buttons.appendChild(cancelBtn);
  1669. }
  1670. div.appendChild(buttons);
  1671. this.container = div;
  1672. };
  1673. })();