/
EditorUi.js
16310 lines (14102 loc) · 429 KB
/
EditorUi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2006-2017, JGraph Ltd
* Copyright (c) 2006-2017, Gaudenz Alder
*/
(function()
{
/**
* Version
*/
EditorUi.VERSION = '@DRAWIO-VERSION@';
/**
* Overrides compact UI setting.
*/
EditorUi.compactUi = uiTheme != 'atlas';
/**
* Overrides default grid color for dark mode
*/
if (Editor.isDarkMode())
{
mxGraphView.prototype.gridColor = mxGraphView.prototype.defaultDarkGridColor;
}
/**
* Switch to disable logging for mode and search terms.
*/
EditorUi.enableLogging = urlParams['stealth'] != '1' && urlParams['lockdown'] != '1' &&
(/.*\.draw\.io$/.test(window.location.hostname) ||
/.*\.diagrams\.net$/.test(window.location.hostname)) &&
window.location.hostname != 'support.draw.io';
/**
* Protocol and hostname to use for embedded files. Default is https://www.draw.io
*/
EditorUi.drawHost = window.DRAWIO_BASE_URL;
/**
* Protocol and hostname to use for embedded files. Default is https://www.draw.io
*/
EditorUi.lightboxHost = window.DRAWIO_LIGHTBOX_URL;
/**
* Switch to disable logging for mode and search terms.
*/
EditorUi.lastErrorMessage = null;
/**
* Switch to disable logging for mode and search terms.
*/
EditorUi.ignoredAnonymizedChars = '\n\t`~!@#$%^&*()_+{}|:"<>?-=[]\;\'.\/,\n\t';
/**
* Specifies the URL for the templates index file.
*/
EditorUi.templateFile = TEMPLATE_PATH + '/index.xml';
/**
* Specifies the URL for the diffsync cache.
*/
EditorUi.cacheUrl = window.REALTIME_URL;
/**
* Disables sync if no diffsync cache is defined.
*/
if (EditorUi.cacheUrl == null && typeof DrawioFile !== 'undefined')
{
DrawioFile.SYNC = 'none'; // Disables real-time sync
}
/**
* Cache timeout is 10 seconds.
*/
Editor.cacheTimeout = 10000;
/**
* Switch to enable PlantUML in the insert from text dialog.
* NOTE: This must also be enabled on the server-side.
*/
EditorUi.enablePlantUml = EditorUi.enableLogging;
/**
* https://github.com/electron/electron/issues/2288
*/
EditorUi.isElectronApp = window != null && window.process != null &&
window.process.versions != null && window.process.versions['electron'] != null;
/**
* Shortcut for capability check.
*/
EditorUi.nativeFileSupport = !mxClient.IS_OP && !EditorUi.isElectronApp &&
urlParams['extAuth'] != '1' && 'showSaveFilePicker' in window &&
'showOpenFilePicker' in window;
/**
* Specifies if drafts should be saved in IndexedDB.
*/
EditorUi.enableDrafts = !mxClient.IS_CHROMEAPP &&
isLocalStorage && urlParams['drafts'] != '0';
/**
* Link for scratchpad help.
*/
EditorUi.scratchpadHelpLink = 'https://www.diagrams.net/doc/faq/scratchpad';
/**
* Specifies if the edit option should be shown in the HTML export dialog.
*/
EditorUi.enableHtmlEditOption = true;
/**
* Default Mermaid config without using foreign objects in flowcharts.
*/
EditorUi.defaultMermaidConfig = {
theme:'neutral',
arrowMarkerAbsolute:false,
flowchart:
{
htmlLabels:false
},
sequence:
{
diagramMarginX:50,
diagramMarginY:10,
actorMargin:50,
width:150,
height:65,
boxMargin:10,
boxTextMargin:5,
noteMargin:10,
messageMargin:35,
mirrorActors:true,
bottomMarginAdj:1,
useMaxWidth:true,
rightAngles:false,
showSequenceNumbers:false
},
gantt:{
titleTopMargin:25,
barHeight:20,
barGap:4,
topPadding:50,
leftPadding:75,
gridLineStartPadding:35,
fontSize:11,
fontFamily:'"Open-Sans", "sans-serif"',
numberSectionStyles:4,
axisFormat:'%Y-%m-%d'
}
};
/**
* Updates action states depending on the selection.
*/
EditorUi.logError = function(message, url, linenumber, colno, err, severity, quiet)
{
severity = ((severity != null) ? severity : (message.indexOf('NetworkError') >= 0 ||
message.indexOf('SecurityError') >= 0 || message.indexOf('NS_ERROR_FAILURE') >= 0 ||
message.indexOf('out of memory') >= 0) ? 'CONFIG' : 'SEVERE');
if (EditorUi.enableLogging && urlParams['dev'] != '1')
{
try
{
if (message == EditorUi.lastErrorMessage || (message != null && url != null &&
((message.indexOf('Script error') != -1) || (message.indexOf('extension') != -1))))
{
// TODO log external domain script failure "Script error." is
// reported when the error occurs in a script that is hosted
// on a domain other than the domain of the current page
}
// DocumentClosedError seems to be an FF bug an can be ignored for now
else if (message != null && message.indexOf('DocumentClosedError') < 0)
{
EditorUi.lastErrorMessage = message;
var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
err = (err != null) ? err : new Error(message);
var img = new Image();
img.src = logDomain + '/log?severity=' + severity + '&v=' + encodeURIComponent(EditorUi.VERSION) +
'&msg=clientError:' + encodeURIComponent(message) + ':url:' + encodeURIComponent(window.location.href) +
':lnum:' + encodeURIComponent(linenumber) + ((colno != null) ? ':colno:' + encodeURIComponent(colno) : '') +
((err != null && err.stack != null) ? '&stack=' + encodeURIComponent(err.stack) : '');
}
}
catch (e)
{
// do nothing
}
}
try
{
if (!quiet && window.console != null)
{
console.error(severity, message, url, linenumber, colno, err);
}
}
catch (e)
{
// ignore
}
};
/**
* Updates action states depending on the selection.
*/
EditorUi.logEvent = function(data)
{
if (urlParams['dev'] == '1')
{
EditorUi.debug('logEvent', data);
}
else if (EditorUi.enableLogging)
{
try
{
var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
var img = new Image();
img.src = logDomain + '/images/1x1.png?' +
'v=' + encodeURIComponent(EditorUi.VERSION) +
((data != null) ? '&data=' + encodeURIComponent(JSON.stringify(data)) : '');
}
catch (e)
{
// ignore
}
}
};
/**
* Sending error reports.
*/
EditorUi.sendReport = function(data, maxLength)
{
if (urlParams['dev'] == '1')
{
EditorUi.debug('sendReport', data);
}
else if (EditorUi.enableLogging)
{
try
{
maxLength = (maxLength != null) ? maxLength : 50000;
if (data.length > maxLength)
{
data = data.substring(0, maxLength) + '\n...[SHORTENED]'
}
mxUtils.post('/email', 'version=' + encodeURIComponent(EditorUi.VERSION) +
'&url=' + encodeURIComponent(window.location.href) +
'&data=' + encodeURIComponent(data));
}
catch (e)
{
// ignore
}
}
};
/**
* Adds the listener for automatically saving the diagram for local changes.
*/
EditorUi.debug = function()
{
try
{
if (window.console != null && urlParams['test'] == '1')
{
var args = [new Date().toISOString()];
for (var i = 0; i < arguments.length; i++)
{
args.push(arguments[i]);
}
console.log.apply(console, args);
}
}
catch (e)
{
// ignore
}
};
/**
* Removes any values, styles and geometries from the given XML node.
*/
EditorUi.removeChildNodes = function(node)
{
while (node.firstChild != null)
{
node.removeChild(node.firstChild);
}
};
/**
* Contains the default XML for an empty diagram.
*/
EditorUi.prototype.emptyDiagramXml = '<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel>';
/**
*
*/
EditorUi.prototype.emptyLibraryXml = '<mxlibrary>[]</mxlibrary>';
/**
* Sets the delay for autosave in milliseconds. Default is 2000.
*/
EditorUi.prototype.mode = null;
/**
* General timeout is 25 seconds.
* LATER: Move to Editor
*/
EditorUi.prototype.timeout = Editor.prototype.timeout;
/**
* Allows for two buttons in the sidebar footer.
*/
EditorUi.prototype.sidebarFooterHeight = 38;
/**
* Specifies the default custom shape style.
*/
EditorUi.prototype.defaultCustomShapeStyle = 'shape=stencil(tZRtTsQgEEBPw1+DJR7AoN6DbWftpAgE0Ortd/jYRGq72R+YNE2YgTePloEJGWblgA18ZuKFDcMj5/Sm8boZq+BgjCX4pTyqk6ZlKROitwusOMXKQDODx5iy4pXxZ5qTHiFHawxB0JrQZH7lCabQ0Fr+XWC1/E8zcsT/gAi+Subo2/3Mh6d/oJb5nU1b5tW7r2knautaa3T+U32o7f7vZwpJkaNDLORJjcu7t59m2jXxqX9un+tt022acsfmoKaQZ+vhhswZtS6Ne/ThQGt0IV0N3Yyv6P3CeT9/tHO0XFI5cAE=);whiteSpace=wrap;html=1;';
/**
* Defines the maximum size for images.
*/
EditorUi.prototype.maxBackgroundSize = 1600;
/**
* Defines the maximum size for images.
*/
EditorUi.prototype.maxImageSize = 520;
/**
* Defines the maximum width for pasted text.
* Use 0 to disable check.
*/
EditorUi.prototype.maxTextWidth = 520;
/**
* Images above 100K should be resampled.
*/
EditorUi.prototype.resampleThreshold = 100000;
/**
* Maximum allowed size for images is 1 MB.
*/
EditorUi.prototype.maxImageBytes = 1000000;
/**
* Maximum size for background images is 2.5 MB.
*/
EditorUi.prototype.maxBackgroundBytes = 2500000;
/**
* Maximum size for text files in labels is 0.5 MB.
*/
EditorUi.prototype.maxTextBytes = 500000;
/**
* Holds the current file.
*/
EditorUi.prototype.currentFile = null;
/**
* Specifies if PDF export should be done via print dialog. Default is
* false which uses the PhantomJS backend to create the PDF.
*/
EditorUi.prototype.printPdfExport = false;
/**
* Specifies if PDF export with pages is enabled.
*/
EditorUi.prototype.pdfPageExport = true;
/**
* Restores app defaults for UI
*/
EditorUi.prototype.formatEnabled = urlParams['format'] != '0';
/**
* Whether template action should be shown in insert menu.
*/
EditorUi.prototype.insertTemplateEnabled = true;
/**
* Restores app defaults for UI
*/
EditorUi.prototype.closableScratchpad = true;
/**
* Restores app defaults for UI
*/
EditorUi.prototype.embedExportBorder = 8;
/**
* Restores app defaults for UI
*/
EditorUi.prototype.embedExportBackground = null;
/**
* Restores app defaults for UI
*/
EditorUi.prototype.shareCursorPosition = true;
/**
* Restores app defaults for UI
*/
EditorUi.prototype.showRemoteCursors = true;
/**
* Capability check for canvas export
*/
(function()
{
EditorUi.prototype.useCanvasForExport = false;
EditorUi.prototype.jpgSupported = false;
// Checks if canvas is supported
try
{
var cnv = document.createElement('canvas');
EditorUi.prototype.canvasSupported = !!(cnv.getContext && cnv.getContext('2d'));
}
catch (e)
{
// ignore
}
try
{
var canvas = document.createElement('canvas');
var img = new Image();
// LATER: Capability check should not be async
img.onload = function()
{
try
{
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
// Works in Chrome, Firefox, Edge, Safari and Opera
var result = canvas.toDataURL('image/png');
EditorUi.prototype.useCanvasForExport = result != null && result.length > 6;
}
catch (e)
{
// ignore
}
};
// Checks if SVG with foreignObject can be exported
var svg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1px" height="1px" version="1.1"><foreignObject pointer-events="all" width="1" height="1"><div xmlns="http://www.w3.org/1999/xhtml"></div></foreignObject></svg>';
img.src = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svg)));
}
catch (e)
{
// ignore
}
// Checks for client-side JPG support
try
{
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
var uri = canvas.toDataURL('image/jpeg');
EditorUi.prototype.jpgSupported = (uri.match('image/jpeg') !== null);
}
catch (e)
{
// ignore
}
})();
/**
* Hook for subclassers.
*/
EditorUi.prototype.openLink = function(url, target, allowOpener)
{
// LATER: Replace this with direct calls to graph
return this.editor.graph.openLink(url, target, allowOpener);
};
/**
* Hook for subclassers.
*/
EditorUi.prototype.showSplash = function(force) { };
/**
* Abstraction for local storage access.
*/
EditorUi.prototype.getLocalData = function(key, fn)
{
fn(localStorage.getItem(key));
};
/**
* Abstraction for local storage access.
*/
EditorUi.prototype.setLocalData = function(key, data, fn)
{
localStorage.setItem(key, data);
if (fn != null)
{
fn();
}
};
/**
* Abstraction for local storage access.
*/
EditorUi.prototype.removeLocalData = function(key, fn)
{
localStorage.removeItem(key)
fn();
};
/**
* Returns true if offline app, which isn't a defined thing
*/
EditorUi.prototype.setShareCursorPosition = function(value)
{
this.shareCursorPosition = value;
this.fireEvent(new mxEventObject('shareCursorPositionChanged'));
};
/**
* Returns true if offline app, which isn't a defined thing
*/
EditorUi.prototype.isShareCursorPosition = function()
{
return this.shareCursorPosition;
};
/**
* Returns true if offline app, which isn't a defined thing
*/
EditorUi.prototype.setShowRemoteCursors = function(value)
{
this.showRemoteCursors = value;
this.fireEvent(new mxEventObject('showRemoteCursorsChanged'));
};
/**
* Returns true if offline app, which isn't a defined thing
*/
EditorUi.prototype.isShowRemoteCursors = function()
{
return this.showRemoteCursors;
};
/**
* Returns true if offline app, which isn't a defined thing
*/
EditorUi.prototype.setMathEnabled = function(value)
{
this.editor.graph.mathEnabled = value;
this.editor.updateGraphComponents();
this.editor.graph.refresh();
this.editor.graph.defaultMathEnabled = value;
this.fireEvent(new mxEventObject('mathEnabledChanged'));
};
/**
* Returns true if offline app, which isn't a defined thing
*/
EditorUi.prototype.isMathEnabled = function(value)
{
return this.editor.graph.mathEnabled;
};
/**
* Returns true if offline app, which isn't a defined thing
*/
EditorUi.prototype.isOfflineApp = function()
{
return urlParams['offline'] == '1';
};
/**
* Deprecated. Poorly defined, to be replaced with isExternalDataComms and other more granular flags.
* Original idea was it returns true if no external comms allowed or possible
*/
EditorUi.prototype.isOffline = function(ignoreStealth)
{
return this.isOfflineApp() || !navigator.onLine || (!ignoreStealth && (urlParams['stealth'] == '1' || urlParams['lockdown'] == '1'));
};
/**
* Returns true if diagram data transmission other than save/load is allowed or possible..
*/
EditorUi.prototype.isExternalDataComms = function()
{
return urlParams['offline'] != '1' && !this.isOffline() && !this.isOfflineApp();
};
/**
* Translates this point by the given vector.
*
* @param {number} dx X-coordinate of the translation.
* @param {number} dy Y-coordinate of the translation.
*/
EditorUi.prototype.createSpinner = function(x, y, size)
{
var autoPosition = (x == null || y == null);
size = (size != null) ? size : 24;
var spinner = new Spinner({
lines: 12, // The number of lines to draw
length: size, // The length of each line
width: Math.round(size / 3), // The line thickness
radius: Math.round(size / 2), // 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
zIndex: 2e9 // The z-index (defaults to 2000000000)
});
// Extends spin method to include an optional label
var oldSpin = spinner.spin;
spinner.spin = function(container, label)
{
var result = false;
if (!this.active)
{
oldSpin.call(this, container);
this.active = true;
if (label != null)
{
if (autoPosition)
{
y = Math.max(document.body.clientHeight || 0, document.documentElement.clientHeight || 0) / 2;
x = document.body.clientWidth / 2 - 2;
}
var status = document.createElement('div');
status.style.position = 'absolute';
status.style.whiteSpace = 'nowrap';
status.style.background = '#4B4243';
status.style.color = 'white';
status.style.fontFamily = Editor.defaultHtmlFont;
status.style.fontSize = '9pt';
status.style.padding = '6px';
status.style.paddingLeft = '10px';
status.style.paddingRight = '10px';
status.style.zIndex = 2e9;
status.style.left = Math.max(0, x) + 'px';
status.style.top = Math.max(0, y + 70) + 'px';
mxUtils.setPrefixedStyle(status.style, 'borderRadius', '6px');
mxUtils.setPrefixedStyle(status.style, 'transform', 'translate(-50%,-50%)');
if (!Editor.isDarkMode())
{
mxUtils.setPrefixedStyle(status.style, 'boxShadow', '2px 2px 3px 0px #ddd');
}
if (label.substring(label.length - 3, label.length) != '...' &&
label.charAt(label.length - 1) != '!')
{
label = label + '...';
}
status.innerHTML = label;
container.appendChild(status);
spinner.status = status;
}
// Pause returns a function to resume the spinner
this.pause = mxUtils.bind(this, function()
{
var fn = function() { };
if (this.active)
{
fn = mxUtils.bind(this, function()
{
this.spin(container, label);
});
}
this.stop();
return fn;
});
result = true;
}
return result;
};
// Extends stop method to remove the optional label
var oldStop = spinner.stop;
spinner.stop = function()
{
oldStop.call(this);
this.active = false;
if (spinner.status != null && spinner.status.parentNode != null)
{
spinner.status.parentNode.removeChild(spinner.status);
}
spinner.status = null;
};
spinner.pause = function()
{
return function() {};
};
return spinner;
};
/**
* Returns true if the given string contains a compatible graph model.
*/
EditorUi.prototype.isCompatibleString = function(data)
{
try
{
var doc = mxUtils.parseXml(data);
var node = this.editor.extractGraphModel(doc.documentElement, true);
return node != null && node.getElementsByTagName('parsererror').length == 0;
}
catch (e)
{
// ignore
}
return false;
};
/**
* Returns true if the given binary data is a Visio file.
*/
EditorUi.prototype.isVisioData = function(data)
{
return data.length > 8 && ((data.charCodeAt(0) == 0xD0 && data.charCodeAt(1) == 0xCF &&
data.charCodeAt(2) == 0x11 && data.charCodeAt(3) == 0xE0 && data.charCodeAt(4) == 0xA1 && data.charCodeAt(5) == 0xB1 &&
data.charCodeAt(6) == 0x1A && data.charCodeAt(7) == 0xE1) || (data.charCodeAt(0) == 0x50 && data.charCodeAt(1) == 0x4B &&
data.charCodeAt(2) == 0x03 && data.charCodeAt(3) == 0x04) || (data.charCodeAt(0) == 0x50 && data.charCodeAt(1) == 0x4B &&
data.charCodeAt(2) == 0x03 && data.charCodeAt(3) == 0x06));
};
/**
* Returns true if the given binary data is a Visio file that requires remote conversion.
* This code returns true for vss, vsd and vdx files.
*/
EditorUi.prototype.isRemoteVisioData = function(data)
{
return data.length > 8 && ((data.charCodeAt(0) == 0xD0 && data.charCodeAt(1) == 0xCF &&
data.charCodeAt(2) == 0x11 && data.charCodeAt(3) == 0xE0 && data.charCodeAt(4) == 0xA1 && data.charCodeAt(5) == 0xB1 &&
data.charCodeAt(6) == 0x1A && data.charCodeAt(7) == 0xE1) || (data.charCodeAt(0) == 0x3C && data.charCodeAt(1) == 0x3F &&
data.charCodeAt(2) == 0x78 && data.charCodeAt(3) == 0x6D && data.charCodeAt(3) == 0x6C));
};
/**
* Adds keyboard shortcuts for page handling.
*/
var editorUiCreateKeyHandler = EditorUi.prototype.createKeyHandler;
EditorUi.prototype.createKeyHandler = function(editor)
{
var keyHandler = editorUiCreateKeyHandler.apply(this, arguments);
if (!this.editor.chromeless || this.editor.editable)
{
var keyHandlerGetFunction = keyHandler.getFunction;
var graph = this.editor.graph;
var ui = this;
keyHandler.getFunction = function(evt)
{
if (graph.isSelectionEmpty() && ui.pages != null && ui.pages.length > 0)
{
var idx = ui.getSelectedPageIndex();
if (mxEvent.isShiftDown(evt))
{
if (evt.keyCode == 37)
{
return function()
{
if (idx > 0)
{
ui.movePage(idx, idx - 1);
}
};
}
else if (evt.keyCode == 38)
{
return function()
{
if (idx > 0)
{
ui.movePage(idx, 0);
}
};
}
else if (evt.keyCode == 39)
{
return function()
{
if (idx < ui.pages.length - 1)
{
ui.movePage(idx, idx + 1);
}
};
}
else if (evt.keyCode == 40)
{
return function()
{
if (idx < ui.pages.length - 1)
{
ui.movePage(idx, ui.pages.length - 1);
}
};
}
}
else if (mxEvent.isControlDown(evt) || (mxClient.IS_MAC && mxEvent.isMetaDown(evt)))
{
if (evt.keyCode == 37)
{
return function()
{
if (idx > 0)
{
ui.selectNextPage(false);
}
};
}
else if (evt.keyCode == 38)
{
return function()
{
if (idx > 0)
{
ui.selectPage(ui.pages[0]);
}
};
}
else if (evt.keyCode == 39)
{
return function()
{
if (idx < ui.pages.length - 1)
{
ui.selectNextPage(true);
}
};
}
else if (evt.keyCode == 40)
{
return function()
{
if (idx < ui.pages.length - 1)
{
ui.selectPage(ui.pages[ui.pages.length - 1]);
}
};
}
}
}
return keyHandlerGetFunction.apply(this, arguments);
};
}
return keyHandler;
};
/**
* Extracts the mxfile from the given HTML data from a data transfer event.
*/
var editorUiExtractGraphModelFromHtml = EditorUi.prototype.extractGraphModelFromHtml;
EditorUi.prototype.extractGraphModelFromHtml = function(data)
{
var result = editorUiExtractGraphModelFromHtml.apply(this, arguments);
if (result == null)
{
try
{
var idx = data.indexOf('<mxfile ');
if (idx >= 0)
{
var idx2 = data.lastIndexOf('</mxfile>');
if (idx2 > idx)
{
result = data.substring(idx, idx2 + 15).replace(/>/g, '>').
replace(/</g, '<').replace(/\\"/g, '"').replace(/\n/g, '');
}
}
else
{
// Gets compressed data from mxgraph element in HTML document
var doc = mxUtils.parseXml(data);
var node = this.editor.extractGraphModel(doc.documentElement, this.pages != null ||
this.diagramContainer.style.visibility == 'hidden');
result = (node != null) ? mxUtils.getXml(node) : '';
}
}
catch (e)
{
// ignore
}
}
return result;
};
/**
* Workaround for malformed xhtml meta element bug 07.08.16. The trailing slash was missing causing
* reopen to fail trying to parse. Used in replaceFileData, setFileData and importFile.
*/
EditorUi.prototype.validateFileData = function(data)
{
if (data != null && data.length > 0)
{
var index = data.indexOf('<meta charset="utf-8">');
if (index >= 0)
{
var replaceString = '<meta charset="utf-8"/>';
var replaceStrLen = replaceString.length;
data = data.slice(0, index) + replaceString + data.slice(index + replaceStrLen - 1, data.length);
}
data = Graph.zapGremlins(data);
}
return data;
};
/**
*
*/
EditorUi.prototype.replaceFileData = function(data)
{
data = this.validateFileData(data);
var node = (data != null && data.length > 0) ? mxUtils.parseXml(data).documentElement : null;
// Some nodes must be extracted here to find the mxfile node
// LATER: Remove duplicate call to extractGraphModel in overridden setGraphXml
var tmp = (node != null) ? this.editor.extractGraphModel(node, true) : null;
if (tmp != null)
{
node = tmp;
}
if (node != null)
{
var graph = this.editor.graph;
graph.model.beginUpdate();
try
{
var oldPages = (this.pages != null) ? this.pages.slice() : null;
var nodes = node.getElementsByTagName('diagram');
if (urlParams['pages'] != '0' || nodes.length > 1 ||
(nodes.length == 1 && nodes[0].hasAttribute('name')))
{
this.fileNode = node;
this.pages = (this.pages != null) ? this.pages : [];
// Wraps page nodes
for (var i = nodes.length - 1; i >= 0; i--)
{
var page = this.updatePageRoot(new DiagramPage(nodes[i]));
// Checks for invalid page names
if (page.getName() == null)
{
page.setName(mxResources.get('pageWithNumber', [i + 1]));