UNPKG

@vuesax-alpha/nightly

Version:
88 lines (83 loc) 2.61 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var shared = require('@vue/shared'); var lodashUnified = require('lodash-unified'); require('../../../utils/index.js'); var method = require('./method.js'); const INSTANCE_KEY = Symbol("VsLoading"); const createInstance = (el, binding) => { var _a; const vm = binding.instance; const getBindingProp = (key) => shared.isObject(binding.value) ? binding.value[key] : void 0; const resolveExpression = (key) => { const data = shared.isString(key) && (vm == null ? void 0 : vm[key]) || key; if (data) return vue.ref(data); return data; }; const getProp = (name, def) => { var _a2, _b; return resolveExpression( (_b = (_a2 = getBindingProp(name)) != null ? _a2 : el.getAttribute(`element-loading-${shared.hyphenate(name)}`)) != null ? _b : def ); }; const options = { text: getProp("text"), color: getProp("color"), background: getProp("background"), target: (_a = getBindingProp("target")) != null ? _a : el, opacity: getProp("opacity"), progress: getProp("progress"), percent: getProp("percent"), scale: getProp("scale"), type: getProp("type") }; el[INSTANCE_KEY] = { options, instance: method.loading(options) }; }; const updateOptions = (newOptions, originalOptions) => { for (const key of Object.keys(originalOptions)) { if (vue.isRef(originalOptions[key])) { originalOptions[key].value = newOptions[key]; } } }; const vLoading = { mounted(el, binding) { if (binding.value == true || shared.isObject(binding.value) && binding.value.visible) { createInstance(el, binding); } }, updated(el, binding) { var _a; const instance = el[INSTANCE_KEY]; if (!lodashUnified.isEqual(binding.value, binding.oldValue)) { if (shared.isObject(binding.value)) { if (binding.value.visible) { if (!((_a = binding.oldValue) == null ? void 0 : _a.visible)) { createInstance(el, binding); } if (instance) updateOptions(binding.value, instance.options); } else { instance == null ? void 0 : instance.instance.close(); } } else { if (binding.value) { createInstance(el, binding); } else { instance == null ? void 0 : instance.instance.close(); } } } }, unmounted(el) { var _a; (_a = el[INSTANCE_KEY]) == null ? void 0 : _a.instance.close(); } }; exports.vLoading = vLoading; //# sourceMappingURL=directive.js.map