ui.diagram.commands.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /**
  2. * DevExtreme (ui/diagram/ui.diagram.commands.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var _diagram_importer = require("./diagram_importer");
  11. var _file_saver = require("../../exporter/file_saver");
  12. var _type = require("../../core/utils/type");
  13. var _window = require("../../core/utils/window");
  14. var SEPARATOR = {
  15. widget: "separator"
  16. };
  17. var CSS_CLASSES = {
  18. SMALL_SELECT: "dx-diagram-select-sm",
  19. BUTTON_SELECT: "dx-diagram-select-b",
  20. BUTTON_COLOR: "dx-diagram-color-b"
  21. };
  22. var DiagramCommands = {
  23. getToolbar: function() {
  24. var _this = this;
  25. var _getDiagram = (0, _diagram_importer.getDiagram)(),
  26. DiagramCommand = _getDiagram.DiagramCommand;
  27. return [{
  28. command: DiagramCommand.Undo,
  29. hint: "Undo",
  30. icon: "undo",
  31. text: "Undo"
  32. }, {
  33. command: DiagramCommand.Redo,
  34. hint: "Redo",
  35. icon: "redo",
  36. text: "Redo"
  37. }, SEPARATOR, {
  38. command: DiagramCommand.FontName,
  39. beginGroup: true,
  40. widget: "dxSelectBox",
  41. items: ["Arial", "Arial Black", "Helvetica", "Times New Roman", "Courier New", "Courier", "Verdana", "Georgia", "Comic Sans MS", "Trebuchet MS"]
  42. }, {
  43. command: DiagramCommand.FontSize,
  44. widget: "dxSelectBox",
  45. items: ["8pt", "9pt", "10pt", "11pt", "12pt", "14pt", "16pt", "18pt", "20pt", "22pt", "24pt", "26pt", "28pt", "36pt", "48pt", "72pt"],
  46. cssClass: CSS_CLASSES.SMALL_SELECT
  47. }, SEPARATOR, {
  48. command: DiagramCommand.Bold,
  49. hint: "Bold",
  50. text: "Bold",
  51. icon: "bold"
  52. }, {
  53. command: DiagramCommand.Italic,
  54. hint: "Italic",
  55. text: "Italic",
  56. icon: "italic"
  57. }, {
  58. command: DiagramCommand.Underline,
  59. hint: "Underline",
  60. text: "Underline",
  61. icon: "underline"
  62. }, SEPARATOR, {
  63. command: DiagramCommand.FontColor,
  64. text: "Text Color",
  65. widget: "dxColorBox",
  66. icon: "dx-icon dx-icon-color",
  67. cssClass: CSS_CLASSES.BUTTON_COLOR
  68. }, {
  69. command: DiagramCommand.StrokeColor,
  70. text: "Line Color",
  71. widget: "dxColorBox",
  72. icon: "dx-icon dx-icon-background",
  73. cssClass: CSS_CLASSES.BUTTON_COLOR
  74. }, {
  75. command: DiagramCommand.FillColor,
  76. text: "Fill Color",
  77. widget: "dxColorBox",
  78. icon: "dx-diagram-i dx-diagram-i-button-fill",
  79. cssClass: CSS_CLASSES.BUTTON_COLOR
  80. }, SEPARATOR, {
  81. command: DiagramCommand.TextLeftAlign,
  82. hint: "Align Left",
  83. text: "Align Left",
  84. icon: "alignleft",
  85. beginGroup: true
  86. }, {
  87. command: DiagramCommand.TextCenterAlign,
  88. hint: "Align Center",
  89. text: "Center",
  90. icon: "aligncenter"
  91. }, {
  92. command: DiagramCommand.TextRightAlign,
  93. hint: "Align Right",
  94. text: "Align Right",
  95. icon: "alignright"
  96. }, SEPARATOR, {
  97. command: DiagramCommand.ConnectorLineOption,
  98. widget: "dxSelectBox",
  99. hint: "Line Type",
  100. items: [{
  101. value: 0,
  102. icon: "dx-diagram-i-connector-straight dx-diagram-i",
  103. hint: "Straight"
  104. }, {
  105. value: 1,
  106. icon: "dx-diagram-i-connector-orthogonal dx-diagram-i",
  107. hint: "Orthogonal"
  108. }],
  109. displayExpr: "name",
  110. valueExpr: "value",
  111. cssClass: CSS_CLASSES.BUTTON_SELECT
  112. }, {
  113. command: DiagramCommand.ConnectorStartLineEnding,
  114. widget: "dxSelectBox",
  115. items: [{
  116. value: 0,
  117. icon: "dx-diagram-i-connector-begin-none dx-diagram-i",
  118. hint: "None"
  119. }, {
  120. value: 1,
  121. icon: "dx-diagram-i-connector-begin-arrow dx-diagram-i",
  122. hint: "Arrow"
  123. }],
  124. displayExpr: "name",
  125. valueExpr: "value",
  126. hint: "Line Start",
  127. cssClass: CSS_CLASSES.BUTTON_SELECT
  128. }, {
  129. command: DiagramCommand.ConnectorEndLineEnding,
  130. widget: "dxSelectBox",
  131. items: [{
  132. value: 0,
  133. icon: "dx-diagram-i-connector-end-none dx-diagram-i",
  134. hint: "None"
  135. }, {
  136. value: 1,
  137. icon: "dx-diagram-i-connector-end-arrow dx-diagram-i",
  138. hint: "Arrow"
  139. }],
  140. displayExpr: "name",
  141. valueExpr: "value",
  142. hint: "Line End",
  143. cssClass: CSS_CLASSES.BUTTON_SELECT
  144. }, SEPARATOR, {
  145. widget: "dxButton",
  146. icon: "export",
  147. text: "Export",
  148. items: [{
  149. command: DiagramCommand.ExportSvg,
  150. text: "Export to SVG",
  151. getParameter: function(widget) {
  152. return function(dataURI) {
  153. return _this._exportTo(widget, dataURI, "SVG", "image/svg+xml")
  154. }
  155. }
  156. }, {
  157. command: DiagramCommand.ExportPng,
  158. text: "Export to PNG",
  159. getParameter: function(widget) {
  160. return function(dataURI) {
  161. return _this._exportTo(widget, dataURI, "PNG", "image/png")
  162. }
  163. }
  164. }, {
  165. command: DiagramCommand.ExportJpg,
  166. text: "Export to JPEG",
  167. getParameter: function(widget) {
  168. return function(dataURI) {
  169. return _this._exportTo(widget, dataURI, "JPEG", "image/jpeg")
  170. }
  171. }
  172. }]
  173. }, {
  174. widget: "dxButton",
  175. text: "Auto Layout",
  176. showText: "always",
  177. items: [{
  178. text: "Tree",
  179. items: [{
  180. command: DiagramCommand.AutoLayoutTreeVertical,
  181. text: "Vertical"
  182. }, {
  183. command: DiagramCommand.AutoLayoutTreeHorizontal,
  184. text: "Horizontal"
  185. }]
  186. }, {
  187. text: "Layered",
  188. items: [{
  189. command: DiagramCommand.AutoLayoutLayeredVertical,
  190. text: "Vertical"
  191. }, {
  192. command: DiagramCommand.AutoLayoutLayeredHorizontal,
  193. text: "Horizontal"
  194. }]
  195. }]
  196. }, {
  197. command: DiagramCommand.Fullscreen,
  198. hint: "Fullscreen",
  199. text: "Fullscreen",
  200. icon: "dx-diagram-i dx-diagram-i-button-fullscreen",
  201. cssClass: CSS_CLASSES.BUTTON_COLOR
  202. }]
  203. },
  204. getOptions: function() {
  205. var _getDiagram2 = (0, _diagram_importer.getDiagram)(),
  206. DiagramCommand = _getDiagram2.DiagramCommand;
  207. return [{
  208. command: DiagramCommand.Units,
  209. text: "Units",
  210. widget: "dxSelectBox"
  211. }, {
  212. command: DiagramCommand.PageSize,
  213. text: "Page Size",
  214. widget: "dxSelectBox",
  215. getValue: function(v) {
  216. return JSON.parse(v)
  217. },
  218. setValue: function(v) {
  219. return JSON.stringify(v)
  220. }
  221. }, {
  222. command: DiagramCommand.PageLandscape,
  223. text: "Page Landscape",
  224. widget: "dxCheckBox"
  225. }, {
  226. command: DiagramCommand.PageColor,
  227. text: "Page Color",
  228. widget: "dxColorBox",
  229. beginGroup: true
  230. }, {
  231. command: DiagramCommand.ShowGrid,
  232. text: "Show Grid",
  233. widget: "dxCheckBox",
  234. beginGroup: true
  235. }, {
  236. command: DiagramCommand.SnapToGrid,
  237. text: "Snap to Grid",
  238. widget: "dxCheckBox"
  239. }, {
  240. command: DiagramCommand.GridSize,
  241. text: "Grid Size",
  242. widget: "dxSelectBox"
  243. }, {
  244. command: DiagramCommand.ZoomLevel,
  245. text: "Zoom Level",
  246. widget: "dxSelectBox",
  247. beginGroup: true
  248. }]
  249. },
  250. getContextMenu: function() {
  251. var _getDiagram3 = (0, _diagram_importer.getDiagram)(),
  252. DiagramCommand = _getDiagram3.DiagramCommand;
  253. return [{
  254. command: DiagramCommand.Cut,
  255. text: "Cut"
  256. }, {
  257. command: DiagramCommand.Copy,
  258. text: "Copy"
  259. }, {
  260. command: DiagramCommand.Paste,
  261. text: "Paste"
  262. }, {
  263. command: DiagramCommand.SelectAll,
  264. text: "Select All",
  265. beginGroup: true
  266. }, {
  267. command: DiagramCommand.Delete,
  268. text: "Delete",
  269. beginGroup: true
  270. }, {
  271. command: DiagramCommand.BringToFront,
  272. text: "Bring to Front",
  273. beginGroup: true
  274. }, {
  275. command: DiagramCommand.SendToBack,
  276. text: "Send to Back"
  277. }, {
  278. command: DiagramCommand.Lock,
  279. text: "Lock",
  280. beginGroup: true
  281. }, {
  282. command: DiagramCommand.Unlock,
  283. text: "Unlock"
  284. }]
  285. },
  286. _exportTo: function(widget, dataURI, format, mimeString) {
  287. var window = (0, _window.getWindow)();
  288. if (window && window.atob && (0, _type.isFunction)(window.Blob)) {
  289. var blob = this._getBlobByDataURI(window, dataURI, mimeString);
  290. var options = widget.option("export");
  291. _file_saver.fileSaver.saveAs(options.fileName || "foo", format, blob, options.proxyURL)
  292. }
  293. },
  294. _getBlobByDataURI: function(window, dataURI, mimeString) {
  295. var byteString = window.atob(dataURI.split(",")[1]);
  296. var arrayBuffer = new ArrayBuffer(byteString.length);
  297. var ia = new Uint8Array(arrayBuffer);
  298. for (var i = 0; i < byteString.length; i++) {
  299. ia[i] = byteString.charCodeAt(i)
  300. }
  301. var dataView = new DataView(arrayBuffer);
  302. return new window.Blob([dataView], {
  303. type: mimeString
  304. })
  305. }
  306. };
  307. module.exports = DiagramCommands;