vuestic-ui
Version:
Vue 3 UI Framework
1 lines • 2.54 kB
Source Map (JSON)
{"version":3,"file":"useDeprecated.mjs","sources":["../../../../src/composables/useDeprecated.ts"],"sourcesContent":["import { unref, Ref, getCurrentInstance } from 'vue'\n\nimport { isDev } from '../utils/env'\n\ntype DeprecationSource = 'slots' | 'props' | 'attrs'\n\nconst OPTIONS_LIST: Record<DeprecationSource, string> = {\n props: 'prop',\n attrs: 'prop',\n slots: 'slot',\n}\n\nexport const useDeprecated = (\n deprecatedList: Ref<string[]> | string[],\n deprecationSource: DeprecationSource[] = ['props', 'attrs'],\n) => {\n if (!isDev) { return undefined }\n\n const instance = getCurrentInstance()\n\n if (!instance) {\n throw new Error('`useDeprecated` hook must be used only inside of setup function!')\n }\n\n const instanceName = instance.type.name\n const deprecatedItems = unref(deprecatedList)\n\n deprecationSource.every((source) => {\n const option = OPTIONS_LIST[source]\n\n const throwWarning = (key: string) =>\n console.warn(`The '${key}' ${option} (${instanceName} component) is deprecated! Please, check the documentation.`)\n\n if (source === 'props') {\n const propsOptions = (instance as any).propsOptions?.[0] || {}\n const propsValues = instance.props || {}\n\n // checking if default prop value isn't equal to the current one -> it's deprecated and used\n deprecatedItems.forEach((propName) => {\n propsOptions[propName] && (propsValues[propName] !== propsOptions[propName].default) && throwWarning(propName)\n })\n\n return true\n }\n\n Object.keys({ ...instance[source] }).forEach((key) => {\n if (deprecatedItems.includes(key)) { throwWarning(key) }\n })\n\n return true\n })\n}\n"],"names":[],"mappings":";;AAMA,MAAM,eAAkD;AAAA,EACtD,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACT;AAEO,MAAM,gBAAgB,CAC3B,gBACA,oBAAyC,CAAC,SAAS,OAAO,MACvD;AACH,MAAI,CAAC,OAAO;AAAS,WAAA;AAAA,EAAU;AAE/B,QAAM,WAAW;AAEjB,MAAI,CAAC,UAAU;AACP,UAAA,IAAI,MAAM,kEAAkE;AAAA,EACpF;AAEM,QAAA,eAAe,SAAS,KAAK;AAC7B,QAAA,kBAAkB,MAAM,cAAc;AAE1B,oBAAA,MAAM,CAAC,WAAW;;AAC5B,UAAA,SAAS,aAAa,MAAM;AAE5B,UAAA,eAAe,CAAC,QACpB,QAAQ,KAAK,QAAQ,GAAG,KAAK,MAAM,KAAK,YAAY,6DAA6D;AAEnH,QAAI,WAAW,SAAS;AACtB,YAAM,iBAAgB,cAAiB,iBAAjB,mBAAgC,OAAM,CAAA;AACtD,YAAA,cAAc,SAAS,SAAS;AAGtB,sBAAA,QAAQ,CAAC,aAAa;AACvB,qBAAA,QAAQ,KAAM,YAAY,QAAQ,MAAM,aAAa,QAAQ,EAAE,WAAY,aAAa,QAAQ;AAAA,MAAA,CAC9G;AAEM,aAAA;AAAA,IACT;AAEO,WAAA,KAAK,EAAE,GAAG,SAAS,MAAM,GAAG,EAAE,QAAQ,CAAC,QAAQ;AAChD,UAAA,gBAAgB,SAAS,GAAG,GAAG;AAAE,qBAAa,GAAG;AAAA,MAAE;AAAA,IAAA,CACxD;AAEM,WAAA;AAAA,EAAA,CACR;AACH;"}