component.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.VantComponent = void 0;
  4. var basic_1 = require("../mixins/basic");
  5. function mapKeys(source, target, map) {
  6. Object.keys(map).forEach(function (key) {
  7. if (source[key]) {
  8. target[map[key]] = source[key];
  9. }
  10. });
  11. }
  12. function VantComponent(vantOptions) {
  13. var options = {};
  14. mapKeys(vantOptions, options, {
  15. data: 'data',
  16. props: 'properties',
  17. watch: 'observers',
  18. mixins: 'behaviors',
  19. methods: 'methods',
  20. beforeCreate: 'created',
  21. created: 'attached',
  22. mounted: 'ready',
  23. destroyed: 'detached',
  24. classes: 'externalClasses',
  25. });
  26. // add default externalClasses
  27. options.externalClasses = options.externalClasses || [];
  28. options.externalClasses.push('custom-class');
  29. // add default behaviors
  30. options.behaviors = options.behaviors || [];
  31. options.behaviors.push(basic_1.basic);
  32. // add relations
  33. var relation = vantOptions.relation;
  34. if (relation) {
  35. options.relations = relation.relations;
  36. options.behaviors.push(relation.mixin);
  37. }
  38. // map field to form-field behavior
  39. if (vantOptions.field) {
  40. options.behaviors.push('wx://form-field');
  41. }
  42. // add default options
  43. options.options = {
  44. multipleSlots: true,
  45. addGlobalClass: true,
  46. };
  47. Component(options);
  48. }
  49. exports.VantComponent = VantComponent;