ui.file_manager.context_menu.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /**
  2. * DevExtreme (ui/file_manager/ui.file_manager.context_menu.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 _extend = require("../../core/utils/extend");
  21. var _type = require("../../core/utils/type");
  22. var _ui = require("../widget/ui.widget");
  23. var _ui2 = _interopRequireDefault(_ui);
  24. var _ui3 = require("../context_menu/ui.context_menu");
  25. var _ui4 = _interopRequireDefault(_ui3);
  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 FILEMANAGER_CONTEXT_MEMU_CLASS = "dx-filemanager-context-menu";
  164. var DEFAULT_CONTEXT_MENU_ITEMS = ["create", "upload", "rename", "move", "copy", "delete", {
  165. commandName: "refresh",
  166. beginGroup: true
  167. }];
  168. var FileManagerContextMenu = function(_Widget) {
  169. _inherits(FileManagerContextMenu, _Widget);
  170. var _super = _createSuper(FileManagerContextMenu);
  171. function FileManagerContextMenu() {
  172. _classCallCheck(this, FileManagerContextMenu);
  173. return _super.apply(this, arguments)
  174. }
  175. _createClass(FileManagerContextMenu, [{
  176. key: "_initMarkup",
  177. value: function() {
  178. var _this = this;
  179. this._createContextMenuHiddenAction();
  180. this._isVisible = false;
  181. var $menu = (0, _renderer2.default)("<div>").appendTo(this.$element());
  182. this._contextMenu = this._createComponent($menu, _ui4.default, {
  183. cssClass: FILEMANAGER_CONTEXT_MEMU_CLASS,
  184. showEvent: "",
  185. onItemClick: function(_ref) {
  186. var commandName = _ref.itemData.commandName;
  187. return _this._onContextMenuItemClick(commandName)
  188. },
  189. onHidden: function() {
  190. return _this._onContextMenuHidden()
  191. }
  192. });
  193. _get(_getPrototypeOf(FileManagerContextMenu.prototype), "_initMarkup", this).call(this)
  194. }
  195. }, {
  196. key: "showAt",
  197. value: function(fileItems, element, offset) {
  198. if (this._isVisible) {
  199. this._raiseContextMenuHidden()
  200. }
  201. this._isVisible = true;
  202. var items = this.createContextMenuItems(fileItems);
  203. var position = {
  204. of: element,
  205. at: "top left",
  206. my: "top left",
  207. offset: ""
  208. };
  209. if (offset) {
  210. position.offset = offset.offsetX + " " + offset.offsetY
  211. } else {
  212. position.my = "left top";
  213. position.at = "left bottom"
  214. }
  215. this._contextMenu.option({
  216. dataSource: items,
  217. target: element,
  218. position: position
  219. });
  220. this._contextMenu.show()
  221. }
  222. }, {
  223. key: "createContextMenuItems",
  224. value: function(fileItems) {
  225. var _this2 = this;
  226. this._targetFileItems = fileItems;
  227. var result = [];
  228. DEFAULT_CONTEXT_MENU_ITEMS.forEach(function(srcItem) {
  229. var commandName = (0, _type.isString)(srcItem) ? srcItem : srcItem.commandName;
  230. if (_this2._commandManager.isCommandAvailable(commandName, fileItems)) {
  231. var item = _this2._createMenuItemByCommandName(commandName);
  232. if ((0, _type.isObject)(srcItem)) {
  233. item = (0, _extend.extend)(true, item, srcItem)
  234. }
  235. result.push(item)
  236. }
  237. });
  238. return result
  239. }
  240. }, {
  241. key: "_createMenuItemByCommandName",
  242. value: function(commandName) {
  243. var _this3 = this;
  244. var _this$_commandManager = this._commandManager.getCommandByName(commandName),
  245. text = _this$_commandManager.text,
  246. icon = _this$_commandManager.icon;
  247. return {
  248. commandName: commandName,
  249. text: text,
  250. icon: icon,
  251. onItemClick: function() {
  252. return _this3._onContextMenuItemClick(commandName)
  253. }
  254. }
  255. }
  256. }, {
  257. key: "_onContextMenuItemClick",
  258. value: function(commandName) {
  259. this._commandManager.executeCommand(commandName, this._targetFileItems)
  260. }
  261. }, {
  262. key: "_createContextMenuHiddenAction",
  263. value: function() {
  264. this._contextMenuHiddenAction = this._createActionByOption("onContextMenuHidden")
  265. }
  266. }, {
  267. key: "_onContextMenuHidden",
  268. value: function() {
  269. this._isVisible = false;
  270. this._raiseContextMenuHidden()
  271. }
  272. }, {
  273. key: "_raiseContextMenuHidden",
  274. value: function() {
  275. this._contextMenuHiddenAction()
  276. }
  277. }, {
  278. key: "_getDefaultOptions",
  279. value: function() {
  280. return (0, _extend.extend)(_get(_getPrototypeOf(FileManagerContextMenu.prototype), "_getDefaultOptions", this).call(this), {
  281. commandManager: null,
  282. onContextMenuHidden: null
  283. })
  284. }
  285. }, {
  286. key: "_optionChanged",
  287. value: function(args) {
  288. var name = args.name;
  289. switch (name) {
  290. case "commandManager":
  291. this.repaint();
  292. break;
  293. case "onContextMenuHidden":
  294. this._createContextMenuHiddenAction();
  295. break;
  296. default:
  297. _get(_getPrototypeOf(FileManagerContextMenu.prototype), "_optionChanged", this).call(this, args)
  298. }
  299. }
  300. }, {
  301. key: "_commandManager",
  302. get: function() {
  303. return this.option("commandManager")
  304. }
  305. }]);
  306. return FileManagerContextMenu
  307. }(_ui2.default);
  308. module.exports = FileManagerContextMenu;