ui.submenu.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /**
  2. * DevExtreme (ui/menu/ui.submenu.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 _common = require("../../core/utils/common");
  21. var _dom = require("../../core/utils/dom");
  22. var _position = require("../../animation/position");
  23. var _extend = require("../../core/utils/extend");
  24. var _context_menu = require("../context_menu");
  25. var _context_menu2 = _interopRequireDefault(_context_menu);
  26. function _interopRequireDefault(obj) {
  27. return obj && obj.__esModule ? obj : {
  28. "default": obj
  29. }
  30. }
  31. function _classCallCheck(instance, Constructor) {
  32. if (!(instance instanceof Constructor)) {
  33. throw new TypeError("Cannot call a class as a function")
  34. }
  35. }
  36. function _defineProperties(target, props) {
  37. for (var i = 0; i < props.length; i++) {
  38. var descriptor = props[i];
  39. descriptor.enumerable = descriptor.enumerable || false;
  40. descriptor.configurable = true;
  41. if ("value" in descriptor) {
  42. descriptor.writable = true
  43. }
  44. Object.defineProperty(target, descriptor.key, descriptor)
  45. }
  46. }
  47. function _createClass(Constructor, protoProps, staticProps) {
  48. if (protoProps) {
  49. _defineProperties(Constructor.prototype, protoProps)
  50. }
  51. if (staticProps) {
  52. _defineProperties(Constructor, staticProps)
  53. }
  54. Object.defineProperty(Constructor, "prototype", {
  55. writable: false
  56. });
  57. return Constructor
  58. }
  59. function _get() {
  60. if ("undefined" !== typeof Reflect && Reflect.get) {
  61. _get = Reflect.get.bind()
  62. } else {
  63. _get = function(target, property, receiver) {
  64. var base = _superPropBase(target, property);
  65. if (!base) {
  66. return
  67. }
  68. var desc = Object.getOwnPropertyDescriptor(base, property);
  69. if (desc.get) {
  70. return desc.get.call(arguments.length < 3 ? target : receiver)
  71. }
  72. return desc.value
  73. }
  74. }
  75. return _get.apply(this, arguments)
  76. }
  77. function _superPropBase(object, property) {
  78. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  79. object = _getPrototypeOf(object);
  80. if (null === object) {
  81. break
  82. }
  83. }
  84. return object
  85. }
  86. function _inherits(subClass, superClass) {
  87. if ("function" !== typeof superClass && null !== superClass) {
  88. throw new TypeError("Super expression must either be null or a function")
  89. }
  90. subClass.prototype = Object.create(superClass && superClass.prototype, {
  91. constructor: {
  92. value: subClass,
  93. writable: true,
  94. configurable: true
  95. }
  96. });
  97. Object.defineProperty(subClass, "prototype", {
  98. writable: false
  99. });
  100. if (superClass) {
  101. _setPrototypeOf(subClass, superClass)
  102. }
  103. }
  104. function _setPrototypeOf(o, p) {
  105. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
  106. o.__proto__ = p;
  107. return o
  108. };
  109. return _setPrototypeOf(o, p)
  110. }
  111. function _createSuper(Derived) {
  112. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  113. return function() {
  114. var result, Super = _getPrototypeOf(Derived);
  115. if (hasNativeReflectConstruct) {
  116. var NewTarget = _getPrototypeOf(this).constructor;
  117. result = Reflect.construct(Super, arguments, NewTarget)
  118. } else {
  119. result = Super.apply(this, arguments)
  120. }
  121. return _possibleConstructorReturn(this, result)
  122. }
  123. }
  124. function _possibleConstructorReturn(self, call) {
  125. if (call && ("object" === _typeof(call) || "function" === typeof call)) {
  126. return call
  127. } else {
  128. if (void 0 !== call) {
  129. throw new TypeError("Derived constructors may only return object or undefined")
  130. }
  131. }
  132. return _assertThisInitialized(self)
  133. }
  134. function _assertThisInitialized(self) {
  135. if (void 0 === self) {
  136. throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
  137. }
  138. return self
  139. }
  140. function _isNativeReflectConstruct() {
  141. if ("undefined" === typeof Reflect || !Reflect.construct) {
  142. return false
  143. }
  144. if (Reflect.construct.sham) {
  145. return false
  146. }
  147. if ("function" === typeof Proxy) {
  148. return true
  149. }
  150. try {
  151. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
  152. return true
  153. } catch (e) {
  154. return false
  155. }
  156. }
  157. function _getPrototypeOf(o) {
  158. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
  159. return o.__proto__ || Object.getPrototypeOf(o)
  160. };
  161. return _getPrototypeOf(o)
  162. }
  163. var DX_CONTEXT_MENU_CONTENT_DELIMITER_CLASS = "dx-context-menu-content-delimiter";
  164. var DX_SUBMENU_CLASS = "dx-submenu";
  165. var Submenu = function(_ContextMenu) {
  166. _inherits(Submenu, _ContextMenu);
  167. var _super = _createSuper(Submenu);
  168. function Submenu() {
  169. _classCallCheck(this, Submenu);
  170. return _super.apply(this, arguments)
  171. }
  172. _createClass(Submenu, [{
  173. key: "_getDefaultOptions",
  174. value: function() {
  175. return (0, _extend.extend)(_get(_getPrototypeOf(Submenu.prototype), "_getDefaultOptions", this).call(this), {
  176. orientation: "horizontal",
  177. tabIndex: null,
  178. onHoverStart: _common.noop
  179. })
  180. }
  181. }, {
  182. key: "_initDataAdapter",
  183. value: function() {
  184. this._dataAdapter = this.option("_dataAdapter");
  185. if (!this._dataAdapter) {
  186. _get(_getPrototypeOf(Submenu.prototype), "_initDataAdapter", this).call(this)
  187. }
  188. }
  189. }, {
  190. key: "_renderContentImpl",
  191. value: function() {
  192. this._renderContextMenuOverlay();
  193. _get(_getPrototypeOf(Submenu.prototype), "_renderContentImpl", this).call(this);
  194. var node = this._dataAdapter.getNodeByKey(this.option("_parentKey"));
  195. node && this._renderItems(this._getChildNodes(node));
  196. this._renderDelimiter()
  197. }
  198. }, {
  199. key: "_renderDelimiter",
  200. value: function() {
  201. this.$contentDelimiter = (0, _renderer2.default)("<div>").appendTo(this._itemContainer()).addClass(DX_CONTEXT_MENU_CONTENT_DELIMITER_CLASS)
  202. }
  203. }, {
  204. key: "_getOverlayOptions",
  205. value: function() {
  206. return (0, _extend.extend)(_get(_getPrototypeOf(Submenu.prototype), "_getOverlayOptions", this).call(this), {
  207. onPositioned: this._overlayPositionedActionHandler.bind(this)
  208. })
  209. }
  210. }, {
  211. key: "_overlayPositionedActionHandler",
  212. value: function(arg) {
  213. this._showDelimiter(arg)
  214. }
  215. }, {
  216. key: "_hoverEndHandler",
  217. value: function(e) {
  218. _get(_getPrototypeOf(Submenu.prototype), "_hoverEndHandler", this).call(this, e);
  219. this._toggleFocusClass(false, e.currentTarget)
  220. }
  221. }, {
  222. key: "_isMenuHorizontal",
  223. value: function() {
  224. return "horizontal" === this.option("orientation")
  225. }
  226. }, {
  227. key: "_hoverStartHandler",
  228. value: function(e) {
  229. var hoverStartAction = this.option("onHoverStart");
  230. hoverStartAction(e);
  231. _get(_getPrototypeOf(Submenu.prototype), "_hoverStartHandler", this).call(this, e);
  232. this._toggleFocusClass(true, e.currentTarget)
  233. }
  234. }, {
  235. key: "_drawSubmenu",
  236. value: function($rootItem) {
  237. this._actions.onShowing({
  238. rootItem: (0, _dom.getPublicElement)($rootItem),
  239. submenu: this
  240. });
  241. _get(_getPrototypeOf(Submenu.prototype), "_drawSubmenu", this).call(this, $rootItem);
  242. this._actions.onShown({
  243. rootItem: (0, _dom.getPublicElement)($rootItem),
  244. submenu: this
  245. })
  246. }
  247. }, {
  248. key: "_hideSubmenu",
  249. value: function($rootItem) {
  250. this._actions.onHiding({
  251. cancel: true,
  252. rootItem: (0, _dom.getPublicElement)($rootItem),
  253. submenu: this
  254. });
  255. _get(_getPrototypeOf(Submenu.prototype), "_hideSubmenu", this).call(this, $rootItem);
  256. this._actions.onHidden({
  257. rootItem: (0, _dom.getPublicElement)($rootItem),
  258. submenu: this
  259. })
  260. }
  261. }, {
  262. key: "_showDelimiter",
  263. value: function(arg) {
  264. if (!this.$contentDelimiter) {
  265. return
  266. }
  267. var $submenu = this._itemContainer().children(".".concat(DX_SUBMENU_CLASS)).eq(0);
  268. var $rootItem = this.option("position").of;
  269. var position = {
  270. of: $submenu
  271. };
  272. var containerOffset = arg.position;
  273. var vLocation = containerOffset.v.location;
  274. var hLocation = containerOffset.h.location;
  275. var rootOffset = $rootItem.offset();
  276. var offsetLeft = Math.round(rootOffset.left);
  277. var offsetTop = Math.round(rootOffset.top);
  278. var rootWidth = $rootItem.width();
  279. var rootHeight = $rootItem.height();
  280. var submenuWidth = $submenu.width();
  281. var submenuHeight = $submenu.height();
  282. this.$contentDelimiter.css("display", "block");
  283. this.$contentDelimiter.width(this._isMenuHorizontal() ? rootWidth < submenuWidth ? rootWidth - 2 : submenuWidth : 2);
  284. this.$contentDelimiter.height(this._isMenuHorizontal() ? 2 : rootHeight < submenuHeight ? rootHeight - 2 : submenuHeight);
  285. if (this._isMenuHorizontal()) {
  286. if (vLocation > offsetTop) {
  287. if (Math.round(hLocation) === offsetLeft) {
  288. position.offset = "1 -1";
  289. position.at = position.my = "left top"
  290. } else {
  291. position.offset = "-1 -1";
  292. position.at = position.my = "right top"
  293. }
  294. } else {
  295. this.$contentDelimiter.height(5);
  296. if (Math.round(hLocation) === offsetLeft) {
  297. position.offset = "1 4";
  298. position.at = position.my = "left bottom"
  299. } else {
  300. position.offset = "-1 2";
  301. position.at = position.my = "right bottom"
  302. }
  303. }
  304. } else {
  305. if (hLocation > offsetLeft) {
  306. if (Math.round(vLocation) === offsetTop) {
  307. position.offset = "-1 1";
  308. position.at = position.my = "left top"
  309. } else {
  310. position.offset = "-1 -1";
  311. position.at = position.my = "left bottom"
  312. }
  313. } else {
  314. if (Math.round(vLocation) === offsetTop) {
  315. position.offset = "1 1";
  316. position.at = position.my = "right top"
  317. } else {
  318. position.offset = "1 -1";
  319. position.at = position.my = "right bottom"
  320. }
  321. }
  322. }(0, _position.setup)(this.$contentDelimiter, position)
  323. }
  324. }, {
  325. key: "_getContextMenuPosition",
  326. value: function() {
  327. return this.option("position")
  328. }
  329. }, {
  330. key: "isOverlayVisible",
  331. value: function() {
  332. return this._overlay.option("visible")
  333. }
  334. }, {
  335. key: "getOverlayContent",
  336. value: function() {
  337. return this._overlay.$content()
  338. }
  339. }]);
  340. return Submenu
  341. }(_context_menu2.default);
  342. module.exports = Submenu;