@gravitee/ui-components 3.25.3-typescript-e7256ca → 3.25.3-typescript-9cbc31e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/package.json +5 -13
  2. package/src/atoms/gv-autocomplete.js +422 -1
  3. package/src/atoms/gv-button.js +397 -1
  4. package/src/atoms/gv-checkbox.js +178 -1
  5. package/src/atoms/gv-date-picker-calendar.js +812 -1
  6. package/src/atoms/gv-date-picker-cell.js +174 -1
  7. package/src/atoms/gv-date-picker.js +638 -1
  8. package/src/atoms/gv-file-upload.js +348 -1
  9. package/src/atoms/gv-icon.js +93 -1
  10. package/src/atoms/gv-image.js +135 -1
  11. package/src/atoms/gv-input-message.js +78 -1
  12. package/src/atoms/gv-input.js +508 -1
  13. package/src/atoms/gv-link.js +204 -1
  14. package/src/atoms/gv-message.js +133 -1
  15. package/src/atoms/gv-metric.js +112 -1
  16. package/src/atoms/gv-relative-time.js +143 -1
  17. package/src/atoms/gv-select-native.js +363 -1
  18. package/src/atoms/gv-select.js +413 -1
  19. package/src/atoms/gv-spinner.js +54 -1
  20. package/src/atoms/gv-state.js +125 -1
  21. package/src/atoms/gv-switch.js +235 -1
  22. package/src/atoms/gv-tag.js +162 -1
  23. package/src/atoms/gv-text.js +160 -1
  24. package/src/charts/gv-chart-bar.js +101 -1
  25. package/src/charts/gv-chart-gauge.js +92 -1
  26. package/src/charts/gv-chart-histogram.js +78 -1
  27. package/src/charts/gv-chart-line.js +218 -1
  28. package/src/charts/gv-chart-map.js +111 -1
  29. package/src/charts/gv-chart-pie.js +89 -1
  30. package/src/index.js +77 -1
  31. package/src/lib/cron-expression.js +176 -1
  32. package/src/lib/date.js +43 -1
  33. package/src/lib/events.js +26 -1
  34. package/src/lib/http-client-schema-form.js +67 -1
  35. package/src/lib/http.js +237 -1
  36. package/src/lib/i18n.js +93 -1
  37. package/src/lib/item.js +110 -1
  38. package/src/lib/properties.js +171 -1
  39. package/src/lib/schema-form.js +39 -1
  40. package/src/lib/studio.js +144 -1
  41. package/src/lib/style.js +39 -1
  42. package/src/lib/text-format.js +65 -1
  43. package/src/lib/theme.js +60 -1
  44. package/src/lib/utils.js +106 -1
  45. package/src/mixins/chart-element.js +153 -1
  46. package/src/mixins/input-element.js +136 -1
  47. package/src/mixins/item-resource.js +102 -1
  48. package/src/mixins/keyboard-element.js +62 -1
  49. package/src/mixins/update-after-browser.js +30 -1
  50. package/src/mixins/with-resize-observer.js +62 -1
  51. package/src/mixins/with-skeleton-attribute.js +109 -1
  52. package/src/molecules/gv-card-full.js +209 -1
  53. package/src/molecules/gv-card-list.js +101 -1
  54. package/src/molecules/gv-card.js +130 -1
  55. package/src/molecules/gv-category-list.js +56 -1
  56. package/src/molecules/gv-category.js +163 -1
  57. package/src/molecules/gv-code.js +334 -1
  58. package/src/molecules/gv-confirm.js +175 -1
  59. package/src/molecules/gv-cron-editor.js +685 -1
  60. package/src/molecules/gv-dropdown-menu.js +108 -1
  61. package/src/molecules/gv-expandable.js +116 -1
  62. package/src/molecules/gv-expression-language.js +263 -1
  63. package/src/molecules/gv-identity-picture.js +139 -1
  64. package/src/molecules/gv-list.js +214 -1
  65. package/src/molecules/gv-metrics.js +147 -1
  66. package/src/molecules/gv-modal.js +203 -1
  67. package/src/molecules/gv-nav.js +180 -1
  68. package/src/molecules/gv-option.js +230 -1
  69. package/src/molecules/gv-plans.js +400 -1
  70. package/src/molecules/gv-popover.js +323 -1
  71. package/src/molecules/gv-promote.js +203 -1
  72. package/src/molecules/gv-rating-list.js +341 -1
  73. package/src/molecules/gv-rating.js +234 -1
  74. package/src/molecules/gv-row-expandable.js +42 -1
  75. package/src/molecules/gv-row.js +205 -1
  76. package/src/molecules/gv-stats.js +110 -1
  77. package/src/molecules/gv-stepper.js +274 -1
  78. package/src/molecules/gv-table.js +644 -1
  79. package/src/molecules/gv-tree.js +238 -1
  80. package/src/organisms/gv-documentation.js +205 -1
  81. package/src/organisms/gv-header.js +276 -1
  82. package/src/organisms/gv-http-client.js +258 -1
  83. package/src/organisms/gv-menu.js +258 -1
  84. package/src/organisms/gv-newsletter-subscription.js +258 -1
  85. package/src/organisms/gv-pagination.js +179 -1
  86. package/src/organisms/gv-properties.js +860 -1
  87. package/src/organisms/gv-resizable-views.js +371 -1
  88. package/src/organisms/gv-resources.js +496 -1
  89. package/src/organisms/gv-schema-form-array.js +237 -1
  90. package/src/organisms/gv-schema-form-control-object.js +141 -1
  91. package/src/organisms/gv-schema-form-control.js +419 -1
  92. package/src/organisms/gv-schema-form.js +700 -1
  93. package/src/organisms/gv-tabs.js +201 -1
  94. package/src/organisms/gv-user-menu.js +298 -1
  95. package/src/organisms/gv-vertical-menu.js +119 -1
  96. package/src/policy-studio/gv-flow-step.js +443 -1
  97. package/src/policy-studio/gv-flow.js +595 -1
  98. package/src/policy-studio/gv-policy-studio-menu.js +689 -1
  99. package/src/policy-studio/gv-policy-studio.js +1712 -1
  100. package/src/styles/empty.js +35 -1
  101. package/src/styles/input.js +262 -1
  102. package/src/styles/link.js +31 -1
  103. package/src/styles/shapes.js +17 -1
  104. package/src/styles/skeleton.js +52 -1
  105. package/src/styles/zoom.js +39 -1
  106. package/src/theme/gv-theme.js +197 -1
  107. package/wc/gv-autocomplete.js +1 -1
  108. package/wc/gv-button.js +1 -1
  109. package/wc/gv-card-full.js +1 -1
  110. package/wc/gv-card-list.js +1 -1
  111. package/wc/gv-card.js +1 -1
  112. package/wc/gv-category-list.js +1 -1
  113. package/wc/gv-category.js +1 -1
  114. package/wc/gv-chart-bar.js +1 -1
  115. package/wc/gv-chart-gauge.js +1 -1
  116. package/wc/gv-chart-histogram.js +1 -1
  117. package/wc/gv-chart-line.js +1 -1
  118. package/wc/gv-chart-map.js +1 -1
  119. package/wc/gv-chart-pie.js +1 -1
  120. package/wc/gv-checkbox.js +1 -1
  121. package/wc/gv-code.js +1 -1
  122. package/wc/gv-confirm.js +1 -1
  123. package/wc/gv-cron-editor.js +1 -1
  124. package/wc/gv-date-picker-calendar.js +1 -1
  125. package/wc/gv-date-picker-cell.js +1 -1
  126. package/wc/gv-date-picker.js +1 -1
  127. package/wc/gv-documentation.js +1 -1
  128. package/wc/gv-dropdown-menu.js +1 -1
  129. package/wc/gv-expandable.js +1 -1
  130. package/wc/gv-expression-language.js +1 -1
  131. package/wc/gv-file-upload.js +1 -1
  132. package/wc/gv-flow-step.js +1 -1
  133. package/wc/gv-flow.js +1 -1
  134. package/wc/gv-header.js +1 -1
  135. package/wc/gv-http-client.js +1 -1
  136. package/wc/gv-icon.js +1 -1
  137. package/wc/gv-identity-picture.js +1 -1
  138. package/wc/gv-image.js +1 -1
  139. package/wc/gv-input-message.js +1 -1
  140. package/wc/gv-input.js +1 -1
  141. package/wc/gv-link.js +1 -1
  142. package/wc/gv-list.js +1 -1
  143. package/wc/gv-menu.js +1 -1
  144. package/wc/gv-message.js +1 -1
  145. package/wc/gv-metric.js +1 -1
  146. package/wc/gv-metrics.js +1 -1
  147. package/wc/gv-modal.js +1 -1
  148. package/wc/gv-nav.js +1 -1
  149. package/wc/gv-newsletter-subscription.js +1 -1
  150. package/wc/gv-option.js +1 -1
  151. package/wc/gv-pagination.js +1 -1
  152. package/wc/gv-plans.js +1 -1
  153. package/wc/gv-policy-studio-menu.js +1 -1
  154. package/wc/gv-policy-studio.js +1 -1
  155. package/wc/gv-popover.js +1 -1
  156. package/wc/gv-promote.js +1 -1
  157. package/wc/gv-properties.js +1 -1
  158. package/wc/gv-rating-list.js +1 -1
  159. package/wc/gv-rating.js +1 -1
  160. package/wc/gv-relative-time.js +1 -1
  161. package/wc/gv-resizable-views.js +1 -1
  162. package/wc/gv-resources.js +1 -1
  163. package/wc/gv-row-expandable.js +1 -1
  164. package/wc/gv-row.js +1 -1
  165. package/wc/gv-schema-form-array.js +1 -1
  166. package/wc/gv-schema-form-control-object.js +1 -1
  167. package/wc/gv-schema-form-control.js +1 -1
  168. package/wc/gv-schema-form.js +1 -1
  169. package/wc/gv-select-native.js +1 -1
  170. package/wc/gv-select.js +1 -1
  171. package/wc/gv-spinner.js +1 -1
  172. package/wc/gv-state.js +1 -1
  173. package/wc/gv-stats.js +1 -1
  174. package/wc/gv-stepper.js +1 -1
  175. package/wc/gv-switch.js +1 -1
  176. package/wc/gv-table.js +1 -1
  177. package/wc/gv-tabs.js +1 -1
  178. package/wc/gv-tag.js +1 -1
  179. package/wc/gv-text.js +1 -1
  180. package/wc/gv-theme.js +1 -1
  181. package/wc/gv-tree.js +1 -1
  182. package/wc/gv-user-menu.js +1 -1
  183. package/wc/gv-vertical-menu.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravitee/ui-components",
