component.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var basic_1 = require("../mixins/basic");
  4. var index_1 = require("../mixins/observer/index");
  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 _a;
  14. if (vantOptions === void 0) { vantOptions = {}; }
  15. var options = {};
  16. mapKeys(vantOptions, options, {
  17. data: 'data',
  18. props: 'properties',
  19. mixins: 'behaviors',
  20. methods: 'methods',
  21. beforeCreate: 'created',
  22. created: 'attached',
  23. mounted: 'ready',
  24. relations: 'relations',
  25. destroyed: 'detached',
  26. classes: 'externalClasses'
  27. });
  28. var relation = vantOptions.relation;
  29. if (relation) {
  30. options.relations = Object.assign(options.relations || {}, (_a = {},
  31. _a["../" + relation.name + "/index"] = relation,
  32. _a));
  33. }
  34. // add default externalClasses
  35. options.externalClasses = options.externalClasses || [];
  36. options.externalClasses.push('custom-class');
  37. // add default behaviors
  38. options.behaviors = options.behaviors || [];
  39. options.behaviors.push(basic_1.basic);
  40. // map field to form-field behavior
  41. if (vantOptions.field) {
  42. options.behaviors.push('wx://form-field');
  43. }
  44. // add default options
  45. options.options = {
  46. multipleSlots: true,
  47. addGlobalClass: true
  48. };
  49. index_1.observe(vantOptions, options);
  50. Component(options);
  51. }
  52. exports.VantComponent = VantComponent;