runtime.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var lodashUnified = require('lodash-unified');
  5. require('../../types.js');
  6. require('../../objects.js');
  7. var shared = require('@vue/shared');
  8. const epPropKey = "__epPropKey";
  9. const definePropType = (val) => val;
  10. const isEpProp = (val) => shared.isObject(val) && !!val[epPropKey];
  11. const buildProp = (prop, key) => {
  12. if (!shared.isObject(prop) || isEpProp(prop))
  13. return prop;
  14. const { values, required, default: defaultValue, type, validator } = prop;
  15. const _validator = values || validator ? (val) => {
  16. let valid = false;
  17. let allowedValues = [];
  18. if (values) {
  19. allowedValues = Array.from(values);
  20. if (shared.hasOwn(prop, "default")) {
  21. allowedValues.push(defaultValue);
  22. }
  23. valid || (valid = allowedValues.includes(val));
  24. }
  25. if (validator)
  26. valid || (valid = validator(val));
  27. if (!valid && allowedValues.length > 0) {
  28. const allowValuesText = [...new Set(allowedValues)].map((value) => JSON.stringify(value)).join(", ");
  29. vue.warn(`Invalid prop: validation failed${key ? ` for prop "${key}"` : ""}. Expected one of [${allowValuesText}], got value ${JSON.stringify(val)}.`);
  30. }
  31. return valid;
  32. } : void 0;
  33. const epProp = {
  34. type,
  35. required: !!required,
  36. validator: _validator,
  37. [epPropKey]: true
  38. };
  39. if (shared.hasOwn(prop, "default"))
  40. epProp.default = defaultValue;
  41. return epProp;
  42. };
  43. const buildProps = (props) => lodashUnified.fromPairs(Object.entries(props).map(([key, option]) => [
  44. key,
  45. buildProp(option, key)
  46. ]));
  47. exports.buildProp = buildProp;
  48. exports.buildProps = buildProps;
  49. exports.definePropType = definePropType;
  50. exports.epPropKey = epPropKey;
  51. exports.isEpProp = isEpProp;
  52. //# sourceMappingURL=runtime.js.map