Chip.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _react = _interopRequireDefault(require("react"));
  7. var _modularityFront = _interopRequireDefault(require("modularity-front"));
  8. var _Chip = _interopRequireDefault(require("@material-ui/core/Chip"));
  9. require("./chip.css");
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  19. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  20. var Module = _modularityFront.default.Module;
  21. var chipTypes = ['manytomany', 'exact', 'onetoone'];
  22. var ChipModule =
  23. /*#__PURE__*/
  24. function (_Modularity$Module) {
  25. _inherits(ChipModule, _Modularity$Module);
  26. function ChipModule(props) {
  27. _classCallCheck(this, ChipModule);
  28. return _possibleConstructorReturn(this, _getPrototypeOf(ChipModule).call(this, props));
  29. }
  30. _createClass(ChipModule, [{
  31. key: "removeChip",
  32. value: function removeChip(filter, key) {
  33. var values = filter.values || [];
  34. if (key) {
  35. var indx = values.indexOf(key);
  36. indx > -1 && values.splice(indx, 1);
  37. filter.values = values;
  38. } else {
  39. // range specific
  40. delete filter.values;
  41. filter.reset && filter.reset();
  42. }
  43. this.chips = this.chips.map(function (item) {
  44. return item.name === filter.name ? filter : item;
  45. });
  46. this.Filters.set(this.chips);
  47. }
  48. }, {
  49. key: "render",
  50. value: function render() {
  51. var _this = this;
  52. this.chips = this.Inputs.value || [];
  53. var chipsView = this.chips.map(function (filter, index) {
  54. var options = filter.options || {};
  55. if (chipTypes.includes(filter.type)) {
  56. return (filter.values || []).map(function (key, index) {
  57. return _react.default.createElement(_Chip.default, {
  58. key: key,
  59. label: options[key],
  60. className: "custom_chip",
  61. onDelete: function onDelete() {
  62. return _this.removeChip(filter, key);
  63. }
  64. });
  65. });
  66. } else if (filter.type === "range" && filter.values) {
  67. return _react.default.createElement(_Chip.default, {
  68. key: "range" + filter.values[0] + filter.values[1],
  69. label: filter.values[0] + " - " + filter.values[1],
  70. className: "custom_chip",
  71. onDelete: function onDelete() {
  72. return _this.removeChip(filter);
  73. }
  74. });
  75. } else {
  76. return null;
  77. }
  78. });
  79. return _react.default.createElement("div", null, chipsView);
  80. }
  81. }]);
  82. return ChipModule;
  83. }(_modularityFront.default.Module);
  84. ChipModule.Inputs = {
  85. Inputs: {
  86. type: Module.Types.Array,
  87. arrType: Module.Types.Object
  88. }
  89. };
  90. ChipModule.Outputs = {
  91. Filters: {}
  92. };
  93. ChipModule.EditPosition = "center";
  94. ChipModule.Category = "sxoinas";
  95. var _default = ChipModule;
  96. exports.default = _default;