UNPKG

yanzhen-design-vue

Version:

116 lines (115 loc) 3.42 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const vue = require("vue"); const utilsVue = require("@yanzhen-libs/utils-vue"); const antDesignVue = require("ant-design-vue"); const lodashEs = require("lodash-es"); const spin = require("./spin.cjs"); const setDefaultIndicator = require("./setDefaultIndicator.cjs"); const { ns } = spin.spinOptions; function useSpin(props, emit) { const _ref = vue.ref(); const spinId = vue.computed(() => props.name ?? Symbol("spin")); const [{ loading, refresh }, Loading] = utilsVue.useProvideLoading({ id: spinId, timeout: vue.computed(() => props.timeout) }); const slots = vue.useSlots(); const watcher = utilsVue.createWatcher(); const spinning = vue.computed(() => Boolean(props.spinning)); const tag = vue.computed(() => props.tag); const isNative = vue.computed(() => { if (lodashEs.isBoolean(utilsVue.unref(tag))) { return false; } return utilsVue.unref(tag) === "spin"; }); watcher.set("loading", { source: () => utilsVue.unref(spinning), handler(value) { loading.value = value; }, immediate: true, debounce: 0 }); const config = vue.computed(() => lodashEs.pick(props, Object.keys(spin.AntSpin.props))); const proxyProps = utilsVue.useProxyProps(config, spin.AntSpin.emits, { emit, exclude: ["spinning"], filter: true }); function Indicator(_props) { if (lodashEs.isFunction(slots.indicator)) { return slots.indicator(_props); } if (vue.isVNode(props.indicator)) { return vue.h(props.indicator, _props); } const { indicator } = setDefaultIndicator.getDefaultIndicator(); if (lodashEs.isFunction(indicator)) { return indicator(_props); } return void 0; } function Tip(_props) { if (lodashEs.isFunction(slots.tip)) { return slots.tip(_props); } if (vue.isVNode(props.tip)) { return vue.h(props.tip, _props); } return props.tip; } vue.onUnmounted(() => { watcher.stop(); }); const exposeCtx = new Proxy( { refresh }, { get(target, p, receiver) { return Reflect.get(target, p, receiver); } } ); return [ { _ref, Indicator, Tip, exposeCtx }, (props2) => { const children = { loading: (props3) => { const renderDefault = utilsVue.unref(isNative) && (slots == null ? void 0 : slots.default) ? vue.withCtx(slots == null ? void 0 : slots.default) : vue.h("div", { style: { height: "100%" } }); return vue.h( antDesignVue.Spin, vue.mergeProps( { wrapperClassName: ns.b("wrapper"), class: [ns.b()] }, utilsVue.unref(proxyProps), props3 ?? {}, { ref: _ref, spinning: utilsVue.unref(isNative) ? utilsVue.unref(spinning) : true } ), { indicator: vue.withCtx(Indicator), tip: vue.withCtx(Tip), default: renderDefault } ); } }; if (utilsVue.unref(isNative)) { return children == null ? void 0 : children.loading(utilsVue.unref(proxyProps)); } return Loading(props2, children); } ]; } exports.useSpin = useSpin;