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.

0 lines
8.3 KiB

3 months ago
  1. {"ast":null,"code":"import { isRef, ref } from 'vue';\nimport { Loading } from './service.mjs';\nimport { isObject, hyphenate, isString } from '@vue/shared';\nconst INSTANCE_KEY = Symbol(\"ElLoading\");\nconst createInstance = (el, binding) => {\n var _a, _b, _c, _d;\n const vm = binding.instance;\n const getBindingProp = key => isObject(binding.value) ? binding.value[key] : void 0;\n const resolveExpression = key => {\n const data = isString(key) && (vm == null ? void 0 : vm[key]) || key;\n if (data) return ref(data);else return data;\n };\n const getProp = name => resolveExpression(getBindingProp(name) || el.getAttribute(`element-loading-${hyphenate(name)}`));\n const fullscreen = (_a = getBindingProp(\"fullscreen\")) != null ? _a : binding.modifiers.fullscreen;\n const options = {\n text: getProp(\"text\"),\n svg: getProp(\"svg\"),\n svgViewBox: getProp(\"svgViewBox\"),\n spinner: getProp(\"spinner\"),\n background: getProp(\"background\"),\n customClass: getProp(\"customClass\"),\n fullscreen,\n target: (_b = getBindingProp(\"target\")) != null ? _b : fullscreen ? void 0 : el,\n body: (_c = getBindingProp(\"body\")) != null ? _c : binding.modifiers.body,\n lock: (_d = getBindingProp(\"lock\")) != null ? _d : binding.modifiers.lock\n };\n el[INSTANCE_KEY] = {\n options,\n instance: Loading(options)\n };\n};\nconst updateOptions = (newOptions, originalOptions) => {\n for (const key of Object.keys(originalOptions)) {\n if (isRef(originalOptions[key])) originalOptions[key].value = newOptions[key];\n }\n};\nconst vLoading = {\n mounted(el, binding) {\n if (binding.value) {\n createInstance(el, binding);\n }\n },\n updated(el, binding) {\n const instance = el[INSTANCE_KEY];\n if (binding.oldValue !== binding.value) {\n if (binding.value && !binding.oldValue) {\n createInstance(el, binding);\n } else if (binding.value && binding.oldValue) {\n if (isObject(binding.value)) updateOptions(binding.value, instance.options);\n } else {\n instance == null ? void 0 : instance.instance.close();\n }\n }\n },\n unmounted(el) {\n var _a;\n (_a = el[INSTANCE_KEY]) == null ? void 0 : _a.instance.close();\n el[INSTANCE_KEY] = null;\n }\n};\nexport { vLoading };","map":{"version":3,"names":["INSTANCE_KEY","Symbol","createInstance","el","binding","_a","_b","_c","_d","vm","instance","getBindingProp","key","isObject","value","resolveExpression","data","isString","ref","getProp","name","getAttribute","hyphenate","fullscreen","modifiers","options","text","svg","svgViewBox","spinner","background","customClass","target","body","lock","Loading","updateOptions","newOptions","originalOptions","Object","keys","isRef","vLoading","mounted","updated","oldValue","close","unmounted"],"sources":["../../../../../../packages/components/loading/src/directive.ts"],"sourcesContent":["// @ts-nocheck\nimport { isRef, ref } from 'vue'\nimport { hyphenate, isObject, isString } from '@element-plus/utils'\nimport { Loading } from './service'\nimport type { Directive, DirectiveBinding, UnwrapRef } from 'vue'\nimport type { LoadingOptions } from './types'\nimport type { LoadingInstance } from './loading'\n\nconst INSTANCE_KEY = Symbol('ElLoading')\n\nexport type LoadingBinding = boolean | UnwrapRef<LoadingOptions>\nexport interface ElementLoading extends HTMLElement {\n [INSTANCE_KEY]?: {\n instance: LoadingInstance\n options: LoadingOptions\n }\n}\n\nconst createInstance = (\n el: ElementLoading,\n binding: DirectiveBinding<LoadingBinding>\n) => {\n const vm = binding.instance\n\n const getBindingProp = <K extends keyof LoadingOptions>(\n key: K\n ): LoadingOptions[K] =>\n isObject(binding.value) ? binding.value[key] : undefined\n\n const resolveExpression = (key: any) => {\n const data = (isString(key) && vm?.[key]) || key\n if (data) return ref(data)\n else return data\n }\n\n const getProp = <K extends keyof LoadingOptions>(name: K) =>\n resolveExpression(\n getBindingProp(name) ||\n el.g