You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
8.8 KiB

  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../../../@patternfly/pfelement/dist/pfelement.umd'), require('../../../@patternfly/pfe-autocomplete/dist/pfe-autocomplete.umd')) :
  3. typeof define === 'function' && define.amd ? define(['../../../@patternfly/pfelement/dist/pfelement.umd', '../../../@patternfly/pfe-autocomplete/dist/pfe-autocomplete.umd'], factory) :
  4. (global.CpSearchAutocomplete = factory(global.PFElement));
  5. }(this, (function (PFElement) { 'use strict';
  6. PFElement = PFElement && PFElement.hasOwnProperty('default') ? PFElement['default'] : PFElement;
  7. var classCallCheck = function (instance, Constructor) {
  8. if (!(instance instanceof Constructor)) {
  9. throw new TypeError("Cannot call a class as a function");
  10. }
  11. };
  12. var createClass = function () {
  13. function defineProperties(target, props) {
  14. for (var i = 0; i < props.length; i++) {
  15. var descriptor = props[i];
  16. descriptor.enumerable = descriptor.enumerable || false;
  17. descriptor.configurable = true;
  18. if ("value" in descriptor) descriptor.writable = true;
  19. Object.defineProperty(target, descriptor.key, descriptor);
  20. }
  21. }
  22. return function (Constructor, protoProps, staticProps) {
  23. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  24. if (staticProps) defineProperties(Constructor, staticProps);
  25. return Constructor;
  26. };
  27. }();
  28. var get = function get(object, property, receiver) {
  29. if (object === null) object = Function.prototype;
  30. var desc = Object.getOwnPropertyDescriptor(object, property);
  31. if (desc === undefined) {
  32. var parent = Object.getPrototypeOf(object);
  33. if (parent === null) {
  34. return undefined;
  35. } else {
  36. return get(parent, property, receiver);
  37. }
  38. } else if ("value" in desc) {
  39. return desc.value;
  40. } else {
  41. var getter = desc.get;
  42. if (getter === undefined) {
  43. return undefined;
  44. }
  45. return getter.call(receiver);
  46. }
  47. };
  48. var inherits = function (subClass, superClass) {
  49. if (typeof superClass !== "function" && superClass !== null) {
  50. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  51. }
  52. subClass.prototype = Object.create(superClass && superClass.prototype, {
  53. constructor: {
  54. value: subClass,
  55. enumerable: false,
  56. writable: true,
  57. configurable: true
  58. }
  59. });
  60. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  61. };
  62. var possibleConstructorReturn = function (self, call) {
  63. if (!self) {
  64. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  65. }
  66. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  67. };
  68. /*!
  69. * PatternFly Elements: CpSearchAutocomplete 0.0.5
  70. * @license
  71. * Copyright 2020 Red Hat, Inc.
  72. *
  73. * Permission is hereby granted, free of charge, to any person obtaining a copy
  74. * of this software and associated documentation files (the "Software"), to deal
  75. * in the Software without restriction, including without limitation the rights
  76. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  77. * copies of the Software, and to permit persons to whom the Software is
  78. * furnished to do so, subject to the following conditions:
  79. *
  80. * The above copyright notice and this permission notice shall be included in
  81. * all copies or substantial portions of the Software.
  82. *
  83. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  84. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  85. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  86. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  87. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  88. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  89. * SOFTWARE.
  90. *
  91. */
  92. // /node_modules
  93. // @patternfly
  94. // pfelement
  95. // dist
  96. // pfelement.js
  97. // @cpelements
  98. // cp-search-autocomplete
  99. // dist
  100. // cp-search-autocomplete.js
  101. var CpSearchAutocomplete = function (_PFElement) {
  102. inherits(CpSearchAutocomplete, _PFElement);
  103. createClass(CpSearchAutocomplete, [{
  104. key: "html",
  105. get: function get$$1() {
  106. return "<style>:host{display:block}:host([hidden]){display:none}pfe-autocomplete input{--pfe-theme--ui--element--size:17px}pfe-autocomplete ul li:hover{color:#252525;background-color:#ececec}\n/*# sourceMappingURL=cp-search-autocomplete.min.css.map */\n</style><pfe-autocomplete id=\"static\" debounce=\"300\"> \n <input placeholder=\"Enter your search term\">\n</pfe-autocomplete>";
  107. }
  108. }, {
  109. key: "schemaUrl",
  110. get: function get$$1() {
  111. return "cp-search-autocomplete.json";
  112. }
  113. }, {
  114. key: "templateUrl",
  115. get: function get$$1() {
  116. return "cp-search-autocomplete.html";
  117. }
  118. }, {
  119. key: "styleUrl",
  120. get: function get$$1() {
  121. return "cp-search-autocomplete.scss";
  122. }
  123. }, {
  124. key: "numItems",
  125. get: function get$$1() {
  126. return this.getAttribute("num-items") || 5;
  127. }
  128. }], [{
  129. key: "version",
  130. get: function get$$1() {
  131. return "0.0.5";
  132. }
  133. }, {
  134. key: "properties",
  135. get: function get$$1() {
  136. return { "location": { "title": "Location", "type": "string", "enum": [], "default": "", "prefixed": true } };
  137. }
  138. }, {
  139. key: "slots",
  140. get: function get$$1() {
  141. return { "default": { "title": "Default slot", "type": "array", "namedSlot": false, "items": { "oneOf": [{ "$ref": "raw" }] } } };
  142. }
  143. }, {
  144. key: "tag",
  145. get: function get$$1() {
  146. return "cp-search-autocomplete";
  147. }
  148. }, {
  149. key: "PfeType",
  150. get: function get$$1() {
  151. return PFElement.PfeTypes.Container;
  152. }
  153. }, {
  154. key: "observedAttributes",
  155. get: function get$$1() {
  156. return ["pfe-location", "path", "query"];
  157. }
  158. }]);
  159. function CpSearchAutocomplete() {
  160. classCallCheck(this, CpSearchAutocomplete);
  161. var _this = possibleConstructorReturn(this, (CpSearchAutocomplete.__proto__ || Object.getPrototypeOf(CpSearchAutocomplete)).call(this, CpSearchAutocomplete, { type: CpSearchAutocomplete.PfeType }));
  162. _this.path = _this.getAttribute("path");
  163. _this._input = _this.shadowRoot.querySelector("input");
  164. _this._data = null;
  165. _this._searchAutocomplete = _this.shadowRoot.querySelector("pfe-autocomplete");
  166. _this._searchAutocomplete.addEventListener("pfe-search-event", function (e) {
  167. return console.log(e.detail.searchValue);
  168. });
  169. return _this;
  170. }
  171. createClass(CpSearchAutocomplete, [{
  172. key: "connectedCallback",
  173. value: function connectedCallback() {
  174. get(CpSearchAutocomplete.prototype.__proto__ || Object.getPrototypeOf(CpSearchAutocomplete.prototype), "connectedCallback", this).call(this);
  175. this._fetchData();
  176. }
  177. // Process the attribute change
  178. }, {
  179. key: "attributeChangedCallback",
  180. value: function attributeChangedCallback(attr, oldValue, newValue) {
  181. get(CpSearchAutocomplete.prototype.__proto__ || Object.getPrototypeOf(CpSearchAutocomplete.prototype), "attributeChangedCallback", this).call(this, attr, oldValue, newValue);
  182. if (attr === "query") {
  183. this._input.value = newValue;
  184. }
  185. }
  186. }, {
  187. key: "_fetchData",
  188. value: function _fetchData() {
  189. var _this2 = this;
  190. var path = this.getAttribute("path");
  191. if (!path) {
  192. return;
  193. }
  194. var xhr = new XMLHttpRequest();
  195. xhr.onload = function () {
  196. if (xhr.status === 404) {
  197. console.log("No data available");
  198. } else {
  199. var response = JSON.parse(xhr.responseText);
  200. _this2._data = response;
  201. _this2._initAutocomplete();
  202. }
  203. };
  204. xhr.open("GET", this.path, true);
  205. xhr.send();
  206. }
  207. }, {
  208. key: "_initAutocomplete",
  209. value: function _initAutocomplete() {
  210. var _this3 = this;
  211. this._searchAutocomplete.autocompleteRequest = function (params, callback) {
  212. var regx = new RegExp("^" + params.query, "i");
  213. var items = _this3._data;
  214. var returnArr = items.filter(function (item) {
  215. return regx.test(item);
  216. }).slice(0, _this3.numItems);
  217. callback(returnArr);
  218. };
  219. }
  220. }]);
  221. return CpSearchAutocomplete;
  222. }(PFElement);
  223. PFElement.create(CpSearchAutocomplete);
  224. return CpSearchAutocomplete;
  225. })));
  226. //# sourceMappingURL=cp-search-autocomplete.umd.js.map