Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VDialog.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  6. require('../../../src/stylus/components/_dialogs.styl');
  7. var _dependent = require('../../mixins/dependent');
  8. var _dependent2 = _interopRequireDefault(_dependent);
  9. var _detachable = require('../../mixins/detachable');
  10. var _detachable2 = _interopRequireDefault(_detachable);
  11. var _overlayable = require('../../mixins/overlayable');
  12. var _overlayable2 = _interopRequireDefault(_overlayable);
  13. var _returnable = require('../../mixins/returnable');
  14. var _returnable2 = _interopRequireDefault(_returnable);
  15. var _stackable = require('../../mixins/stackable');
  16. var _stackable2 = _interopRequireDefault(_stackable);
  17. var _toggleable = require('../../mixins/toggleable');
  18. var _toggleable2 = _interopRequireDefault(_toggleable);
  19. var _clickOutside = require('../../directives/click-outside');
  20. var _clickOutside2 = _interopRequireDefault(_clickOutside);
  21. var _helpers = require('../../util/helpers');
  22. var _ThemeProvider = require('../../util/ThemeProvider');
  23. var _ThemeProvider2 = _interopRequireDefault(_ThemeProvider);
  24. var _console = require('../../util/console');
  25. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  27. // Mixins
  28. // Directives
  29. // Helpers
  30. /* @vue/component */
  31. exports.default = {
  32. name: 'v-dialog',
  33. directives: {
  34. ClickOutside: _clickOutside2.default
  35. },
  36. mixins: [_dependent2.default, _detachable2.default, _overlayable2.default, _returnable2.default, _stackable2.default, _toggleable2.default],
  37. props: {
  38. disabled: Boolean,
  39. persistent: Boolean,
  40. fullscreen: Boolean,
  41. fullWidth: Boolean,
  42. noClickAnimation: Boolean,
  43. light: Boolean,
  44. dark: Boolean,
  45. maxWidth: {
  46. type: [String, Number],
  47. default: 'none'
  48. },
  49. origin: {
  50. type: String,
  51. default: 'center center'
  52. },
  53. width: {
  54. type: [String, Number],
  55. default: 'auto'
  56. },
  57. scrollable: Boolean,
  58. transition: {
  59. type: [String, Boolean],
  60. default: 'dialog-transition'
  61. }
  62. },
  63. data: function data() {
  64. return {
  65. animate: false,
  66. animateTimeout: null,
  67. stackClass: 'v-dialog__content--active',
  68. stackMinZIndex: 200
  69. };
  70. },
  71. computed: {
  72. classes: function classes() {
  73. var _ref;
  74. return _ref = {}, _defineProperty(_ref, ('v-dialog ' + this.contentClass).trim(), true), _defineProperty(_ref, 'v-dialog--active', this.isActive), _defineProperty(_ref, 'v-dialog--persistent', this.persistent), _defineProperty(_ref, 'v-dialog--fullscreen', this.fullscreen), _defineProperty(_ref, 'v-dialog--scrollable', this.scrollable), _defineProperty(_ref, 'v-dialog--animated', this.animate), _ref;
  75. },
  76. contentClasses: function contentClasses() {
  77. return {
  78. 'v-dialog__content': true,
  79. 'v-dialog__content--active': this.isActive
  80. };
  81. },
  82. hasActivator: function hasActivator() {
  83. return Boolean(!!this.$slots.activator || !!this.$scopedSlots.activator);
  84. }
  85. },
  86. watch: {
  87. isActive: function isActive(val) {
  88. if (val) {
  89. this.show();
  90. this.hideScroll();
  91. } else {
  92. this.removeOverlay();
  93. this.unbind();
  94. }
  95. },
  96. fullscreen: function fullscreen(val) {
  97. if (!this.isActive) return;
  98. if (val) {
  99. this.hideScroll();
  100. this.removeOverlay(false);
  101. } else {
  102. this.showScroll();
  103. this.genOverlay();
  104. }
  105. }
  106. },
  107. beforeMount: function beforeMount() {
  108. var _this = this;
  109. this.$nextTick(function () {
  110. _this.isBooted = _this.isActive;
  111. _this.isActive && _this.show();
  112. });
  113. },
  114. mounted: function mounted() {
  115. if ((0, _helpers.getSlotType)(this, 'activator', true) === 'v-slot') {
  116. (0, _console.consoleError)('v-dialog\'s activator slot must be bound, try \'<template #activator="data"><v-btn v-on="data.on>\'', this);
  117. }
  118. },
  119. beforeDestroy: function beforeDestroy() {
  120. if (typeof window !== 'undefined') this.unbind();
  121. },
  122. methods: {
  123. animateClick: function animateClick() {
  124. var _this2 = this;
  125. this.animate = false;
  126. // Needed for when clicking very fast
  127. // outside of the dialog
  128. this.$nextTick(function () {
  129. _this2.animate = true;
  130. clearTimeout(_this2.animateTimeout);
  131. _this2.animateTimeout = setTimeout(function () {
  132. return _this2.animate = false;
  133. }, 150);
  134. });
  135. },
  136. closeConditional: function closeConditional(e) {
  137. // If the dialog content contains
  138. // the click event, or if the
  139. // dialog is not active
  140. if (!this.isActive || this.$refs.content.contains(e.target)) return false;
  141. // If we made it here, the click is outside
  142. // and is active. If persistent, and the
  143. // click is on the overlay, animate
  144. if (this.persistent) {
  145. if (!this.noClickAnimation && this.overlay === e.target) this.animateClick();
  146. return false;
  147. }
  148. // close dialog if !persistent, clicked outside and we're the topmost dialog.
  149. // Since this should only be called in a capture event (bottom up), we shouldn't need to stop propagation
  150. return this.activeZIndex >= this.getMaxZIndex();
  151. },
  152. hideScroll: function hideScroll() {
  153. if (this.fullscreen) {
  154. document.documentElement.classList.add('overflow-y-hidden');
  155. } else {
  156. _overlayable2.default.options.methods.hideScroll.call(this);
  157. }
  158. },
  159. show: function show() {
  160. !this.fullscreen && !this.hideOverlay && this.genOverlay();
  161. this.$refs.content.focus();
  162. this.bind();
  163. },
  164. bind: function bind() {
  165. window.addEventListener('focusin', this.onFocusin);
  166. },
  167. unbind: function unbind() {
  168. window.removeEventListener('focusin', this.onFocusin);
  169. },
  170. onKeydown: function onKeydown(e) {
  171. if (e.keyCode === _helpers.keyCodes.esc && !this.getOpenDependents().length) {
  172. if (!this.persistent) {
  173. this.isActive = false;
  174. var activator = this.getActivator();
  175. this.$nextTick(function () {
  176. return activator && activator.focus();
  177. });
  178. } else if (!this.noClickAnimation) {
  179. this.animateClick();
  180. }
  181. }
  182. this.$emit('keydown', e);
  183. },
  184. onFocusin: function onFocusin(e) {
  185. var _event = event,
  186. target = _event.target;
  187. if (
  188. // It isn't the document or the dialog body
  189. ![document, this.$refs.content].includes(target) &&
  190. // It isn't inside the dialog body
  191. !this.$refs.content.contains(target) &&
  192. // We're the topmost dialog
  193. this.activeZIndex >= this.getMaxZIndex() &&
  194. // It isn't inside a dependent element (like a menu)
  195. !this.getOpenDependentElements().some(function (el) {
  196. return el.contains(target);
  197. })
  198. // So we must have focused something outside the dialog and its children
  199. ) {
  200. // Find and focus the first available element inside the dialog
  201. var focusable = this.$refs.content.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
  202. focusable.length && focusable[0].focus();
  203. }
  204. },
  205. getActivator: function getActivator(e) {
  206. if (this.$refs.activator) {
  207. return this.$refs.activator.children.length > 0 ? this.$refs.activator.children[0] : this.$refs.activator;
  208. }
  209. if (e) {
  210. this.activatedBy = e.currentTarget || e.target;
  211. }
  212. if (this.activatedBy) return this.activatedBy;
  213. if (this.activatorNode) {
  214. var activator = Array.isArray(this.activatorNode) ? this.activatorNode[0] : this.activatorNode;
  215. var el = activator && activator.elm;
  216. if (el) return el;
  217. }
  218. (0, _console.consoleError)('No activator found');
  219. },
  220. genActivator: function genActivator() {
  221. var _this3 = this;
  222. if (!this.hasActivator) return null;
  223. var listeners = this.disabled ? {} : {
  224. click: function click(e) {
  225. e.stopPropagation();
  226. _this3.getActivator(e);
  227. if (!_this3.disabled) _this3.isActive = !_this3.isActive;
  228. }
  229. };
  230. if ((0, _helpers.getSlotType)(this, 'activator') === 'scoped') {
  231. var activator = this.$scopedSlots.activator({ on: listeners });
  232. this.activatorNode = activator;
  233. return activator;
  234. }
  235. return this.$createElement('div', {
  236. staticClass: 'v-dialog__activator',
  237. class: {
  238. 'v-dialog__activator--disabled': this.disabled
  239. },
  240. ref: 'activator',
  241. on: listeners
  242. }, this.$slots.activator);
  243. }
  244. },
  245. render: function render(h) {
  246. var _this4 = this;
  247. var children = [];
  248. var data = {
  249. 'class': this.classes,
  250. ref: 'dialog',
  251. directives: [{
  252. name: 'click-outside',
  253. value: function value() {
  254. _this4.isActive = false;
  255. },
  256. args: {
  257. closeConditional: this.closeConditional,
  258. include: this.getOpenDependentElements
  259. }
  260. }, { name: 'show', value: this.isActive }],
  261. on: {
  262. click: function click(e) {
  263. e.stopPropagation();
  264. }
  265. }
  266. };
  267. if (!this.fullscreen) {
  268. data.style = {
  269. maxWidth: this.maxWidth === 'none' ? undefined : (0, _helpers.convertToUnit)(this.maxWidth),
  270. width: this.width === 'auto' ? undefined : (0, _helpers.convertToUnit)(this.width)
  271. };
  272. }
  273. children.push(this.genActivator());
  274. var dialog = h('div', data, this.showLazyContent(this.$slots.default));
  275. if (this.transition) {
  276. dialog = h('transition', {
  277. props: {
  278. name: this.transition,
  279. origin: this.origin
  280. }
  281. }, [dialog]);
  282. }
  283. children.push(h('div', {
  284. 'class': this.contentClasses,
  285. attrs: _extends({
  286. tabIndex: '-1'
  287. }, this.getScopeIdAttrs()),
  288. on: {
  289. keydown: this.onKeydown
  290. },
  291. style: { zIndex: this.activeZIndex },
  292. ref: 'content'
  293. }, [this.$createElement(_ThemeProvider2.default, {
  294. props: {
  295. root: true,
  296. light: this.light,
  297. dark: this.dark
  298. }
  299. }, [dialog])]));
  300. return h('div', {
  301. staticClass: 'v-dialog__container',
  302. style: {
  303. display: !this.hasActivator || this.fullWidth ? 'block' : 'inline-block'
  304. }
  305. }, children);
  306. }
  307. };
  308. //# sourceMappingURL=VDialog.js.map