a32952799220b7f4dc09eb2c03c3bd42863b44479b6dd641f29a88f20467414474e25df18b1406c93fc37d0c388c60da27f7a1e29a9bea0c1103529f10935d 2.7 KB

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