UNPKG

vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

1 lines 3.21 kB
{"version":3,"file":"index.mjs","sources":["../../../directives/loading/index.ts"],"sourcesContent":["import { Spin } from '@/components/spin'\n\nimport { createVNode, nextTick, render } from 'vue'\n\nimport { isObject } from '@vexip-ui/utils'\n\nimport type { SpinProps } from '@/components/spin'\nimport type { DirectiveBinding, ObjectDirective, VNode } from 'vue'\n\ninterface LoadingRecord {\n spin: VNode,\n props: SpinProps,\n originPosition: string,\n}\n\ntype LoadingElement = HTMLElement & { __loading?: LoadingRecord }\n\nfunction createSpin(\n el: LoadingElement,\n binding: DirectiveBinding<boolean | SpinProps>,\n vnode: VNode<any, LoadingElement>,\n) {\n const props: SpinProps = isObject(binding.value)\n ? { ...binding.value }\n : { active: binding.value }\n\n props.inner = true\n\n const spin = createVNode(Spin, props, null, 0, Object.keys(props))\n const position = getComputedStyle(el).position\n\n spin.appContext = vnode.appContext ?? (vnode as any).ctx?.appContext\n\n el.__loading = {\n spin,\n props,\n originPosition: position,\n }\n\n if (position === 'static') {\n el.style.position = 'relative'\n }\n\n render(spin, el)\n}\n\nexport const vLoading: ObjectDirective<LoadingElement, boolean | SpinProps> = {\n mounted(el, binding, vnode) {\n nextTick(() => createSpin(el, binding, vnode))\n },\n updated(el, binding, vnode) {\n nextTick(() => {\n if (!el.__loading) {\n createSpin(el, binding, vnode)\n return\n }\n\n const props: SpinProps = isObject(binding.value) ? binding.value : { active: binding.value }\n const component = el.__loading.spin.component\n\n if (component) {\n Object.keys(props).forEach(key => {\n component.props[key] = props[key as keyof SpinProps]\n })\n\n component.props.inner = true\n }\n })\n },\n beforeUnmount(el) {\n if (!el.__loading) return\n\n render(null, el)\n delete el.__loading\n },\n}\n"],"names":["createSpin","el","binding","vnode","props","isObject","spin","createVNode","Spin","position","_a","render","vLoading","nextTick","component","key"],"mappings":";;;;AAiBA,SAASA,EACPC,GACAC,GACAC,GACA;;AACA,QAAMC,IAAmBC,EA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