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.

helpers.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2. 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; };
  3. import Vue from 'vue';
  4. export function createSimpleFunctional(c) {
  5. var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'div';
  6. var name = arguments[2];
  7. return Vue.extend({
  8. name: name || c.replace(/__/g, '-'),
  9. functional: true,
  10. render: function render(h, _ref) {
  11. var data = _ref.data,
  12. children = _ref.children;
  13. data.staticClass = (c + ' ' + (data.staticClass || '')).trim();
  14. return h(el, data, children);
  15. }
  16. });
  17. }
  18. function mergeTransitions(transitions, array) {
  19. if (Array.isArray(transitions)) return transitions.concat(array);
  20. if (transitions) array.push(transitions);
  21. return array;
  22. }
  23. export function createSimpleTransition(name) {
  24. var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top center 0';
  25. var mode = arguments[2];
  26. return {
  27. name: name,
  28. functional: true,
  29. props: {
  30. group: {
  31. type: Boolean,
  32. default: false
  33. },
  34. hideOnLeave: {
  35. type: Boolean,
  36. default: false
  37. },
  38. leaveAbsolute: {
  39. type: Boolean,
  40. default: false
  41. },
  42. mode: {
  43. type: String,
  44. default: mode
  45. },
  46. origin: {
  47. type: String,
  48. default: origin
  49. }
  50. },
  51. render: function render(h, context) {
  52. var tag = 'transition' + (context.props.group ? '-group' : '');
  53. context.data = context.data || {};
  54. context.data.props = {
  55. name: name,
  56. mode: context.props.mode
  57. };
  58. context.data.on = context.data.on || {};
  59. if (!Object.isExtensible(context.data.on)) {
  60. context.data.on = _extends({}, context.data.on);
  61. }
  62. var ourBeforeEnter = [];
  63. var ourLeave = [];
  64. var absolute = function absolute(el) {
  65. return el.style.position = 'absolute';
  66. };
  67. ourBeforeEnter.push(function (el) {
  68. el.style.transformOrigin = context.props.origin;
  69. el.style.webkitTransformOrigin = context.props.origin;
  70. });
  71. if (context.props.leaveAbsolute) ourLeave.push(absolute);
  72. if (context.props.hideOnLeave) {
  73. ourLeave.push(function (el) {
  74. return el.style.display = 'none';
  75. });
  76. }
  77. var _context$data$on = context.data.on,
  78. beforeEnter = _context$data$on.beforeEnter,
  79. leave = _context$data$on.leave;
  80. // Type says Function | Function[] but
  81. // will only work if provided a function
  82. context.data.on.beforeEnter = function () {
  83. return mergeTransitions(beforeEnter, ourBeforeEnter);
  84. };
  85. context.data.on.leave = mergeTransitions(leave, ourLeave);
  86. return h(tag, context.data, context.children);
  87. }
  88. };
  89. }
  90. export function createJavaScriptTransition(name, functions) {
  91. var mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'in-out';
  92. return {
  93. name: name,
  94. functional: true,
  95. props: {
  96. mode: {
  97. type: String,
  98. default: mode
  99. }
  100. },
  101. render: function render(h, context) {
  102. var data = {
  103. props: _extends({}, context.props, {
  104. name: name
  105. }),
  106. on: functions
  107. };
  108. return h('transition', data, context.children);
  109. }
  110. };
  111. }
  112. export function directiveConfig(binding) {
  113. var defaults = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  114. return _extends({}, defaults, binding.modifiers, {
  115. value: binding.arg
  116. }, binding.value || {});
  117. }
  118. export function addOnceEventListener(el, event, cb) {
  119. var once = function once() {
  120. cb();
  121. el.removeEventListener(event, once, false);
  122. };
  123. el.addEventListener(event, once, false);
  124. }
  125. var passiveSupported = false;
  126. try {
  127. if (typeof window !== 'undefined') {
  128. var testListenerOpts = Object.defineProperty({}, 'passive', {
  129. get: function get() {
  130. passiveSupported = true;
  131. }
  132. });
  133. window.addEventListener('testListener', testListenerOpts, testListenerOpts);
  134. window.removeEventListener('testListener', testListenerOpts, testListenerOpts);
  135. }
  136. } catch (e) {
  137. console.warn(e);
  138. }
  139. export { passiveSupported };
  140. export function addPassiveEventListener(el, event, cb, options) {
  141. el.addEventListener(event, cb, passiveSupported ? options : false);
  142. }
  143. export function getNestedValue(obj, path, fallback) {
  144. var last = path.length - 1;
  145. if (last < 0) return obj === undefined ? fallback : obj;
  146. for (var i = 0; i < last; i++) {
  147. if (obj == null) {
  148. return fallback;
  149. }
  150. obj = obj[path[i]];
  151. }
  152. if (obj == null) return fallback;
  153. return obj[path[last]] === undefined ? fallback : obj[path[last]];
  154. }
  155. export function deepEqual(a, b) {
  156. if (a === b) return true;
  157. if (a instanceof Date && b instanceof Date) {
  158. // If the values are Date, they were convert to timestamp with getTime and compare it
  159. if (a.getTime() !== b.getTime()) return false;
  160. }
  161. if (a !== Object(a) || b !== Object(b)) {
  162. // If the values aren't objects, they were already checked for equality
  163. return false;
  164. }
  165. var props = Object.keys(a);
  166. if (props.length !== Object.keys(b).length) {
  167. // Different number of props, don't bother to check
  168. return false;
  169. }
  170. return props.every(function (p) {
  171. return deepEqual(a[p], b[p]);
  172. });
  173. }
  174. export function getObjectValueByPath(obj, path, fallback) {
  175. // credit: http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key#comment55278413_6491621
  176. if (!path || path.constructor !== String) return fallback;
  177. path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
  178. path = path.replace(/^\./, ''); // strip a leading dot
  179. return getNestedValue(obj, path.split('.'), fallback);
  180. }
  181. export function getPropertyFromItem(item, property, fallback) {
  182. if (property == null) return item === undefined ? fallback : item;
  183. if (item !== Object(item)) return fallback === undefined ? item : fallback;
  184. if (typeof property === 'string') return getObjectValueByPath(item, property, fallback);
  185. if (Array.isArray(property)) return getNestedValue(item, property, fallback);
  186. if (typeof property !== 'function') return fallback;
  187. var value = property(item, fallback);
  188. return typeof value === 'undefined' ? fallback : value;
  189. }
  190. export function createRange(length) {
  191. return Array.from({ length: length }, function (v, k) {
  192. return k;
  193. });
  194. }
  195. export function getZIndex(el) {
  196. if (!el || el.nodeType !== Node.ELEMENT_NODE) return 0;
  197. var index = +window.getComputedStyle(el).getPropertyValue('z-index');
  198. if (isNaN(index)) return getZIndex(el.parentNode);
  199. return index;
  200. }
  201. var tagsToReplace = {
  202. '&': '&amp;',
  203. '<': '&lt;',
  204. '>': '&gt;'
  205. };
  206. export function escapeHTML(str) {
  207. return str.replace(/[&<>]/g, function (tag) {
  208. return tagsToReplace[tag] || tag;
  209. });
  210. }
  211. export function filterObjectOnKeys(obj, keys) {
  212. var filtered = {};
  213. for (var i = 0; i < keys.length; i++) {
  214. var key = keys[i];
  215. if (typeof obj[key] !== 'undefined') {
  216. filtered[key] = obj[key];
  217. }
  218. }
  219. return filtered;
  220. }
  221. export function filterChildren() {
  222. var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  223. var tag = arguments[1];
  224. return array.filter(function (child) {
  225. return child.componentOptions && child.componentOptions.Ctor.options.name === tag;
  226. });
  227. }
  228. export function convertToUnit(str) {
  229. var unit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'px';
  230. if (str == null || str === '') {
  231. return undefined;
  232. } else if (isNaN(+str)) {
  233. return String(str);
  234. } else {
  235. return '' + Number(str) + unit;
  236. }
  237. }
  238. export function kebabCase(str) {
  239. return (str || '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  240. }
  241. export function isObject(obj) {
  242. return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object';
  243. }
  244. // KeyboardEvent.keyCode aliases
  245. export var keyCodes = Object.freeze({
  246. enter: 13,
  247. tab: 9,
  248. delete: 46,
  249. esc: 27,
  250. space: 32,
  251. up: 38,
  252. down: 40,
  253. left: 37,
  254. right: 39,
  255. end: 35,
  256. home: 36,
  257. del: 46,
  258. backspace: 8,
  259. insert: 45,
  260. pageup: 33,
  261. pagedown: 34
  262. });
  263. var ICONS_PREFIX = '$vuetify.icons.';
  264. // This remaps internal names like '$vuetify.icons.cancel'
  265. // to the current name or component for that icon.
  266. export function remapInternalIcon(vm, iconName) {
  267. if (!iconName.startsWith(ICONS_PREFIX)) {
  268. return iconName;
  269. }
  270. // Now look up icon indirection name, e.g. '$vuetify.icons.cancel'
  271. return getObjectValueByPath(vm, iconName, iconName);
  272. }
  273. export function keys(o) {
  274. return Object.keys(o);
  275. }
  276. /**
  277. * Camelize a hyphen-delimited string.
  278. */
  279. var camelizeRE = /-(\w)/g;
  280. export var camelize = function camelize(str) {
  281. return str.replace(camelizeRE, function (_, c) {
  282. return c ? c.toUpperCase() : '';
  283. });
  284. };
  285. /**
  286. * Returns the set difference of B and A, i.e. the set of elements in B but not in A
  287. */
  288. export function arrayDiff(a, b) {
  289. var diff = [];
  290. for (var i = 0; i < b.length; i++) {
  291. if (a.indexOf(b[i]) < 0) diff.push(b[i]);
  292. }
  293. return diff;
  294. }
  295. /**
  296. * Makes the first character of a string uppercase
  297. */
  298. export function upperFirst(str) {
  299. return str.charAt(0).toUpperCase() + str.slice(1);
  300. }
  301. /**
  302. * Returns:
  303. * - 'normal' for old style slots - `<template slot="default">`
  304. * - 'scoped' for old style scoped slots (`<template slot="default" slot-scope="data">`) or bound v-slot (`#default="data"`)
  305. * - 'v-slot' for unbound v-slot (`#default`) - only if the third param is true, otherwise counts as scoped
  306. */
  307. export function getSlotType(vm, name, split) {
  308. if (vm.$slots[name] && vm.$scopedSlots[name] && vm.$scopedSlots[name].name) {
  309. return split ? 'v-slot' : 'scoped';
  310. }
  311. if (vm.$slots[name]) return 'normal';
  312. if (vm.$scopedSlots[name]) return 'scoped';
  313. }
  314. //# sourceMappingURL=helpers.js.map