UNPKG

@extclp/vexip-ui

Version:

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

1 lines 2.71 kB
{"version":3,"file":"directive.mjs","sources":["../../../components/spin/directive.ts"],"sourcesContent":["import { Spin } from '@/components/spin'\r\n\r\nimport { createVNode, nextTick, render } from 'vue'\r\n\r\nimport { isObject } from '@vexip-ui/utils'\r\n\r\nimport type { ObjectDirective, VNode } from 'vue'\r\n\r\ninterface LoadingRecord {\r\n spin: VNode,\r\n props: any,\r\n originPosition: string,\r\n}\r\n\r\nexport const loading: ObjectDirective<HTMLElement & { __loading?: LoadingRecord }, any> = {\r\n mounted(el, binding) {\r\n nextTick(() => {\r\n const props = isObject(binding.value)\r\n ? { ...binding.value }\r\n : ({ active: binding.value } as any)\r\n\r\n props.inner = true\r\n\r\n const spin = createVNode(Spin, props, null, 0, Object.keys(props))\r\n const position = getComputedStyle(el).position\r\n\r\n el.__loading = {\r\n spin,\r\n props,\r\n originPosition: position,\r\n }\r\n\r\n if (position === 'static') {\r\n el.style.position = 'relative'\r\n }\r\n\r\n render(spin, el)\r\n })\r\n },\r\n updated(el, binding) {\r\n nextTick(() => {\r\n if (!el.__loading) return\r\n\r\n const props = isObject(binding.value) ? binding.value : { active: binding.value }\r\n const component = el.__loading.spin.component\r\n\r\n if (component) {\r\n Object.keys(props).forEach(key => {\r\n component.props[key] = props[key]\r\n })\r\n\r\n component.props.inner = true\r\n }\r\n })\r\n },\r\n beforeUnmount(el) {\r\n if (!el.__loading) return\r\n\r\n render(null, el)\r\n delete el.__loading\r\n },\r\n}\r\n"],"names":["loading","el","binding","nextTick","props","isObject","spin","createVNode","Spin","position","render","component","key"],"mappings":";;;;AAcO,MAAMA,IAA6E;AAAA,EACxF,QAAQC,GAAIC,GAAS;AACnB,IAAAC,EAAS,MAAM;AACb,YAAMC,IAAQC,EAASH,EAAQ,KAAK,IAChC,EAAE,GAAGA,EAAQ,MAAM,IAClB,EAAE,QAAQA,EAAQ,MAAM;AAE7B,MAAAE,EAAM,QAAQ;AAER,YAAAE,IAAOC,EAAYC,GAAMJ,GAAO,MAAM,GAAG,OAAO,KAAKA,CAAK,CAAC,GAC3DK,IAAW,iBAAiBR,CAAE,EAAE;AAEtC,MAAAA,EAAG,YAAY;AAAA,QACb,MAAAK;AAAA,QACA,OAAAF;AAAA,QACA,gBAAgBK;AAAA,MAClB,GAEIA,MAAa,aACfR,EAAG,MAAM,WAAW,aAGtBS,EAAOJ,GAAML,CAAE;AAAA,IAAA,CAChB;AAAA,EACH;AAAA,EACA,QAAQA,GAAIC,GAAS;AACnB,IAAAC,EAAS,MAAM;AACT,UAAA,CAACF,EAAG,UAAW;AAEb,YAAAG,IAAQC,EAASH,EAAQ,KAAK,IAAIA,EAAQ,QAAQ,EAAE,QAAQA,EAAQ,MAAM,GAC1ES,IAAYV,EAAG,UAAU,KAAK;AAEpC,MAAIU,MACF,OAAO,KAAKP,CAAK,EAAE,QAAQ,CAAOQ,MAAA;AAChC,QAAAD,EAAU,MAAMC,CAAG,IAAIR,EAAMQ,CAAG;AAAA,MAAA,CACjC,GAEDD,EAAU,MAAM,QAAQ;AAAA,IAC1B,CACD;AAAA,EACH;AAAA,EACA,cAAcV,GAAI;AACZ,IAACA,EAAG,cAERS,EAAO,MAAMT,CAAE,GACf,OAAOA,EAAG;AAAA,EAAA;AAEd;"}