component.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. mixins: 'behaviors',
  18. methods: 'methods',
  19. beforeCreate: 'created',
  20. created: 'attached',
  21. mounted: 'ready',
  22. destroyed: 'detached',
  23. classes: 'externalClasses',
  24. });
  25. // add default externalClasses
  26. options.externalClasses = options.externalClasses || [];
  27. options.externalClasses.push('custom-class');
  28. // add default behaviors
  29. options.behaviors = options.behaviors || [];
  30. options.behaviors.push(basic_1.basic);
  31. // add relations
  32. var relation = vantOptions.relation;
  33. if (relation) {
  34. options.relations = relation.relations;
  35. options.behaviors.push(relation.mixin);
  36. }
  37. // map field to form-field behavior
  38. if (vantOptions.field) {
  39. options.behaviors.push('wx://form-field');
  40. }
  41. // add default options
  42. options.options = {
  43. multipleSlots: true,
  44. addGlobalClass: true,
  45. };
  46. Component(options);
  47. }
  48. exports.VantComponent = VantComponent;