3
- "version": "3.25.3-typescript-e7256ca",
3
+ "version": "3.25.3-typescript-9cbc31e",
4
4
  "description": "Gravitee.io UI Components library, based on Web Components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,7 +23,7 @@
23
23
  "check:i18n": "node tasks/check-i18n.js",
24
24
  "danger": "danger ci",
25
25
  "docs": "wca analyze src/** --outFile .docs/custom-elements.json && node tasks/generate-docs.js",
26
- "generate:dist": "npm run tsc && npm run rollup",
26
+ "generate:dist": "npm run tsc && cp -R assets dist/ && cp package.json dist/",
27
27
  "generate:icons": "node tasks/generate-icons.js && npm run lint:fix",
28
28
  "generate:theme": "node tasks/generate-theme.js && npm run lint:fix",
29
29
  "lint": "eslint src stories tasks && npm run prettier",
@@ -36,7 +36,6 @@
36
36
  "prettier": "prettier --check \"**/*.{js,html,css,json}\"",
37
37
  "prettier:fix": "prettier --write \"**/*.{js,html,css,json}\"",
38
38
  "release": "semantic-release",
39
- "rollup": "rollup -c ",
40
39
  "serve": "npm run docs && start-storybook -p 6006 --ci -s assets --modern",
41
40
  "serve:prod": "npm run build && static -a 0.0.0.0 -p 8080 storybook-static --modern",
