UNPKG

mldong-flow-designer-plus

Version:

本项目包含了作者为B站课堂视频[《工作流设计器开发最佳实践》](https://www.bilibili.com/cheese/play/ss24484)的过程源码。教程中开发的组件也可用于实际生产环境中。以下是和使用文档和课程章节说明。 ## 演示地址 本工程提供两个演示站,分别覆盖库本身和真实业务集成两种形态:

82 lines (81 loc) 3.27 kB
import { k as keysOf } from "./objects-CozeWXQE.js"; import { u as useNamespace, g as debugWarn, A as namespaceContextKey } from "./error-DnK9DIl5.js"; import { u as useLocale, l as localeContextKey, e as emptyValuesContextKey } from "./index-C8K9SHVe.js"; import { u as useZIndex, d as defaultInitialZIndex, z as zIndexContextKey } from "./index-F4uefAAR.js"; import { S as SIZE_INJECTION_KEY } from "./style-1lZfUlv4.js"; import { getCurrentInstance, inject, computed, ref, unref, provide } from "vue"; import { h as isNil } from "./index-aCfw1Ky1.js"; const configProviderContextKey = Symbol(); const globalConfig = ref(); function useGlobalConfig(key, defaultValue = void 0) { const config = getCurrentInstance() ? inject(configProviderContextKey, globalConfig) : globalConfig; if (key) return computed(() => { var _a; return ((_a = config.value) == null ? void 0 : _a[key]) ?? defaultValue; }); else return config; } function useGlobalComponentSettings(block, sizeFallback) { const config = useGlobalConfig(); const ns = useNamespace(block, computed(() => { var _a; return ((_a = config.value) == null ? void 0 : _a.namespace) || "el"; })); const locale = useLocale(computed(() => { var _a; return (_a = config.value) == null ? void 0 : _a.locale; })); const zIndex = useZIndex(computed(() => { var _a; const zIndex2 = (_a = config.value) == null ? void 0 : _a.zIndex; return isNil(zIndex2) || Number.isNaN(zIndex2) ? defaultInitialZIndex : zIndex2; })); const size = computed(() => { var _a; return unref(sizeFallback) || ((_a = config.value) == null ? void 0 : _a.size) || ""; }); provideGlobalConfig(computed(() => unref(config) || {})); return { ns, locale, zIndex, size }; } const provideGlobalConfig = (config, app, global = false) => { const inSetup = !!getCurrentInstance(); const oldConfig = inSetup ? useGlobalConfig() : void 0; const provideFn = inSetup ? provide : void 0; if (!provideFn) { debugWarn("provideGlobalConfig", "provideGlobalConfig() can only be used inside setup()."); return; } const context = computed(() => { const cfg = unref(config); if (!(oldConfig == null ? void 0 : oldConfig.value)) return cfg; return mergeConfig(oldConfig.value, cfg); }); provideFn(configProviderContextKey, context); provideFn(localeContextKey, computed(() => context.value.locale)); provideFn(namespaceContextKey, computed(() => context.value.namespace)); provideFn(zIndexContextKey, computed(() => context.value.zIndex)); provideFn(SIZE_INJECTION_KEY, { size: computed(() => context.value.size || "") }); provideFn(emptyValuesContextKey, computed(() => ({ emptyValues: context.value.emptyValues, valueOnClear: context.value.valueOnClear }))); if (global || !globalConfig.value) globalConfig.value = context.value; return context; }; const mergeConfig = (a, b) => { const keys = [.../* @__PURE__ */ new Set([...keysOf(a), ...keysOf(b)])]; const obj = {}; for (const key of keys) obj[key] = b[key] !== void 0 ? b[key] : a[key]; return obj; }; export { useGlobalComponentSettings as a, provideGlobalConfig as p, useGlobalConfig as u }; //# sourceMappingURL=use-global-config-Bm7GF3Cr.js.map