ui.diagram.contextmenu.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /**
  2. * DevExtreme (ui/diagram/ui.diagram.contextmenu.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. function _typeof(obj) {
  11. "@babel/helpers - typeof";
  12. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
  13. return typeof obj
  14. } : function(obj) {
  15. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
  16. }, _typeof(obj)
  17. }
  18. var _renderer = require("../../core/renderer");
  19. var _renderer2 = _interopRequireDefault(_renderer);
  20. var _ui = require("../widget/ui.widget");
  21. var _ui2 = _interopRequireDefault(_ui);
  22. var _context_menu = require("../context_menu");
  23. var _context_menu2 = _interopRequireDefault(_context_menu);
  24. var _uiDiagram = require("./ui.diagram.commands");
  25. var _uiDiagram2 = _interopRequireDefault(_uiDiagram);
  26. var _diagram_bar = require("./diagram_bar");
  27. var _diagram_bar2 = _interopRequireDefault(_diagram_bar);
  28. function _interopRequireDefault(obj) {
  29. return obj && obj.__esModule ? obj : {
  30. "default": obj
  31. }
  32. }
  33. function _classCallCheck(instance, Constructor) {
  34. if (!(instance instanceof Constructor)) {
  35. throw new TypeError("Cannot call a class as a function")
  36. }
  37. }
  38. function _defineProperties(target, props) {
  39. for (var i = 0; i < props.length; i++) {
  40. var descriptor = props[i];
  41. descriptor.enumerable = descriptor.enumerable || false;
  42. descriptor.configurable = true;
  43. if ("value" in descriptor) {
  44. descriptor.writable = true
  45. }
  46. Object.defineProperty(target, descriptor.key, descriptor)
  47. }
  48. }
  49. function _createClass(Constructor, protoProps, staticProps) {
  50. if (protoProps) {
  51. _defineProperties(Constructor.prototype, protoProps)
  52. }
  53. if (staticProps) {
  54. _defineProperties(Constructor, staticProps)
  55. }
  56. Object.defineProperty(Constructor, "prototype", {
  57. writable: false
  58. });
  59. return Constructor
  60. }
  61. function _get() {
  62. if ("undefined" !== typeof Reflect && Reflect.get) {
  63. _get = Reflect.get.bind()
  64. } else {
  65. _get = function(target, property, receiver) {
  66. var base = _superPropBase(target, property);
  67. if (!base) {
  68. return
  69. }
  70. var desc = Object.getOwnPropertyDescriptor(base, property);
  71. if (desc.get) {
  72. return desc.get.call(arguments.length < 3 ? target : receiver)
  73. }
  74. return desc.value
  75. }
  76. }
  77. return _get.apply(this, arguments)
  78. }
  79. function _superPropBase(object, property) {
  80. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  81. object = _getPrototypeOf(object);
  82. if (null === object) {
  83. break
  84. }
  85. }
  86. return object
  87. }
  88. function _inherits(subClass, superClass) {
  89. if ("function" !== typeof superClass && null !== superClass) {
  90. throw new TypeError("Super expression must either be null or a function")
  91. }
  92. subClass.prototype = Object.create(superClass && superClass.prototype, {
  93. constructor: {
  94. value: subClass,
  95. writable: true,
  96. configurable: true
  97. }
  98. });
  99. Object.defineProperty(subClass, "prototype", {
  100. writable: false
  101. });
  102. if (superClass) {
  103. _setPrototypeOf(subClass, superClass)
  104. }
  105. }
  106. function _setPrototypeOf(o, p) {
  107. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
  108. o.__proto__ = p;
  109. return o
  110. };
  111. return _setPrototypeOf(o, p)
  112. }
  113. function _createSuper(Derived) {
  114. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  115. return function() {
  116. var result, Super = _getPrototypeOf(Derived);
  117. if (hasNativeReflectConstruct) {
  118. var NewTarget = _getPrototypeOf(this).constructor;
  119. result = Reflect.construct(Super, arguments, NewTarget)
  120. } else {
  121. result = Super.apply(this, arguments)
  122. }
  123. return _possibleConstructorReturn(this, result)
  124. }
  125. }
  126. function _possibleConstructorReturn(self, call) {
  127. if (call && ("object" === _typeof(call) || "function" === typeof call)) {
  128. return call
  129. } else {
  130. if (void 0 !== call) {
  131. throw new TypeError("Derived constructors may only return object or undefined")
  132. }
  133. }
  134. return _assertThisInitialized(self)
  135. }
  136. function _assertThisInitialized(self) {
  137. if (void 0 === self) {
  138. throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
  139. }
  140. return self
  141. }
  142. function _isNativeReflectConstruct() {
  143. if ("undefined" === typeof Reflect || !Reflect.construct) {
  144. return false
  145. }
  146. if (Reflect.construct.sham) {
  147. return false
  148. }
  149. if ("function" === typeof Proxy) {
  150. return true
  151. }
  152. try {
  153. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
  154. return true
  155. } catch (e) {
  156. return false
  157. }
  158. }
  159. function _getPrototypeOf(o) {
  160. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
  161. return o.__proto__ || Object.getPrototypeOf(o)
  162. };
  163. return _getPrototypeOf(o)
  164. }
  165. var DiagramContextMenu = function(_Widget) {
  166. _inherits(DiagramContextMenu, _Widget);
  167. var _super = _createSuper(DiagramContextMenu);
  168. function DiagramContextMenu() {
  169. _classCallCheck(this, DiagramContextMenu);
  170. return _super.apply(this, arguments)
  171. }
  172. _createClass(DiagramContextMenu, [{
  173. key: "_init",
  174. value: function() {
  175. _get(_getPrototypeOf(DiagramContextMenu.prototype), "_init", this).call(this);
  176. this._createOnVisibleChangedAction();
  177. this.bar = new ContextMenuBar(this);
  178. this._tempState = void 0;
  179. this._commandToIndexMap = {}
  180. }
  181. }, {
  182. key: "_initMarkup",
  183. value: function() {
  184. var _this = this;
  185. _get(_getPrototypeOf(DiagramContextMenu.prototype), "_initMarkup", this).call(this);
  186. var items = _uiDiagram2.default.getContextMenu();
  187. var $contextMenu = (0, _renderer2.default)("<div>").appendTo(this.$element());
  188. this._contextMenuInstance = this._createComponent($contextMenu, _context_menu2.default, {
  189. target: this.option("container"),
  190. dataSource: items,
  191. displayExpr: "text",
  192. onItemClick: function(_ref) {
  193. var itemData = _ref.itemData;
  194. return _this._onItemClick(itemData.command)
  195. },
  196. onShowing: function(e) {
  197. _this._tempState = true;
  198. _this._onVisibleChangedAction({
  199. visible: true,
  200. component: _this
  201. });
  202. delete _this._tempState
  203. },
  204. onHiding: function(e) {
  205. _this._tempState = false;
  206. _this._onVisibleChangedAction({
  207. visible: false,
  208. component: _this
  209. });
  210. delete _this._tempState
  211. }
  212. });
  213. items.forEach(function(item, index) {
  214. return _this._commandToIndexMap[item.command] = index
  215. })
  216. }
  217. }, {
  218. key: "_onItemClick",
  219. value: function(command) {
  220. this.bar.raiseBarCommandExecuted(command);
  221. this._contextMenuInstance.hide()
  222. }
  223. }, {
  224. key: "_setItemEnabled",
  225. value: function(key, enabled) {
  226. if (key in this._commandToIndexMap) {
  227. this._contextMenuInstance.option("items[".concat(this._commandToIndexMap[key], "].disabled"), !enabled)
  228. }
  229. }
  230. }, {
  231. key: "_setEnabled",
  232. value: function(enabled) {
  233. this._contextMenuInstance.option("disabled", !enabled)
  234. }
  235. }, {
  236. key: "isVisible",
  237. value: function() {
  238. if (void 0 !== this._tempState) {
  239. return this._tempState
  240. }
  241. return !!this._contextMenuInstance.option("visible")
  242. }
  243. }, {
  244. key: "_createOnVisibleChangedAction",
  245. value: function() {
  246. this._onVisibleChangedAction = this._createActionByOption("onVisibleChanged")
  247. }
  248. }, {
  249. key: "_optionChanged",
  250. value: function(args) {
  251. switch (args.name) {
  252. case "onVisibleChanged":
  253. this._createOnVisibleChangedAction();
  254. break;
  255. default:
  256. _get(_getPrototypeOf(DiagramContextMenu.prototype), "_optionChanged", this).call(this, args)
  257. }
  258. }
  259. }]);
  260. return DiagramContextMenu
  261. }(_ui2.default);
  262. var ContextMenuBar = function(_DiagramBar) {
  263. _inherits(ContextMenuBar, _DiagramBar);
  264. var _super2 = _createSuper(ContextMenuBar);
  265. function ContextMenuBar() {
  266. _classCallCheck(this, ContextMenuBar);
  267. return _super2.apply(this, arguments)
  268. }
  269. _createClass(ContextMenuBar, [{
  270. key: "getCommandKeys",
  271. value: function() {
  272. return _uiDiagram2.default.getContextMenu().map(function(c) {
  273. return c.command
  274. })
  275. }
  276. }, {
  277. key: "setItemEnabled",
  278. value: function(key, enabled) {
  279. this._owner._setItemEnabled(key, enabled)
  280. }
  281. }, {
  282. key: "setEnabled",
  283. value: function(enabled) {
  284. this._owner._setEnabled(enabled)
  285. }
  286. }, {
  287. key: "isVisible",
  288. value: function() {
  289. return this._owner.isVisible()
  290. }
  291. }]);
  292. return ContextMenuBar
  293. }(_diagram_bar2.default);
  294. module.exports = DiagramContextMenu;