@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
45 lines (42 loc) • 1.22 kB
JavaScript
'use client';
import { createContext, memo, use } from 'react';
import { genCdnUrl } from "../utils/genCdnUrl";
import { jsx as _jsx } from "react/jsx-runtime";
export var ConfigContext = /*#__PURE__*/createContext(null);
var ConfigProvider = /*#__PURE__*/memo(function (_ref) {
var children = _ref.children,
config = _ref.config;
return /*#__PURE__*/_jsx(ConfigContext, {
value: config,
children: children
});
});
// useCdnFn
var cdnFallback = function cdnFallback(_ref2) {
var pkg = _ref2.pkg,
version = _ref2.version,
path = _ref2.path;
return genCdnUrl({
path: path,
pkg: pkg,
proxy: 'aliyun',
version: version
});
};
export var useCdnFn = function useCdnFn() {
var config = use(ConfigContext);
if (!config) return cdnFallback;
if ((config === null || config === void 0 ? void 0 : config.proxy) !== 'custom') return function (_ref3) {
var pkg = _ref3.pkg,
version = _ref3.version,
path = _ref3.path;
return genCdnUrl({
path: path,
pkg: pkg,
proxy: config.proxy,
version: version
});
};
return (config === null || config === void 0 ? void 0 : config.customCdnFn) || cdnFallback;
};
export default ConfigProvider;