42
41
  "size": "node tasks/size.js",
@@ -74,10 +73,9 @@
74
73
  "@babel/plugin-syntax-dynamic-import": "7.8.3",
75
74
  "@babel/preset-env": "7.16.5",
76
75
  "@babel/preset-typescript": "^7.16.5",
77
- "@commitlint/cli": "15.0.0",
78
- "@commitlint/config-conventional": "15.0.0",
76
+ "@commitlint/cli": "16.0.0",
77
+ "@commitlint/config-conventional": "16.0.0",
79
78
  "@highcharts/map-collection": "1.1.4",
80
- "@rollup/plugin-json": "^4.1.0",
81
79
  "@semantic-release/changelog": "6.0.1",
82
80
  "@semantic-release/git": "10.0.1",
83
81
  "@storybook/addon-a11y": "6.4.9",
@@ -85,13 +83,12 @@
85
83
  "@storybook/components": "6.4.9",
86
84
  "@storybook/theming": "6.4.9",
87
85
  "@storybook/web-components": "6.4.9",
88
- "@web/rollup-plugin-copy": "^0.3.0",
89
86
  "asciidoctor": "2.2.5",
90
87
  "asciidoctor-highlight.js": "0.4.0",
91
88
  "babel-jest": "27.4.5",
92
89
  "babel-loader": "8.2.3",
93
90
  "bundle-phobia-cli": "0.14.13",
94
- "chromatic": "6.2.3",
91
+ "chromatic": "6.3.3",
95
92
  "danger": "10.7.1",
96
93
  "del": "6.0.0",
97
94
  "eslint": "8.5.0",
@@ -123,11 +120,6 @@
123
120
  "nodemon": "2.0.15",
124
121
  "pascal-case": "3.1.2",
125
122
  "prettier": "2.5.1",
126
- "rollup": "^2.61.1",
127
- "rollup-plugin-commonjs": "^10.1.0",
128
- "rollup-plugin-minify-html-literals": "^1.2.6",
129
- "rollup-plugin-multi-input": "^1.3.1",
130
- "rollup-plugin-terser": "^7.0.2",
131
123
  "semantic-release": "18.0.1",
132
124
  "sort-package-json": "1.53.1",
