{"version":3,"file":"directive.js","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\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\n) => {\n const vm = binding.instance\n\n const getBindingProp = (\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 = (name: K) =>\n resolveExpression(\n getBindingProp(name) ||\n el.getAttribute(`element-loading-${hyphenate(name)}`)\n )\n\n const fullscreen =\n getBindingProp('fullscreen') ?? binding.modifiers.fullscreen\n\n const options: LoadingOptions = {\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: getBindingProp('target') ?? (fullscreen ? undefined : el),\n body: getBindingProp('body') ?? binding.modifiers.body,\n lock: getBindingProp('lock') ?? binding.modifiers.lock,\n }\n el[INSTANCE_KEY] = {\n options,\n instance: Loading(options),\n }\n}\n\nconst updateOptions = (\n newOptions: UnwrapRef,\n originalOptions: LoadingOptions\n) => {\n for (const key of Object.keys(originalOptions)) {\n if (isRef(originalOptions[key]))\n originalOptions[key].value = newOptions[key]\n }\n}\n\nexport const vLoading: Directive = {\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))\n updateOptions(binding.value, instance!.options)\n } else {\n instance?.instance.close()\n }\n }\n },\n unmounted(el) {\n el[INSTANCE_KEY]?.instance.close()\n el[INSTANCE_KEY] = null\n },\n}\n"],"names":["isObject","isString","ref","hyphenate","Loading","isRef"],"mappings":";;;;;;;;;AAGA,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AACzC,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,OAAO,KAAK;AACxC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AACrB,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;AAC9B,EAAE,MAAM,cAAc,GAAG,CAAC,GAAG,KAAKA,eAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;AACxF,EAAE,MAAM,iBAAiB,GAAG,CAAC,GAAG,KAAK;AACrC,IAAI,MAAM,IAAI,GAAGC,eAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC;AACzE,IAAI,IAAI,IAAI;AACZ,MAAM,OAAOC,OAAG,CAAC,IAAI,CAAC,CAAC;AACvB;AACA,MAAM,OAAO,IAAI,CAAC;AAClB,GAAG,CAAC;AACJ,EAAE,MAAM,OAAO,GAAG,CAAC,IAAI,KAAK,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,CAAC,gBAAgB,EAAEC,gBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7H,EAAE,MAAM,UAAU,GAAG,CAAC,EAAE,GA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