searchbar.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _react = _interopRequireWildcard(require("react"));
  7. var _reactMaterialize = require("react-materialize");
  8. var _MyAutocomplete = _interopRequireDefault(require("./MyAutocomplete"));
  9. var _modularityFront = _interopRequireDefault(require("modularity-front"));
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  12. 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); }
  13. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14. 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); } }
  15. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  19. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  20. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  21. 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); }
  22. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  23. var Module = _modularityFront.default.Module;
  24. var SearchBarModule =
  25. /*#__PURE__*/
  26. function (_Modularity$Module) {
  27. _inherits(SearchBarModule, _Modularity$Module);
  28. function SearchBarModule(props) {
  29. _classCallCheck(this, SearchBarModule);
  30. return _possibleConstructorReturn(this, _getPrototypeOf(SearchBarModule).call(this, props));
  31. }
  32. _createClass(SearchBarModule, [{
  33. key: "_complete",
  34. value: function _complete(value, obj) {
  35. if (value === undefined) return;
  36. this.SearchData.set(value);
  37. this.ObjectData.set(obj);
  38. if (this.Route.value && this.Redirect.value) {
  39. this.CoreSystem.go("/search/" + value);
  40. }
  41. }
  42. }, {
  43. key: "render",
  44. value: function render() {
  45. var _this = this;
  46. var options = {
  47. data: this.Data.value,
  48. limit: 5
  49. };
  50. return _react.default.createElement("div", {
  51. className: 'SearchBar ' + this.props.className
  52. }, _react.default.createElement(_reactMaterialize.Icon, null, "search"), _react.default.createElement(_MyAutocomplete.default, {
  53. data: this.Data.value,
  54. onChange: function onChange(v) {
  55. return _this.Text.set(v.target.value);
  56. },
  57. placeholder: this.SearchBar.value.placeholder,
  58. options: options,
  59. value: this.SearchBar.value.defaultValue,
  60. onComplete: function onComplete(v, o) {
  61. return _this._complete(v, o);
  62. }
  63. }), _get(_getPrototypeOf(SearchBarModule.prototype), "render", this).call(this));
  64. }
  65. }]);
  66. return SearchBarModule;
  67. }(_modularityFront.default.Module); // Not used anymore
  68. var AutocompleteNew =
  69. /*#__PURE__*/
  70. function (_Autocomplete) {
  71. _inherits(AutocompleteNew, _Autocomplete);
  72. function AutocompleteNew(props) {
  73. _classCallCheck(this, AutocompleteNew);
  74. return _possibleConstructorReturn(this, _getPrototypeOf(AutocompleteNew).call(this, props));
  75. }
  76. _createClass(AutocompleteNew, [{
  77. key: "componentWillReceiveProps",
  78. value: function componentWillReceiveProps(props) {
  79. if (this.instance) {
  80. this.instance.updateData(props.options.data);
  81. }
  82. if (props.value !== this.props.value) {
  83. this.setState({
  84. value: props.value
  85. });
  86. }
  87. }
  88. }]);
  89. return AutocompleteNew;
  90. }(_reactMaterialize.Autocomplete);
  91. SearchBarModule.EditPosition = "top-right";
  92. SearchBarModule.Inputs = {
  93. SearchBar: {
  94. type: Module.Types.Object,
  95. defaultValue: {
  96. placeholder: "Search"
  97. }
  98. },
  99. Data: {
  100. type: Module.Types.Object,
  101. defaultValue: {
  102. 'Apple': null,
  103. 'Microsoft': null,
  104. 'Google': 'http://placehold.it/250x250'
  105. }
  106. },
  107. Redirect: {
  108. type: Module.Types.Boolean,
  109. defaultValue: false
  110. },
  111. Route: {
  112. type: Module.Types.Text,
  113. defaultValue: 'search'
  114. }
  115. };
  116. SearchBarModule.Outputs = {
  117. SearchData: {},
  118. ObjectData: {},
  119. Text: {}
  120. };
  121. SearchBarModule.Category = 'sxoinas';
  122. var _default = SearchBarModule;
  123. exports.default = _default;