ui.file_manager.adaptivity.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /**
  2. * DevExtreme (ui/file_manager/ui.file_manager.adaptivity.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 _window = require("../../core/utils/window");
  23. var _ui = require("../widget/ui.widget");
  24. var _ui2 = _interopRequireDefault(_ui);
  25. var _ui3 = require("../drawer/ui.drawer");
  26. var _ui4 = _interopRequireDefault(_ui3);
  27. function _interopRequireDefault(obj) {
  28. return obj && obj.__esModule ? obj : {
  29. "default": obj
  30. }
  31. }
  32. function _classCallCheck(instance, Constructor) {
  33. if (!(instance instanceof Constructor)) {
  34. throw new TypeError("Cannot call a class as a function")
  35. }
  36. }
  37. function _defineProperties(target, props) {
  38. for (var i = 0; i < props.length; i++) {
  39. var descriptor = props[i];
  40. descriptor.enumerable = descriptor.enumerable || false;
  41. descriptor.configurable = true;
  42. if ("value" in descriptor) {
  43. descriptor.writable = true
  44. }
  45. Object.defineProperty(target, descriptor.key, descriptor)
  46. }
  47. }
  48. function _createClass(Constructor, protoProps, staticProps) {
  49. if (protoProps) {
  50. _defineProperties(Constructor.prototype, protoProps)
  51. }
  52. if (staticProps) {
  53. _defineProperties(Constructor, staticProps)
  54. }
  55. Object.defineProperty(Constructor, "prototype", {
  56. writable: false
  57. });
  58. return Constructor
  59. }
  60. function _get() {
  61. if ("undefined" !== typeof Reflect && Reflect.get) {
  62. _get = Reflect.get.bind()
  63. } else {
  64. _get = function(target, property, receiver) {
  65. var base = _superPropBase(target, property);
  66. if (!base) {
  67. return
  68. }
  69. var desc = Object.getOwnPropertyDescriptor(base, property);
  70. if (desc.get) {
  71. return desc.get.call(arguments.length < 3 ? target : receiver)
  72. }
  73. return desc.value
  74. }
  75. }
  76. return _get.apply(this, arguments)
  77. }
  78. function _superPropBase(object, property) {
  79. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  80. object = _getPrototypeOf(object);
  81. if (null === object) {
  82. break
  83. }
  84. }
  85. return object
  86. }
  87. function _inherits(subClass, superClass) {
  88. if ("function" !== typeof superClass && null !== superClass) {
  89. throw new TypeError("Super expression must either be null or a function")
  90. }
  91. subClass.prototype = Object.create(superClass && superClass.prototype, {
  92. constructor: {
  93. value: subClass,
  94. writable: true,
  95. configurable: true
  96. }
  97. });
  98. Object.defineProperty(subClass, "prototype", {
  99. writable: false
  100. });
  101. if (superClass) {
  102. _setPrototypeOf(subClass, superClass)
  103. }
  104. }
  105. function _setPrototypeOf(o, p) {
  106. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
  107. o.__proto__ = p;
  108. return o
  109. };
  110. return _setPrototypeOf(o, p)
  111. }
  112. function _createSuper(Derived) {
  113. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  114. return function() {
  115. var result, Super = _getPrototypeOf(Derived);
  116. if (hasNativeReflectConstruct) {
  117. var NewTarget = _getPrototypeOf(this).constructor;
  118. result = Reflect.construct(Super, arguments, NewTarget)
  119. } else {
  120. result = Super.apply(this, arguments)
  121. }
  122. return _possibleConstructorReturn(this, result)
  123. }
  124. }
  125. function _possibleConstructorReturn(self, call) {
  126. if (call && ("object" === _typeof(call) || "function" === typeof call)) {
  127. return call
  128. } else {
  129. if (void 0 !== call) {
  130. throw new TypeError("Derived constructors may only return object or undefined")
  131. }
  132. }
  133. return _assertThisInitialized(self)
  134. }
  135. function _assertThisInitialized(self) {
  136. if (void 0 === self) {
  137. throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
  138. }
  139. return self
  140. }
  141. function _isNativeReflectConstruct() {
  142. if ("undefined" === typeof Reflect || !Reflect.construct) {
  143. return false
  144. }
  145. if (Reflect.construct.sham) {
  146. return false
  147. }
  148. if ("function" === typeof Proxy) {
  149. return true
  150. }
  151. try {
  152. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
  153. return true
  154. } catch (e) {
  155. return false
  156. }
  157. }
  158. function _getPrototypeOf(o) {
  159. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
  160. return o.__proto__ || Object.getPrototypeOf(o)
  161. };
  162. return _getPrototypeOf(o)
  163. }
  164. var window = (0, _window.getWindow)();
  165. var ADAPTIVE_STATE_SCREEN_WIDTH = 573;
  166. var FileManagerAdaptivityControl = function(_Widget) {
  167. _inherits(FileManagerAdaptivityControl, _Widget);
  168. var _super = _createSuper(FileManagerAdaptivityControl);
  169. function FileManagerAdaptivityControl() {
  170. _classCallCheck(this, FileManagerAdaptivityControl);
  171. return _super.apply(this, arguments)
  172. }
  173. _createClass(FileManagerAdaptivityControl, [{
  174. key: "_initMarkup",
  175. value: function() {
  176. _get(_getPrototypeOf(FileManagerAdaptivityControl.prototype), "_initMarkup", this).call(this);
  177. this._initActions();
  178. this._isInAdaptiveState = false;
  179. var $drawer = (0, _renderer2.default)("<div>").appendTo(this.$element());
  180. var contentRenderer = this.option("contentTemplate");
  181. if ((0, _type.isFunction)(contentRenderer)) {
  182. contentRenderer($drawer)
  183. }
  184. this._drawer = this._createComponent($drawer, _ui4.default, {
  185. opened: true,
  186. template: this.option("drawerTemplate")
  187. })
  188. }
  189. }, {
  190. key: "_render",
  191. value: function() {
  192. _get(_getPrototypeOf(FileManagerAdaptivityControl.prototype), "_render", this).call(this);
  193. this._checkAdaptiveState()
  194. }
  195. }, {
  196. key: "_dimensionChanged",
  197. value: function(dimension) {
  198. if (!dimension || "height" !== dimension) {
  199. this._checkAdaptiveState()
  200. }
  201. }
  202. }, {
  203. key: "_checkAdaptiveState",
  204. value: function() {
  205. var oldState = this._isInAdaptiveState;
  206. this._isInAdaptiveState = this._isSmallScreen();
  207. if (oldState !== this._isInAdaptiveState) {
  208. this.toggleDrawer(!this._isInAdaptiveState, true);
  209. this._raiseAdaptiveStateChanged(this._isInAdaptiveState)
  210. }
  211. }
  212. }, {
  213. key: "_isSmallScreen",
  214. value: function() {
  215. return (0, _renderer2.default)(window).width() <= ADAPTIVE_STATE_SCREEN_WIDTH
  216. }
  217. }, {
  218. key: "_initActions",
  219. value: function() {
  220. this._actions = {
  221. onAdaptiveStateChanged: this._createActionByOption("onAdaptiveStateChanged")
  222. }
  223. }
  224. }, {
  225. key: "_raiseAdaptiveStateChanged",
  226. value: function(enabled) {
  227. this._actions.onAdaptiveStateChanged({
  228. enabled: enabled
  229. })
  230. }
  231. }, {
  232. key: "_getDefaultOptions",
  233. value: function() {
  234. return (0, _extend.extend)(_get(_getPrototypeOf(FileManagerAdaptivityControl.prototype), "_getDefaultOptions", this).call(this), {
  235. drawerTemplate: null,
  236. contentTemplate: null,
  237. onAdaptiveStateChanged: null
  238. })
  239. }
  240. }, {
  241. key: "_optionChanged",
  242. value: function(args) {
  243. var name = args.name;
  244. switch (name) {
  245. case "drawerTemplate":
  246. case "contentTemplate":
  247. this.repaint();
  248. break;
  249. case "onAdaptiveStateChanged":
  250. this._actions[name] = this._createActionByOption(name);
  251. break;
  252. default:
  253. _get(_getPrototypeOf(FileManagerAdaptivityControl.prototype), "_optionChanged", this).call(this, args)
  254. }
  255. }
  256. }, {
  257. key: "isInAdaptiveState",
  258. value: function() {
  259. return this._isInAdaptiveState
  260. }
  261. }, {
  262. key: "toggleDrawer",
  263. value: function(showing, skipAnimation) {
  264. this._drawer.option("animationEnabled", !skipAnimation);
  265. this._drawer.toggle(showing)
  266. }
  267. }]);
  268. return FileManagerAdaptivityControl
  269. }(_ui2.default);
  270. module.exports = FileManagerAdaptivityControl;