You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
7.6 KiB

3 months ago
{"ast":null,"code":"import \"core-js/modules/es.array.push.js\";\nimport \"core-js/modules/es.set.difference.v2.js\";\nimport \"core-js/modules/es.set.intersection.v2.js\";\nimport \"core-js/modules/es.set.is-disjoint-from.v2.js\";\nimport \"core-js/modules/es.set.is-subset-of.v2.js\";\nimport \"core-js/modules/es.set.is-superset-of.v2.js\";\nimport \"core-js/modules/es.set.symmetric-difference.v2.js\";\nimport \"core-js/modules/es.set.union.v2.js\";\nimport { warn } from 'vue';\nimport { fromPairs } from 'lodash-unified';\nimport '../../types.mjs';\nimport '../../objects.mjs';\nimport { isObject, hasOwn } from '@vue/shared';\nconst epPropKey = \"__epPropKey\";\nconst definePropType = val => val;\nconst isEpProp = val => isObject(val) && !!val[epPropKey];\nconst buildProp = (prop, key) => {\n if (!isObject(prop) || isEpProp(prop)) return prop;\n const {\n values,\n required,\n default: defaultValue,\n type,\n validator\n } = prop;\n const _validator = values || validator ? val => {\n let valid = false;\n let allowedValues = [];\n if (values) {\n allowedValues = Array.from(values);\n if (hasOwn(prop, \"default\")) {\n allowedValues.push(defaultValue);\n }\n valid || (valid = allowedValues.includes(val));\n }\n if (validator) valid || (valid = validator(val));\n if (!valid && allowedValues.length > 0) {\n const allowValuesText = [...new Set(allowedValues)].map(value => JSON.stringify(value)).join(\", \");\n warn(`Invalid prop: validation failed${key ? ` for prop \"${key}\"` : \"\"}. Expected one of [${allowValuesText}], got value ${JSON.stringify(val)}.`);\n }\n return valid;\n } : void 0;\n const epProp = {\n type,\n required: !!required,\n validator: _validator,\n [epPropKey]: true\n };\n if (hasOwn(prop, \"default\")) epProp.default = defaultValue;\n return epProp;\n};\nconst buildProps = props => fromPairs(Object.entries(props).map(([key, option]) => [key, buildProp(option, key)]));\nexport { buildProp, buildProps, definePropType, epPropKey, isEpProp };","map":{"version":3,"names":["epPropKey","definePropType","val","isEpProp","isObject","buildProp","prop","key","values","required","default","defaultValue","type","validator","_validator","valid","allowedValues","Array","from","hasOwn","push","includes","length","allowValuesText","Set","map","value","JSON","stringify","join","warn","epProp","buildProps","props","fromPairs","Object","entries","option"],"sources":["../../../../../../packages/utils/vue/props/runtime.ts"],"sourcesContent":["import { warn } from 'vue'\nimport { fromPairs } from 'lodash-unified'\nimport { isObject } from '../../types'\nimport { hasOwn } from '../../objects'\n\nimport type { PropType } from 'vue'\nimport type {\n EpProp,\n EpPropConvert,\n EpPropFinalized,\n EpPropInput,\n EpPropMergeType,\n IfEpProp,\n IfNativePropType,\n NativePropType,\n} from './types'\n\nexport const epPropKey = '__epPropKey'\n\nexport const definePropType = <T>(val: any): PropType<T> => val\n\nexport const isEpProp = (val: unknown): val is EpProp<any, any, any> =>\n isObject(val) && !!(val as any)[epPropKey]\n\n/**\n * @description Build prop. It can better optimize prop types\n * @description prop\n * @example\n // limited options\n // the type will be PropType<'light' | 'dark'>\n buildProp({\n type: String,\n values: ['light', 'dark'],\n } as const)\n * @example\n // limited options and other types\n // the type will be PropType<'small' | 'large' | number>\n buildProp({\n type: [String, Number],\n values: ['small', 'large'],\n validator: (val: unknown): val is number => typeof val === 'number',\n } as const)\n @link see more: https://github.com/element-plus/element-plus/pull/3341\n */\nexport const buildProp = <\n Type = never,\n Value = never,\n Validator = never,\n Default extends EpPropMergeType<Type, Value, Validator> = never,\n Required extends boolean = false\n>(\n prop: EpPropInput<Type, Value, Validator, Default, Required>,\n key?: string\n)