vuestic-ui
Version:
Vue 3 UI Framework
1 lines • 2.13 kB
Source Map (JSON)
{"version":3,"file":"extract-component-options.mjs","sources":["../../../../../src/utils/component-options/extract-component-options.ts"],"sourcesContent":["import type { ExtractComponentEmits, ExtractComponentProps, DefineComponentOptions } from './types'\nimport { getComponentProps } from './resolve-component-props'\n\n/**\n * Returns component props options.\n *\n *\n * @param ignoreProps - deprecated - prefer using lodash omit instead\n *\n * @returns object that looks like this:\n * ```ts\n * {\n * modelValue: { type: String, required: true },\n * options: { type: Array, default: [] },\n * size: { type: String as PropType<'small' | 'medium' | 'large'>, default: 'medium' }\n * }\n * ```\n */\nexport function extractComponentProps<T, IgnoreProps extends string = ''> (component: T, ignoreProps?: IgnoreProps[]): Omit<ExtractComponentProps<T>, IgnoreProps> {\n const props: any = getComponentProps(component as any)\n\n // TODO: Not sure if it is a good idea to handle ignore props here\n // Looks like it is not type safe. Need a separated filter object function\n if (ignoreProps) {\n return Object\n .keys(props)\n .reduce<any>((acc, propName) => {\n if (ignoreProps.includes(propName as unknown as IgnoreProps)) { return acc }\n\n if (props[propName] === undefined) { return acc }\n\n acc[propName] = typeof props[propName] === 'string' ? {} : props[propName]\n\n return acc\n }, {})\n }\n\n return props\n}\n\n/** Returns component emits option */\nexport function extractComponentEmits<T> (component: T): ExtractComponentEmits<T> {\n return [...new Set((component as any).emits)] as any\n}\n"],"names":[],"mappings":";AAkBgB,SAAA,sBAA2D,WAAc,aAA0E;AAC3J,QAAA,QAAa,kBAAkB,SAAgB;AAIrD,MAAI,aAAa;AACf,WAAO,OACJ,KAAK,KAAK,EACV,OAAY,CAAC,KAAK,aAAa;AAC1B,UAAA,YAAY,SAAS,QAAkC,GAAG;AAAS,eAAA;AAAA,MAAI;AAEvE,UAAA,MAAM,QAAQ,MAAM,QAAW;AAAS,eAAA;AAAA,MAAI;AAE5C,UAAA,QAAQ,IAAI,OAAO,MAAM,QAAQ,MAAM,WAAW,CAAK,IAAA,MAAM,QAAQ;AAElE,aAAA;AAAA,IACT,GAAG,CAAE,CAAA;AAAA,EACT;AAEO,SAAA;AACT;AAGO,SAAS,sBAA0B,WAAwC;AAChF,SAAO,CAAC,GAAG,IAAI,IAAK,UAAkB,KAAK,CAAC;AAC9C;"}