@innovation-system/vuetify-week-scheduler
Version:
Vuetify week scheduler for Vue 2
1,680 lines (1,471 loc) • 63.2 kB
JavaScript
'use strict';var lib=require('vuetify/lib');function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _regeneratorRuntime() {
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
_regeneratorRuntime = function () {
return exports;
};
var exports = {},
Op = Object.prototype,
hasOwn = Op.hasOwnProperty,
$Symbol = "function" == typeof Symbol ? Symbol : {},
iteratorSymbol = $Symbol.iterator || "@@iterator",
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function define(obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: !0,
configurable: !0,
writable: !0
}), obj[key];
}
try {
define({}, "");
} catch (err) {
define = function (obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
generator = Object.create(protoGenerator.prototype),
context = new Context(tryLocsList || []);
return generator._invoke = function (innerFn, self, context) {
var state = "suspendedStart";
return function (method, arg) {
if ("executing" === state) throw new Error("Generator is already running");
if ("completed" === state) {
if ("throw" === method) throw arg;
return doneResult();
}
for (context.method = method, context.arg = arg;;) {
var delegate = context.delegate;
if (delegate) {
var delegateResult = maybeInvokeDelegate(delegate, context);
if (delegateResult) {
if (delegateResult === ContinueSentinel) continue;
return delegateResult;
}
}
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
if ("suspendedStart" === state) throw state = "completed", context.arg;
context.dispatchException(context.arg);
} else "return" === context.method && context.abrupt("return", context.arg);
state = "executing";
var record = tryCatch(innerFn, self, context);
if ("normal" === record.type) {
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
return {
value: record.arg,
done: context.done
};
}
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
}
};
}(innerFn, self, context), generator;
}
function tryCatch(fn, obj, arg) {
try {
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return {
type: "throw",
arg: err
};
}
}
exports.wrap = wrap;
var ContinueSentinel = {};
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
var IteratorPrototype = {};
define(IteratorPrototype, iteratorSymbol, function () {
return this;
});
var getProto = Object.getPrototypeOf,
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);
});
});
}
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if ("throw" !== record.type) {
var result = record.arg,
value = result.value;
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
result.value = unwrapped, resolve(result);
}, function (error) {
return invoke("throw", error, resolve, reject);
});
}
reject(record.arg);
}
var previousPromise;
this._invoke = function (method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
};
}
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
if (undefined === method) {
if (context.delegate = null, "throw" === context.method) {
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
return ContinueSentinel;
}
var record = tryCatch(method, delegate.iterator, context.arg);
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
var info = record.arg;
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
}
function pushTryEntry(locs) {
var entry = {
tryLoc: locs[0]
};
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal", delete record.arg, entry.completion = record;
}
function Context(tryLocsList) {
this.tryEntries = [{
tryLoc: "root"
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
}
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) return iteratorMethod.call(iterable);
if ("function" == typeof iterable.next) return iterable;
if (!isNaN(iterable.length)) {
var i = -1,
next = function next() {
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
return next.value = undefined, next.done = !0, next;
};
return next.next = next;
}
}
return {
next: doneResult
};
}
function doneResult() {
return {
value: undefined,
done: !0
};
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
var ctor = "function" == typeof genFun && genFun.constructor;
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
}, exports.mark = function (genFun) {
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
}, exports.awrap = function (arg) {
return {
__await: arg
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
void 0 === PromiseImpl && (PromiseImpl = Promise);
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
return this;
}), define(Gp, "toString", function () {
return "[object Generator]";
}), exports.keys = function (object) {
var keys = [];
for (var key in object) keys.push(key);
return keys.reverse(), function next() {
for (; keys.length;) {
var key = keys.pop();
if (key in object) return next.value = key, next.done = !1, next;
}
return next.done = !0, next;
};
}, exports.values = values, Context.prototype = {
constructor: Context,
reset: function (skipTempReset) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
},
stop: function () {
this.done = !0;
var rootRecord = this.tryEntries[0].completion;
if ("throw" === rootRecord.type) throw rootRecord.arg;
return this.rval;
},
dispatchException: function (exception) {
if (this.done) throw exception;
var context = this;
function handle(loc, caught) {
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
}
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i],
record = entry.completion;
if ("root" === entry.tryLoc) return handle("end");
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc"),
hasFinally = hasOwn.call(entry, "finallyLoc");
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
} else if (hasCatch) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
} else {
if (!hasFinally) throw new Error("try statement without catch or finally");
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
}
}
}
},
abrupt: function (type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;
break;
}
}
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
var record = finallyEntry ? finallyEntry.completion : {};
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
},
complete: function (record, afterLoc) {
if ("throw" === record.type) throw record.arg;
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
},
finish: function (finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
}
},
catch: function (tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc === tryLoc) {
var record = entry.completion;
if ("throw" === record.type) {
var thrown = record.arg;
resetTryEntry(entry);
}
return thrown;
}
}
throw new Error("illegal catch attempt");
},
delegateYield: function (iterable, resultName, nextLoc) {
return this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
}
}, exports;
}
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
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;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _createForOfIteratorHelper(o, allowArrayLike) {
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (!it) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
var F = function () {};
return {
s: F,
n: function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
},
e: function (e) {
throw e;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true,
didErr = false,
err;
return {
s: function () {
it = it.call(o);
},
n: function () {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function (e) {
didErr = true;
err = e;
},
f: function () {
try {
if (!normalCompletion && it.return != null) it.return();
} finally {
if (didErr) throw err;
}
}
};
}//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var script$1 = {
components: {
VIcon: lib.VIcon,
VBtn: lib.VBtn,
VHover: lib.VHover
},
name: "vuetify-week-scheduler-period",
props: {
period: Object,
settings: Object,
blockHeight: Number,
editable: {
type: Boolean,
default: false
}
},
computed: {
options: function options() {
return this.period.options;
},
shortPeriod: function shortPeriod() {
return this.period.height <= 30;
}
}
};function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
if (typeof shadowMode !== 'boolean') {
createInjectorSSR = createInjector;
createInjector = shadowMode;
shadowMode = false;
}
// Vue.extend constructor export interop.
const options = typeof script === 'function' ? script.options : script;
// render functions
if (template && template.render) {
options.render = template.render;
options.staticRenderFns = template.staticRenderFns;
options._compiled = true;
// functional template
if (isFunctionalTemplate) {
options.functional = true;
}
}
// scopedId
if (scopeId) {
options._scopeId = scopeId;
}
let hook;
if (moduleIdentifier) {
// server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__;
}
// inject component styles
if (style) {
style.call(this, createInjectorSSR(context));
}
// register component module identifier for async chunk inference
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier);
}
};
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook;
}
else if (style) {
hook = shadowMode
? function (context) {
style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
}
: function (context) {
style.call(this, createInjector(context));
};
}
if (hook) {
if (options.functional) {
// register for functional component in vue file
const originalRender = options.render;
options.render = function renderWithStyleInjection(h, context) {
hook.call(context);
return originalRender(h, context);
};
}
else {
// inject component registration as beforeCreate hook
const existing = options.beforeCreate;
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
}
}
return script;
}/* script */
var __vue_script__$1 = script$1;
/* template */
var __vue_render__$1 = function __vue_render__() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c('v-hover', {
scopedSlots: _vm._u([{
key: "default",
fn: function fn(ref) {
var hover = ref.hover;
return [_c('div', {
staticClass: "vws-period",
style: {
backgroundColor: _vm.options.backgroundColor,
outlineColor: _vm.options.borderColor,
textColor: _vm.options.textColor,
color: _vm.options.textColor,
top: _vm.period.top + 'px',
height: _vm.period.height + 'px'
},
on: {
"mousedown": function mousedown($event) {
$event.stopPropagation();
return _vm.$emit('period-drag', $event);
},
"touchstart": function touchstart($event) {
$event.stopPropagation();
return _vm.$emit('period-drag', $event);
},
"contextmenu": function contextmenu($event) {
$event.stopPropagation();
$event.preventDefault();
return _vm.$emit('edit', $event);
},
"dblclick": function dblclick($event) {
$event.stopPropagation();
$event.preventDefault();
return _vm.$emit('edit', $event);
}
}
}, [_c('div', {
staticClass: "vws-period-container"
}, [_c('v-icon', {
directives: [{
name: "show",
rawName: "v-show",
value: _vm.editable && hover,
expression: "editable && hover"
}],
staticClass: "vws-handle",
attrs: {
"small": ""
},
on: {
"mousedown": function mousedown($event) {
$event.stopPropagation();
return _vm.$emit('period-resize', {
$event: $event,
isUp: true,
$el: _vm.$el
});
},
"touchstart": function touchstart($event) {
$event.stopPropagation();
return _vm.$emit('period-resize', {
$event: $event,
isUp: true,
$el: _vm.$el
});
}
}
}, [_vm._v("\n mdi-chevron-up\n ")]), _vm._v(" "), _c('div', {
staticClass: "vws-period-time"
}, [_vm._v("\n " + _vm._s(_vm.options.start) + " - " + _vm._s(_vm.options.end) + "\n "), _c('span', {
directives: [{
name: "show",
rawName: "v-show",
value: _vm.shortPeriod,
expression: "shortPeriod"
}],
staticClass: "text--caption ml-2"
}, [_vm._v(_vm._s(_vm.options.title))])]), _vm._v(" "), _c('div', {
directives: [{
name: "show",
rawName: "v-show",
value: !_vm.shortPeriod,
expression: "!shortPeriod"
}],
staticClass: "vws-period-title text-truncate"
}, [_vm._v("\n " + _vm._s(_vm.options.title) + "\n ")]), _vm._v(" "), _c('div', {
directives: [{
name: "show",
rawName: "v-show",
value: _vm.editable && hover,
expression: "editable && hover"
}],
staticClass: "vws-period-buttons",
attrs: {
"justify": "end"
}
}, [_c('v-btn', {
attrs: {
"icon": "",
"x-small": "",
"title": _vm.settings.periodRemoveButton
},
on: {
"click": function click($event) {
$event.stopPropagation();
return _vm.$emit('delete');
},
"mousedown": function mousedown($event) {
$event.stopPropagation();
},
"touchstart": function touchstart($event) {
$event.stopPropagation();
}
}
}, [_c('v-icon', {
attrs: {
"x-small": ""
}
}, [_vm._v("mdi-close")])], 1), _vm._v(" "), _c('v-btn', {
attrs: {
"icon": "",
"x-small": "",
"title": _vm.settings.periodDuplicateButton
},
on: {
"click": function click($event) {
$event.stopPropagation();
return _vm.$emit('clone');
},
"mousedown": function mousedown($event) {
$event.stopPropagation();
},
"touchstart": function touchstart($event) {
$event.stopPropagation();
}
}
}, [_c('v-icon', {
attrs: {
"x-small": ""
}
}, [_vm._v("mdi-content-copy")])], 1)], 1), _vm._v(" "), _c('v-icon', {
directives: [{
name: "show",
rawName: "v-show",
value: _vm.editable && hover,
expression: "editable && hover"
}],
staticClass: "vws-handle",
staticStyle: {
"bottom": "0"
},
attrs: {
"small": ""
},
on: {
"mousedown": function mousedown($event) {
$event.stopPropagation();
return _vm.$emit('period-resize', {
$event: $event,
isUp: false,
$el: _vm.$el
});
},
"touchstart": function touchstart($event) {
$event.stopPropagation();
return _vm.$emit('period-resize', {
$event: $event,
isUp: false,
$el: _vm.$el
});
}
}
}, [_vm._v("\n mdi-chevron-down\n ")])], 1)])];
}
}])
});
};
var __vue_staticRenderFns__$1 = [];
/* style */
var __vue_inject_styles__$1 = undefined;
/* scoped */
var __vue_scope_id__$1 = undefined;
/* module identifier */
var __vue_module_identifier__$1 = "data-v-2726a30b";
/* functional template */
var __vue_is_functional_template__$1 = false;
/* style inject */
/* style inject SSR */
/* style inject shadow dom */
var __vue_component__$1 = /*#__PURE__*/normalizeComponent({
render: __vue_render__$1,
staticRenderFns: __vue_staticRenderFns__$1
}, __vue_inject_styles__$1, __vue_script__$1, __vue_scope_id__$1, __vue_is_functional_template__$1, __vue_module_identifier__$1, false, undefined, undefined, undefined);var script = {
name: "vuetify-week-scheduler",
// vue component name
components: {
SchedulerPeriod: __vue_component__$1,
VIcon: lib.VIcon,
VBtn: lib.VBtn,
VHover: lib.VHover,
VTextField: lib.VTextField,
VListItem: lib.VListItem,
VList: lib.VList,
VMenu: lib.VMenu
},
props: {
config: {
type: Object,
default: function _default() {}
},
value: {
type: Array,
required: true
},
editable: {
type: Boolean,
default: false
}
},
data: function data() {
return {
settings: {},
counter: 0,
blocksEachHour: 0,
maxBlocks: 0,
blockHeight: 0,
events: [],
// keep track of listeners
newPeriod: null,
draggingPeriod: null,
resizingPeriod: null,
showEditMenu: false,
x: 0,
y: 0,
editEvent: null
};
},
mounted: function mounted() {
this.settings = _objectSpread2(_objectSpread2({}, this.getDefaults()), this.config);
this.init();
this.handleEvents();
},
beforeDestroy: function beforeDestroy() {
this.events.forEach(function (e) {
e.element.removeEventListener(e.event, e.callback);
});
},
computed: {
data: {
get: function get() {
var toReturn = this.value; // validate data object
if (this.value.length !== this.settings.days) {
toReturn = [];
for (var i = 0; i < this.settings.days; i++) {
toReturn.push({
day: i,
periods: []
});
}
this.$emit("input", toReturn);
}
return toReturn;
},
set: function set(value) {
this.$emit("input", value);
}
},
daysPeriods: function daysPeriods() {
var toReturn = [];
for (var d = 0; d < this.settings.days; d++) {
var _this$data;
var toPush = {
day: d,
periods: []
};
toReturn.push(toPush);
var day = (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data[d];
if (day) {
for (var i = 0; i < day.periods.length; i++) {
var period = day.periods[i];
var start = this.positionFormat(period.start);
var end = this.positionFormat(period.end);
toPush.periods.push({
options: this.addDefaults(period),
index: i,
top: start * this.blockHeight,
height: (end - start) * this.blockHeight
});
}
}
}
return toReturn;
},
isMobile: function isMobile() {
return this.$vuetify.breakpoint.mdAndDown;
}
},
methods: {
getDefaults: function getDefaults() {
return {
hour: 24,
// 12
days: 7,
// 7/5
periodDuration: 15,
// 15/30/60
periodTitle: "",
periodBackgroundColor: "#F44336FF",
periodBorderColor: "transparent",
periodTextColor: "#000",
periodRemoveButton: "Remove",
periodDuplicateButton: "Duplicate",
periodSelectWholeButton: "Select whole day",
inputType: "text",
daysList: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
colors: ["#F44336", "#FF9800", "#FFEB3B", "#8BC34A", "#4CAF50", "#00BCD4", "#2196F3"]
};
},
/** When clicking on a day */
onDayDown: function onDayDown(day, e) {
if (!this.editable) return;
var rect = e.currentTarget.getBoundingClientRect();
var offset = this.getY(e, true) - rect.top;
var blocks = Math.floor(offset / this.blockHeight);
var start = this.blocksToTime(blocks);
var end = this.blocksToTime(blocks + 2);
var height = 2 * this.blockHeight; // show the ghost period
this.newPeriod = {
dragStart: this.getY(e, true),
startHeight: height,
maxHeight: e.currentTarget.clientHeight,
day: day,
start: start,
end: end,
top: blocks * this.blockHeight,
height: height
};
},
/** Add defaults to period */
addDefaults: function addDefaults(period) {
return _objectSpread2({
title: this.settings.periodTitle,
backgroundColor: this.settings.periodBackgroundColor,
borderColor: this.settings.periodBorderColor,
textColor: this.settings.periodTextColor
}, period);
},
handleEvents: function handleEvents() {
var _this = this;
var onUp = function onUp() {
if (_this.newPeriod) {
_this.addPeriod(_this.newPeriod.day, {
start: _this.newPeriod.start,
end: _this.newPeriod.end
});
_this.newPeriod = null;
} else if (_this.draggingPeriod) {
var _this$draggingPeriod = _this.draggingPeriod,
el = _this$draggingPeriod.el,
day = _this$draggingPeriod.day,
index = _this$draggingPeriod.index;
var top = el.offsetTop;
var height = el.clientHeight;
_this.onPositionChange(day, index, {
top: top,
height: height
});
_this.draggingPeriod = null;
} else if (_this.resizingPeriod) {
var _this$resizingPeriod = _this.resizingPeriod,
_el = _this$resizingPeriod.el,
_day = _this$resizingPeriod.day,
_index = _this$resizingPeriod.index;
var _top = _el.offsetTop;
var _height = _el.clientHeight;
_this.onPositionChange(_day, _index, {
top: _top,
height: _height
});
_this.resizingPeriod = null;
}
};
var onMove = function onMove(e) {
if (_this.newPeriod) {
e.preventDefault();
var dragDelta = _this.roundBlock(_this.newPeriod.dragStart - _this.getY(e, true));
var height = _this.roundBlock(_this.newPeriod.startHeight - dragDelta);
if (height > _this.blockHeight && _this.newPeriod.top + height <= _this.newPeriod.maxHeight) {
var _this$positionToInter = _this.positionToInterval(_this.newPeriod),
start = _this$positionToInter.start,
end = _this$positionToInter.end;
var periods = _this.data[_this.newPeriod.day].periods;
if (_this.isValid({
start: start,
end: end
}, periods)) {
Object.assign(_this.newPeriod, {
height: height,
start: start,
end: end
});
}
}
} else if (_this.draggingPeriod) {
e.preventDefault();
var _this$draggingPeriod2 = _this.draggingPeriod,
startDrag = _this$draggingPeriod2.startDrag,
startTop = _this$draggingPeriod2.startTop,
el = _this$draggingPeriod2.el,
day = _this$draggingPeriod2.day,
index = _this$draggingPeriod2.index;
var _dragDelta = startDrag - _this.getY(e, true);
var top = _this.roundBlock(startTop - _dragDelta);
var _height2 = el.clientHeight;
var maxHeight = el.parentElement.clientHeight;
if (top + _height2 <= maxHeight && top >= 0) {
el.style.top = "".concat(top, "px");
_this.onPositionChange(day, index, {
top: top,
height: _height2
});
}
} else if (_this.resizingPeriod) {
e.preventDefault();
var _this$resizingPeriod2 = _this.resizingPeriod,
_startDrag = _this$resizingPeriod2.startDrag,
_startTop = _this$resizingPeriod2.startTop,
startHeight = _this$resizingPeriod2.startHeight,
_el2 = _this$resizingPeriod2.el,
_day2 = _this$resizingPeriod2.day,
_index2 = _this$resizingPeriod2.index,
isUp = _this$resizingPeriod2.isUp;
var _dragDelta2 = _this.roundBlock(_startDrag - _this.getY(e, true));
var _top2 = isUp ? _this.roundBlock(_startTop - _dragDelta2) : _el2.offsetTop;
var _height3 = _this.roundBlock(startHeight + (isUp ? _dragDelta2 : -_dragDelta2));
var _maxHeight = document.querySelector(".vws-day").clientHeight;
_height3 = Math.max(_height3, _this.blockHeight);
if (_top2 + _height3 <= _maxHeight && _top2 >= 0) {
_el2.style.height = "".concat(_height3, "px");
if (isUp) {
_el2.style.top = "".concat(_top2, "px");
}
_this.onPositionChange(_day2, _index2, {
top: _top2,
height: _height3
});
}
}
};
this.addListener(document, "mouseup", onUp);
this.addListener(document, "touchend", onUp);
this.addListener(document, "mousemove", onMove);
this.addListener(document, "touchmove", onMove);
},
onPeriodDown: function onPeriodDown(e, day, index) {
if (this.editable) {
var el = e.currentTarget;
this.draggingPeriod = {
el: el,
day: day,
index: index,
startDrag: this.getY(e, false),
startTop: el.offsetTop
};
}
},
onPeriodResize: function onPeriodResize(event, day, index) {
if (this.editable) {
var e = event.$event,
isUp = event.isUp,
$el = event.$el;
this.resizingPeriod = {
el: $el,
day: day,
index: index,
isUp: isUp,
startDrag: this.getY(e, false),
startTop: $el.offsetTop,
startHeight: $el.clientHeight
};
}
},
addPeriod: function addPeriod(day, period) {
if (!this.data[day]) {
this.data[day] = {
day: day,
periods: []
};
}
var periods = this.data[day].periods;
period = this.addDefaults(period);
if (this.isValid(period, periods)) {
periods.push(period);
}
},
init: function init() {
var _this2 = this;
try {
// duration validation
if (![15, 30, 60].includes(this.settings.periodDuration)) {
throw new Error("Invalide period duration");
}
this.blocksEachHour = 60 / this.settings.periodDuration; // How many blocks there are in an hour
this.maxBlocks = 24 * this.blocksEachHour; // Period height in blocks
this.blockHeight = 40 / this.blocksEachHour; // Pixel height of each block
// periods validation
this.data.forEach(function (d) {
d === null || d === void 0 ? void 0 : d.periods.forEach(function (period, i) {
if (!_this2.isValid(period, d.periods)) {
d.periods.splice(i, 1); // eslint-disable-next-line no-console
console.error("Invalid period duration", period);
}
});
});
} catch (error) {
this.$emit("error", error);
}
},
deletePeriod: function deletePeriod(day, index) {
this.data[day].periods.splice(index, 1);
},
clonePeriod: function clonePeriod(day, indexOrPeriod) {
var period = _typeof(indexOrPeriod) === "object" ? indexOrPeriod : this.data[day].periods[indexOrPeriod];
var _iterator = _createForOfIteratorHelper(this.data),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var d = _step.value;
if (d.day !== day && this.isValid(period, d.periods)) {
d.periods.push(_objectSpread2({}, period));
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
},
clearDayPeriods: function clearDayPeriods(day) {
if (this.data[day]) {
this.data[day].periods = [];
}
},
cloneDayPeriods: function cloneDayPeriods(day) {
if (this.data[day]) {
var periods = this.data[day].periods;
var _iterator2 = _createForOfIteratorHelper(this.data),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var d = _step2.value;
if (d.day !== day) {
var _iterator3 = _createForOfIteratorHelper(periods),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var p = _step3.value;
this.clonePeriod(day, p);
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
},
onPositionChange: function onPositionChange(day, periodIndex, pos) {
var _this3 = this;
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var _this3$data, _day3;
var period, _this3$positionToInte, start, end, oldStart, oldEnd;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
day = (_this3$data = _this3.data) === null || _this3$data === void 0 ? void 0 : _this3$data[day];
period = (_day3 = day) === null || _day3 === void 0 ? void 0 : _day3.periods[periodIndex];
if (!period) {
_context.next = 10;
break;
}
_this3$positionToInte = _this3.positionToInterval(pos), start = _this3$positionToInte.start, end = _this3$positionToInte.end;
oldStart = period.start;
oldEnd = period.end;
Object.assign(period, {
start: start,
end: end
});
_context.next = 9;
return _this3.$nextTick();
case 9:
if (!_this3.isValid(period, day.periods)) {
Object.assign(period, {
start: oldStart,
end: oldEnd
});
}
case 10:
case "end":
return _context.stop();
}
}
}, _callee);
}))();
},
/** Round val to nearest multiple of blockHeight */
roundBlock: function roundBlock(val) {
return Math.round(val / this.blockHeight) * this.blockHeight;
},
/** Returns start/end hours string (hh:mm) from period top/height in pixel */
positionToInterval: function positionToInterval(pos) {
return {
start: this.blocksToTime(pos.top / this.blockHeight),
end: this.blocksToTime(Math.floor((pos.top + pos.height) / this.blockHeight))
};
},
/**
* Return a readable hour from a block position
* @param position
* @returns {number}
*/
blocksToTime: function blocksToTime(nBlocks) {
if (nBlocks > this.maxBlocks) {
nBlocks = 0;
}
if (nBlocks < 0) {
nBlocks = 0;
}
var hour = Math.floor(nBlocks / this.blocksEachHour);
var mn = (nBlocks / this.blocksEachHour - hour) * 60;
if (this.settings.hour === 12) {
var time = hour;
var ind = "";
if (hour >= 12) {
ind = "p";
}
if (hour > 12) {
time = hour - 12;
}
if (hour === 0 || hour === 24) {
ind = "";
time = 12;
}
if (mn !== 0) {
time += ":".concat(mn);
}
return time + ind;
}
if (hour < 10) {
hour = "0".concat(hour);
}
if (mn < 10) {
mn = "0".concat(mn);
} // back compatibility when period ends on 23:59
if (hour === 23 && mn === 59) {
hour = "24";
mn = "00";
}
return "".concat(hour, ":").concat(mn);
},
/** Hour to string */
formatHour: function formatHour(hour) {
if (this.settings.hour === 12) {
switch (hour) {
case 0:
case 24:
hour = "12am";
break;
case 12:
hour = "12pm";
break;
default:
if (hour > 12) {
hour = "".concat(hour - 12, "pm");
} else {
hour += "am";
}
}
} else {
if (hour > 24) {
hour = 0;
}
if (hour < 10) {
hour = "0".concat(hour);
}
hour += ":00";
}
return hour;
},
/**
* Return blocks from a time string (hh:mm)
* @param time
* @returns {number}
*/
positionFormat: function positionFormat(time) {
var split = time.split(":");
var hour = parseInt(split[0], 10);
var mn = parseInt(split[1], 10);
if (this.settings.hour === 12) {
var matches = time.match(/([0-1]?[0-9]):?([0-5][0-9])?\s?(am|pm|p)?/);
var ind = matches[3];
if (!ind) {
ind = "am";
}
hour = parseInt(matches[1], 10);
mn = parseInt(matches[2], 10);
if (!mn) {
mn = 0;
}
if (hour === 12 && ind === "am") {
hour = 0;
}
if (hour === 12 && (ind === "pm" || ind === "p")) {
ind = "am";
}
if (ind === "pm" || ind === "p") {
hour += 12;
}
}
var position = 0;
position += hour * this.blocksEachHour;
position += mn / 60 * this.blocksEachHour; // if (Math.floor(position) !== position) {
// return -1
// }
return position;
},
/**
* Check if a period is valid
* @param current
* @returns {boolean}
*/
isValid: function isValid(current, periods) {
var currentStart = this.positionFormat(current.start);
var currentEnd = this.positionFormat(current.end);
var start = 0;
var end = 0;
var check = true;
var _iterator4 = _createForOfIteratorHelper(periods),
_step4;
try {
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
var p = _step4.value;
if (p !== current) {
start = this.positionFormat(p.start);
end = this.positionFormat(p.end);
if (start > currentStart && start < currentEnd) {
check = false;
}
if (end > currentStart && end < currentEnd) {
check = false;
}
if (start < currentStart && end > currentEnd) {
check = false;
}
if (start === currentStart || end === currentEnd) {
check = false;
}
if (!check) {
break;
}
}
}
} catch (err) {
_iterator4.e(err);
} finally {
_iterator4.f();
}
return check;
},
addListener: function addListener(element, event, callback, options) {
this.events.push({
element: element,
event: event,
callback: callback
});
element.addEventListener(event, callback, options);
},
editPeriod: function editPeriod(day, index, e) {
var _this4 = this;
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
var periods;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (!_this4.editable) {
_context2.next = 14;
break;
}
if (!_this4.$listeners.edit) {
_context2.next = 5;
break;
}
_this4.$emit("edit", {
day: day,
index: index
});
_context2.next = 14;
break;
case 5:
e.preventDefault();
_this4.showEditMenu = false;
_this4.x = e.clientX;
_this4.y = e.clientY;
periods = _this4.value[day].periods;
_this4.editEvent = periods[index];
_context2.next = 13;
return _this4.$nextTick();
case 13:
_this4.showEditMenu = true;
case 14:
case "end":
return _context2.stop();
}
}
}, _callee2);
}))();
},
getY: function getY(e, prevent) {
var y = null;
if (e.type === "touchstart" || e.type === "touchmove" || e.type === "touchend" || e.type === "touchcancel") {
if (prevent) {
e.preventDefault();