UNPKG

vuestic-ui

Version:
52 lines (51 loc) 2.32 kB
import { u as useLocalConfig } from "../../../composables/useLocalConfig.js"; import { computed } from "vue"; import { i as injectChildPropsFromParent } from "../../../composables/useChildComponents.js"; import { n as notNil } from "../../../utils/isNilValue.js"; import { u as useGlobalConfig } from "../../../composables/useGlobalConfig.js"; const withPresetProp = (props) => "preset" in props; const getPresetProp = (props) => withPresetProp(props) ? props.preset : void 0; const useComponentConfigProps = (component, originalProps) => { const localConfig = useLocalConfig(); const { globalConfig } = useGlobalConfig(); const componentName = component.name; const getPresetProps = (presetPropValue) => { return (presetPropValue instanceof Array ? presetPropValue : [presetPropValue]).reduce((acc, presetName) => { var _a, _b, _c; const presetProps = (_c = (_b = (_a = globalConfig.value.components) == null ? void 0 : _a.presets) == null ? void 0 : _b[componentName]) == null ? void 0 : _c[presetName]; if (!presetProps) { return acc; } const extendedPresets = getPresetProp(presetProps); return { ...acc, ...extendedPresets ? getPresetProps(extendedPresets) : void 0, ...presetProps }; }, {}); }; const parentInjectedProps = injectChildPropsFromParent(); return computed(() => { var _a, _b; const globalConfigProps = { ...(_a = globalConfig.value.components) == null ? void 0 : _a.all, ...(_b = globalConfig.value.components) == null ? void 0 : _b[componentName] }; const localConfigProps = localConfig.value.reduce((finalConfig, config) => { const componentConfigProps = config[componentName]; return componentConfigProps ? { ...finalConfig, ...componentConfigProps } : finalConfig; }, {}); const presetProp = [ originalProps, parentInjectedProps == null ? void 0 : parentInjectedProps.value, localConfigProps, globalConfigProps ].filter(notNil).map(getPresetProp).filter(notNil).at(0); const presetProps = presetProp ? getPresetProps(presetProp) : void 0; return { ...globalConfigProps, ...localConfigProps, ...presetProps }; }); }; export { useComponentConfigProps as u }; //# sourceMappingURL=use-component-config-props.js.map