vuestic-ui
Version:
Vue 3 UI Framework
42 lines (41 loc) • 1.4 kB
JavaScript
import { getCurrentInstance, unref } from "vue";
import { i as isDev } from "../utils/env.mjs";
const OPTIONS_LIST = {
props: "prop",
attrs: "prop",
slots: "slot"
};
const useDeprecated = (deprecatedList, deprecationSource = ["props", "attrs"]) => {
if (!isDev) {
return void 0;
}
const instance = getCurrentInstance();
if (!instance) {
throw new Error("`useDeprecated` hook must be used only inside of setup function!");
}
const instanceName = instance.type.name;
const deprecatedItems = unref(deprecatedList);
deprecationSource.every((source) => {
var _a;
const option = OPTIONS_LIST[source];
const throwWarning = (key) => console.warn(`The '${key}' ${option} (${instanceName} component) is deprecated! Please, check the documentation.`);
if (source === "props") {
const propsOptions = ((_a = instance.propsOptions) == null ? void 0 : _a[0]) || {};
const propsValues = instance.props || {};
deprecatedItems.forEach((propName) => {
propsOptions[propName] && propsValues[propName] !== propsOptions[propName].default && throwWarning(propName);
});
return true;
}
Object.keys({ ...instance[source] }).forEach((key) => {
if (deprecatedItems.includes(key)) {
throwWarning(key);
}
});
return true;
});
};
export {
useDeprecated as u
};
//# sourceMappingURL=useDeprecated.mjs.map