directive.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var service = require('./service.js');
  5. var shared = require('@vue/shared');
  6. const INSTANCE_KEY = Symbol("ElLoading");
  7. const getAttributeName = (name) => {
  8. return `element-loading-${shared.hyphenate(name)}`;
  9. };
  10. const createInstance = (el, binding) => {
  11. var _a, _b, _c, _d;
  12. const vm = binding.instance;
  13. const getBindingProp = (key) => shared.isObject(binding.value) ? binding.value[key] : void 0;
  14. const resolveExpression = (key) => {
  15. const data = shared.isString(key) && (vm == null ? void 0 : vm[key]) || key;
  16. return vue.ref(data);
  17. };
  18. const getProp = (name) => resolveExpression(getBindingProp(name) || el.getAttribute(getAttributeName(name)));
  19. const fullscreen = (_a = getBindingProp("fullscreen")) != null ? _a : binding.modifiers.fullscreen;
  20. const options = {
  21. text: getProp("text"),
  22. svg: getProp("svg"),
  23. svgViewBox: getProp("svgViewBox"),
  24. spinner: getProp("spinner"),
  25. background: getProp("background"),
  26. customClass: getProp("customClass"),
  27. fullscreen,
  28. target: (_b = getBindingProp("target")) != null ? _b : fullscreen ? void 0 : el,
  29. body: (_c = getBindingProp("body")) != null ? _c : binding.modifiers.body,
  30. lock: (_d = getBindingProp("lock")) != null ? _d : binding.modifiers.lock
  31. };
  32. const instance = service["default"](options);
  33. instance._context = vLoading._context;
  34. el[INSTANCE_KEY] = {
  35. options,
  36. instance
  37. };
  38. };
  39. const updateOptions = (originalOptions, newOptions) => {
  40. for (const key of Object.keys(originalOptions)) {
  41. if (vue.isRef(originalOptions[key]))
  42. originalOptions[key].value = newOptions[key];
  43. }
  44. };
  45. const vLoading = {
  46. mounted(el, binding) {
  47. if (binding.value) {
  48. createInstance(el, binding);
  49. }
  50. },
  51. updated(el, binding) {
  52. const instance = el[INSTANCE_KEY];
  53. if (!binding.value) {
  54. instance == null ? void 0 : instance.instance.close();
  55. el[INSTANCE_KEY] = null;
  56. return;
  57. }
  58. if (!instance)
  59. createInstance(el, binding);
  60. else {
  61. updateOptions(instance.options, shared.isObject(binding.value) ? binding.value : {
  62. text: el.getAttribute(getAttributeName("text")),
  63. svg: el.getAttribute(getAttributeName("svg")),
  64. svgViewBox: el.getAttribute(getAttributeName("svgViewBox")),
  65. spinner: el.getAttribute(getAttributeName("spinner")),
  66. background: el.getAttribute(getAttributeName("background")),
  67. customClass: el.getAttribute(getAttributeName("customClass"))
  68. });
  69. }
  70. },
  71. unmounted(el) {
  72. var _a;
  73. (_a = el[INSTANCE_KEY]) == null ? void 0 : _a.instance.close();
  74. el[INSTANCE_KEY] = null;
  75. }
  76. };
  77. vLoading._context = null;
  78. exports["default"] = vLoading;
  79. //# sourceMappingURL=directive.js.map