133
125
  "svgo": "2.8.0",
@@ -1 +1,422 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvAutocomplete=void 0;const t=require("lit"),e=require("../lib/events"),o=require("lit/directives/repeat"),i=require("lit/directives/class-map"),s=require("lit/directives/style-map");class n extends t.LitElement{static get properties(){return{options:{type:Array,reflect:!0},value:{type:String,reflect:!0},style:{type:String},minChars:{type:Number},filter:{type:Boolean|Function},size:{type:Number},_options:{type:Array,attribute:!1},_forceOpen:{type:Boolean,attribute:!1}}}static get styles(){return[t.css`:host{box-sizing:border-box;display:inline-block;width:100%}::slotted(*){width:100%}.container{position:relative}.container .options.open{display:block;visibility:visible;opacity:1;-webkit-transform:-webkit-translateY(0);transform:translateY(0);z-index:100}.options{background-color:var(--gv-autocomplete--bgc,var(--gv-theme-neutral-color-lightest,#fff));color:var(--gv-autocomplete--c,var(--gv-theme-font-color,#262626));margin:.2rem;position:absolute;box-shadow:0 0 0 1px var(--gv-theme-neutral-color,#f5f5f5),0 1px 3px var(--gv-theme-neutral-color-dark,#bfbfbf);border-radius:2px;display:block;width:100%;cursor:pointer;left:0;right:0;visibility:hidden;opacity:0;-webkit-transform:-webkit-translateY(-2em);transform:translateY(-2em);-webkit-transition:-webkit-transform 150ms ease-in-out,opacity 150ms ease-in-out;-moz-transition:all 150ms ease-in-out;-ms-transition:all 150ms ease-in-out;-o-transition:all 150ms ease-in-out;overflow:auto}.option{padding:.2rem;min-height:30px;word-break:break-all}.option.match~.option.match{background-color:transparent}.keyboard .option.hover:hover,.option.hover,.option:hover{background-color:var(--gv-autocomplete-hover--bgc,var(--gv-theme-neutral-color-lighter,#fafafa))}.keyboard .option:hover{background-color:transparent}.show{display:block}.hide{display:none}`]}constructor(){super(),this._options=[],this._candidateIndex=-1,this.minChars=1,this.value="",this.style="",this.filter=!1,this.size=5,this._handleOpened=this._onOpened.bind(this)}set options(t){this._options=t}get options(){return this._options}reset(){this._getInput().reset(),this._options=[]}_getFilteredOptions(){return this.filter&&this.value&&this.value.length>=this.minChars&&"*"!==this.value?"function"==typeof this.filter?this._options.filter((t=>this.filter(this.value,t))):this._options.filter((t=>-1!==t.value.indexOf(this.value))):this._options}_onInput(t){clearTimeout(this._cancellableTimeout),this.value=t.target.value,null!=this.value&&this.value.trim().length>=this.minChars?this._cancellableTimeout=setTimeout((()=>{this._open(),(0,e.dispatchCustomEvent)(this,"search",this.value)}),200):this.options=[]}_onSelect(t,o){null==o&&(o=this._options.find((e=>e.value===t))),this.value=this._getInput().value=t,this._close(),(0,e.dispatchCustomEvent)(this,"select",o)}_onMouseOver(){this.shadowRoot.firstElementChild.classList.remove("keyboard"),this._clearHover(),this._shouldSelect=!0}_onMouseLeave(){this._shouldSelect=!1}_renderOption(t){if(t.element)return t.element;if(t.innerHTML){const e=document.createElement("div");return e.innerHTML=t.innerHTML,e}return t.value}_renderStyle(){if(this.style){const e=document.createElement("div");return e.innerHTML=(0,t.unsafeCSS)(this.style),e}return""}_hasNoOptionSlot(){for(const t of this.childNodes)if("noOption"===t.slot)return!0;return!1}render(){const e=this._getFilteredOptions();let n=!1;e&&e.length>0&&this._forceOpen&&(n=0===this.minChars||this.value.trim().length>=this.minChars);const r=this._getInput();let a=0;null!=r&&(a=r.offsetHeight);const l={options:!0,open:n};return t.html`<div class="container">${this._renderStyle()}<slot></slot>${this._hasNoOptionSlot()&&this._forceOpen?t.html`<div class="options open" style="${(0,s.styleMap)({top:`${a}px`})}"><slot name="noOption" class="${e&&0!==e.length?"hide":"show"}"></slot></div>`:""}<div class="${(0,i.classMap)(l)}" @mouseleave="${this._onMouseLeave}" style="${(0,s.styleMap)({top:`${a}px`})}">${(0,o.repeat)(e,(t=>t),((e,o)=>t.html`<div class="${(0,i.classMap)({option:!0})}" data-value="${e.value}" @mouseover="${()=>this._onMouseOver(e,o)}" @click="${()=>this._onSelect(e.value,e)}">${this._renderOption(e)}</div>`))}</div></div>`}_clearHover(){this.shadowRoot.querySelectorAll(".option.hover").forEach((t=>t.classList.remove("hover")))}_updateHover(){if(this._clearHover(),this._candidateIndex>-1){this.shadowRoot.firstElementChild.classList.add("keyboard");const t=this.shadowRoot.querySelectorAll(".option")[this._candidateIndex];if(t){const e=this.shadowRoot.querySelector(".options"),{top:o,left:i}=t.getBoundingClientRect(),s=e.getBoundingClientRect(),n=i-s.left,r=o-s.top;e.scrollTo(n,r),t.classList.add("hover")}}}_onKeydown(t){switch(t.keyCode){case 13:{const e=this.shadowRoot.querySelectorAll(".option")[this._candidateIndex];e&&(t.preventDefault(),t.stopPropagation(),this._candidateIndex=-1,this._onSelect(e.getAttribute("data-value")),this._updateHover()),this._close();break}case 40:this._candidateIndex<this.shadowRoot.querySelectorAll(".option").length-1&&(t.preventDefault(),t.stopPropagation(),this._candidateIndex+=1,this._updateHover());break;case 38:this._candidateIndex>0&&(t.preventDefault(),t.stopPropagation(),this._candidateIndex-=1,this._updateHover());break;case 27:t.preventDefault(),t.stopPropagation(),this._candidateIndex=-1,this._updateHover();break;default:this.value=this._getInput().value,this._candidateIndex=-1,this._updateHover()}}_open(){this._forceOpen=!0,(0,e.dispatchCustomEvent)(this,"opened",{target:this})}_close(){this._forceOpen=!1}_onFocus(){this._open()}_onBlur(){!1===this._shouldSelect&&this._close()}_getInput(){for(const t of this.childNodes)if("input"===t.slot)return t;return this.firstElementChild}_onClear(t){this.value=t.target.value}updated(){setTimeout((()=>{const t=this.shadowRoot.querySelector(".option");if(t){const e=t.clientHeight*parseInt(this.size,10),o=this.shadowRoot.querySelector(".options");o.style.maxHeight=`${e}px`,o.scrollTo(0,0)}}),0)}firstUpdated(){this._handlers={input:this._onInput.bind(this),focus:this._onFocus.bind(this),blur:this._onBlur.bind(this),keydown:this._onKeydown.bind(this),clear:this._onClear.bind(this)},this.shadowRoot.addEventListener("input",this._handlers.input),this.shadowRoot.addEventListener("keydown",this._handlers.keydown);const t=this._getInput();t.addEventListener("focus",this._handlers.focus),t.addEventListener("blur",this._handlers.blur),t.addEventListener("gv-input:clear",this._handlers.clear),"gv-input"===t.tagName.toLowerCase()&&t.setAttribute("no-submit",!0)}_onOpened({detail:t}){t.target!==this&&this._close()}connectedCallback(){super.connectedCallback(),window.addEventListener("gv-autocomplete:opened",this._handleOpened)}disconnectedCallback(){if(this._handlers){this.shadowRoot.removeEventListener("input",this._handlers.input),this.shadowRoot.removeEventListener("keydown",this._handlers.keydown);const t=this._getInput();t.removeEventListener("focus",this._handlers.focus),t.removeEventListener("blur",this._handlers.blur),t.removeEventListener("gv-input:clear",this._handlers.clear)}window.removeEventListener("gv-autocomplete:open",this._handleOpened),super.disconnectedCallback()}}exports.GvAutocomplete=n,window.customElements.define("gv-autocomplete",n);
1
+ /*
2
+ * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { css, LitElement, unsafeCSS, html } from 'lit';
17
+ import { dispatchCustomEvent } from '../lib/events';
18
+ import { repeat } from 'lit/directives/repeat';
19
+ import { classMap } from 'lit/directives/class-map';
20
+ import { styleMap } from 'lit/directives/style-map';
21
+ const ENTER_KEY_CODE = 13;
22
+ const DOWN_ARROW_KEY_CODE = 40;
23
+ const UP_ARROW_KEY_CODE = 38;
24
+ const ESCAPE_KEY_CODE = 27;
25
+ /**
26
+ * Autocomplete input wrapper
27
+ *
28
+ * ## Details
29
+ * * has @theme facet
30
+ *
31
+ * @fires gv-autocomplete:search - Custom event when user search value
32
+ * @fires gv-autocomplete:select - Custom event when user select value
33
+ * @fires gv-autocomplete:opened - Custom event after opened autocomplete
34
+ *
35
+ * @slot style - The options style
36
+ * @slot input - The input to wrap
37
+ * @slot noOption - What should be shown when there is no options to display
38
+ *
39
+ * @attr {Array.<{value: String, innerHTML?: String}>} options - the options for search
40
+ * @attr {String} value - selected value
41
+ * @attr {String} style - css if you want custom options rendered
42
+ * @attr {Number} minChars - minimum of characters for launch search and show results
43
+ * @attr {Number} size - results size to show before user must scroll
44
+ * @attr {Boolean|Function(value,option)} filter - If true, filter options by input, if function, filter options against it. The function will
45
+ * receive two arguments, inputValue and option, if the function returns true, the option will be included
46
+ * in the filtered set; Otherwise, it will be excluded.
47
+ * the option will be included in the filtered set; Otherwise, it will be excluded.
48
+ *
49
+ * @cssprop {Color} [--gv-autocomplete-hover--bgc=var(--gv-theme-neutral-color-lighter, #fafafa)] - Hover background color
50
+ * @cssprop {Color} [--gv-autocomplete--bgc=var(--gv-theme-neutral-color-lightest, #ffffff)] - Background color
51
+ * @cssprop {Color} [--gv-autocomplete--c=var(--gv-theme-font-color, #262626)] - Color
52
+ */
53
+ export class GvAutocomplete extends LitElement {
54
+ static get properties() {
55
+ return {
56
+ options: { type: Array, reflect: true },
57
+ value: { type: String, reflect: true },
58
+ style: { type: String },
59
+ minChars: { type: Number },
60
+ filter: { type: Boolean | Function },
61
+ size: { type: Number },
62
+ _options: { type: Array, attribute: false },
63
+ _forceOpen: { type: Boolean, attribute: false },
64
+ };
65
+ }
66
+ static get styles() {
67
+ return [
68
+ // language=CSS
69
+ css `
70
+ :host {
71
+ box-sizing: border-box;
72
+ display: inline-block;
73
+ width: 100%;
74
+ }
75
+
76
+ ::slotted(*) {
77
+ width: 100%;
78
+ }
79
+
80
+ .container {
81
+ position: relative;
82
+ }
83
+
84
+ .container .options.open {
85
+ display: block;
86
+ visibility: visible;
87
+ opacity: 1;
88
+ -webkit-transform: -webkit-translateY(0%);
89
+ transform: translateY(0%);
90
+ z-index: 100;
91
+ }
92
+
93
+ .options {
94
+ background-color: var(--gv-autocomplete--bgc, var(--gv-theme-neutral-color-lightest, #ffffff));
95
+ color: var(--gv-autocomplete--c, var(--gv-theme-font-color, #262626));
96
+ margin: 0.2rem;
97
+ position: absolute;
98
+ box-shadow: 0 0 0 1px var(--gv-theme-neutral-color, #f5f5f5), 0 1px 3px var(--gv-theme-neutral-color-dark, #bfbfbf);
99
+ border-radius: 2px;
100
+ display: block;
101
+ width: 100%;
102
+ cursor: pointer;
103
+ left: 0;
104
+ right: 0;
105
+ visibility: hidden;
106
+ opacity: 0;
107
+ -webkit-transform: -webkit-translateY(-2em);
108
+ transform: translateY(-2em);
109
+ -webkit-transition: -webkit-transform 150ms ease-in-out, opacity 150ms ease-in-out;
110
+ -moz-transition: all 150ms ease-in-out;
111
+ -ms-transition: all 150ms ease-in-out;
112
+ -o-transition: all 150ms ease-in-out;
113
+ overflow: auto;
114
+ }
115
+
116
+ .option {
117
+ padding: 0.2rem;
118
+ min-height: 30px;
119
+ word-break: break-all;
120
+ }
121
+
122
+ .option.match ~ .option.match {
123
+ background-color: transparent;
124
+ }
125
+
126
+ .option:hover,
127
+ .option.hover,
128
+ .keyboard .option.hover:hover {
129
+ background-color: var(--gv-autocomplete-hover--bgc, var(--gv-theme-neutral-color-lighter, #fafafa));
130
+ }
131
+
132
+ .keyboard .option:hover {
133
+ background-color: transparent;
134
+ }
135
+
136
+ .show {
137
+ display: block;
138
+ }
139
+
140
+ .hide {
141
+ display: none;
142
+ }
143
+ `,
144
+ ];
145
+ }
146
+ constructor() {
147
+ super();
148
+ this._options = [];
149
+ this._candidateIndex = -1;
150
+ this.minChars = 1;
151
+ this.value = '';
152
+ this.style = '';
153
+ this.filter = false;
154
+ this.size = 5;
155
+ this._handleOpened = this._onOpened.bind(this);
156
+ }
157
+ set options(options) {
158
+ this._options = options;
159
+ }
160
+ get options() {
161
+ return this._options;
162
+ }
163
+ reset() {
164
+ this._getInput().reset();
165
+ this._options = [];
166
+ }
167
+ _getFilteredOptions() {
168
+ if (this.filter && this.value && this.value.length >= this.minChars && this.value !== '*') {
169
+ if (typeof this.filter === 'function') {
170
+ return this._options.filter((option) => {
171
+ return this.filter(this.value, option);
172
+ });
173
+ }
174
+ else {
175
+ return this._options.filter((option) => {
176
+ return option.value.indexOf(this.value) !== -1;
177
+ });
178
+ }
179
+ }
180
+ else {
181
+ return this._options;
182
+ }
183
+ }
184
+ _onInput(event) {
185
+ clearTimeout(this._cancellableTimeout);
186
+ this.value = event.target.value;
187
+ if (this.value != null && this.value.trim().length >= this.minChars) {
188
+ this._cancellableTimeout = setTimeout(() => {
189
+ this._open();
190
+ dispatchCustomEvent(this, 'search', this.value);
191
+ }, 200);
192
+ }
193
+ else {
194
+ this.options = [];
195
+ }
196
+ }
197
+ _onSelect(value, option) {
198
+ if (option == null) {
199
+ option = this._options.find((option) => {
200
+ return option.value === value;
201
+ });
202
+ }
203
+ this.value = this._getInput().value = value;
204
+ this._close();
205
+ dispatchCustomEvent(this, 'select', option);
206
+ }
207
+ _onMouseOver() {
208
+ this.shadowRoot.firstElementChild.classList.remove('keyboard');
209
+ this._clearHover();
210
+ this._shouldSelect = true;
211
+ }
212
+ _onMouseLeave() {
213
+ this._shouldSelect = false;
214
+ }
215
+ _renderOption(option) {
216
+ if (option.element) {
217
+ return option.element;
218
+ }
219
+ if (option.innerHTML) {
220
+ const wrapper = document.createElement('div');
221
+ wrapper.innerHTML = option.innerHTML;
222
+ return wrapper;
223
+ }
224
+ return option.value;
225
+ }
226
+ _renderStyle() {
227
+ if (this.style) {
228
+ const wrapper = document.createElement('div');
229
+ wrapper.innerHTML = unsafeCSS(this.style);
230
+ return wrapper;
231
+ }
232
+ return '';
233
+ }
234
+ _hasNoOptionSlot() {
235
+ for (const node of this.childNodes) {
236
+ if (node.slot === 'noOption') {
237
+ return true;
238
+ }
239
+ }
240
+ return false;
241
+ }
242
+ render() {
243
+ const options = this._getFilteredOptions();
244
+ let open = false;
245
+ if (options && options.length > 0 && this._forceOpen) {
246
+ open = this.minChars === 0 || this.value.trim().length >= this.minChars;
247
+ }
248
+ const input = this._getInput();
249
+ let top = 0;
250
+ if (input != null) {
251
+ top = input.offsetHeight;
252
+ }
253
+ const classes = {
254
+ options: true,
255
+ open,
256
+ };
257
+ return html ` <div class="container">
258
+ ${this._renderStyle()}
259
+ <slot></slot>
260
+ ${this._hasNoOptionSlot() && this._forceOpen
261
+ ? html `<div class="options open" style="${styleMap({ top: `${top}px` })}">
262
+ <slot name="noOption" class="${!options || options.length === 0 ? 'show' : 'hide'}"></slot>
263
+ </div>`
264
+ : ''}
265
+ <div class="${classMap(classes)}" @mouseleave="${this._onMouseLeave}" style="${styleMap({ top: `${top}px` })}">
266
+ ${repeat(options, (option) => option, (option, index) => html `
267
+ <div
268
+ class="${classMap({ option: true })}"
269
+ data-value="${option.value}"
270
+ @mouseover="${() => this._onMouseOver(option, index)}"
271
+ @click="${() => this._onSelect(option.value, option)}"
272
+ >
273
+ ${this._renderOption(option)}
274
+ </div>
275
+ `)}
276
+ </div>
277
+ </div>`;
278
+ }
279
+ _clearHover() {
280
+ this.shadowRoot.querySelectorAll('.option.hover').forEach((o) => o.classList.remove('hover'));
281
+ }
282
+ _updateHover() {
283
+ this._clearHover();
284
+ if (this._candidateIndex > -1) {
285
+ this.shadowRoot.firstElementChild.classList.add('keyboard');
286
+ const candidate = this.shadowRoot.querySelectorAll('.option')[this._candidateIndex];
287
+ if (candidate) {
288
+ const options = this.shadowRoot.querySelector('.options');
289
+ const { top, left } = candidate.getBoundingClientRect();
290
+ const container = options.getBoundingClientRect();
291
+ const scrollLeft = left - container.left;
292
+ const scrollTop = top - container.top;
293
+ options.scrollTo(scrollLeft, scrollTop);
294
+ candidate.classList.add('hover');
295
+ }
296
+ }
297
+ }
298
+ _onKeydown(e) {
299
+ switch (e.keyCode) {
300
+ case ENTER_KEY_CODE: {
301
+ const options = this.shadowRoot.querySelectorAll('.option');
302
+ const candidate = options[this._candidateIndex];
303
+ if (candidate) {
304
+ e.preventDefault();
305
+ e.stopPropagation();
306
+ this._candidateIndex = -1;
307
+ this._onSelect(candidate.getAttribute('data-value'));
308
+ this._updateHover();
309
+ }
310
+ this._close();
311
+ break;
312
+ }
313
+ case DOWN_ARROW_KEY_CODE: {
314
+ if (this._candidateIndex < this.shadowRoot.querySelectorAll('.option').length - 1) {
315
+ e.preventDefault();
316
+ e.stopPropagation();
317
+ this._candidateIndex += 1;
318
+ this._updateHover();
319
+ }
320
+ break;
321
+ }
322
+ case UP_ARROW_KEY_CODE: {
323
+ if (this._candidateIndex > 0) {
324
+ e.preventDefault();
325
+ e.stopPropagation();
326
+ this._candidateIndex -= 1;
327
+ this._updateHover();
328
+ }
329
+ break;
330
+ }
331
+ case ESCAPE_KEY_CODE: {
332
+ e.preventDefault();
333
+ e.stopPropagation();
334
+ this._candidateIndex = -1;
335
+ this._updateHover();
336
+ break;
337
+ }
338
+ default:
339
+ this.value = this._getInput().value;
340
+ this._candidateIndex = -1;
341
+ this._updateHover();
342
+ }
343
+ }
344
+ _open() {
345
+ this._forceOpen = true;
346
+ dispatchCustomEvent(this, 'opened', { target: this });
347
+ }
348
+ _close() {
349
+ this._forceOpen = false;
350
+ }
351
+ _onFocus() {
352
+ this._open();
353
+ }
354
+ _onBlur() {
355
+ // Important when using custom HTML in options
356
+ if (this._shouldSelect === false) {
357
+ this._close();
358
+ }
359
+ }
360
+ _getInput() {
361
+ for (const node of this.childNodes) {
362
+ if (node.slot === 'input') {
363
+ return node;
364
+ }
365
+ }
366
+ return this.firstElementChild;
367
+ }
368
+ _onClear(event) {
369
+ this.value = event.target.value;
370
+ }
371
+ updated() {
372
+ setTimeout(() => {
373
+ const firstOption = this.shadowRoot.querySelector('.option');
374
+ if (firstOption) {
375
+ const maxHeight = firstOption.clientHeight * parseInt(this.size, 10);
376
+ const options = this.shadowRoot.querySelector('.options');
377
+ options.style.maxHeight = `${maxHeight}px`;
378
+ options.scrollTo(0, 0);
379
+ }
380
+ }, 0);
381
+ }
382
+ firstUpdated() {
383
+ this._handlers = {
384
+ input: this._onInput.bind(this),
385
+ focus: this._onFocus.bind(this),
386
+ blur: this._onBlur.bind(this),
387
+ keydown: this._onKeydown.bind(this),
388
+ clear: this._onClear.bind(this),
389
+ };
390
+ this.shadowRoot.addEventListener('input', this._handlers.input);
391
+ this.shadowRoot.addEventListener('keydown', this._handlers.keydown);
392
+ const input = this._getInput();
393
+ input.addEventListener('focus', this._handlers.focus);
394
+ input.addEventListener('blur', this._handlers.blur);
395
+ input.addEventListener('gv-input:clear', this._handlers.clear);
396
+ if (input.tagName.toLowerCase() === 'gv-input') {
397
+ input.setAttribute('no-submit', true);
398
+ }
399
+ }
400
+ _onOpened({ detail }) {
401
+ if (detail.target !== this) {
402
+ this._close();
403
+ }
404
+ }
405
+ connectedCallback() {
406
+ super.connectedCallback();
407
+ window.addEventListener('gv-autocomplete:opened', this._handleOpened);
408
+ }
409
+ disconnectedCallback() {
410
+ if (this._handlers) {
411
+ this.shadowRoot.removeEventListener('input', this._handlers.input);
412
+ this.shadowRoot.removeEventListener('keydown', this._handlers.keydown);
413
+ const input = this._getInput();
414
+ input.removeEventListener('focus', this._handlers.focus);
415
+ input.removeEventListener('blur', this._handlers.blur);
416
+ input.removeEventListener('gv-input:clear', this._handlers.clear);
417
+ }
418
+ window.removeEventListener('gv-autocomplete:open', this._handleOpened);
419
+ super.disconnectedCallback();
420
+ }
421
+ }
422
+ window.customElements.define('gv-autocomplete', GvAutocomplete);