@shoper/phoenix_design_system 1.17.16-4 → 1.17.16-6

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.
@@ -76,10 +76,6 @@ exports.HSearchResults = class HSearchResults extends phoenix_light_lit_element.
76
76
  locale="${this.locale}"
77
77
  view="${this.view}"
78
78
  module-instance-id="${this.moduleInstanceId}"
79
- search-phrase="${this.searchPhrase}"
80
- .suggestions="${this.results.suggestions}"
81
- .products="${this.results.products}"
82
- .categories="${this.results.categories}"
83
79
  .suggestionAriaLabel=${this.settings.suggesterItemAriaLabel}
84
80
  >
85
81
  </h-search-suggestion-content>`)}
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,qDAAyD;AACjF;AACA;AACA;AACA;AACA,iBAAiB,8DAAkE;AACnF,mBAAmB,8DAAkE;AACrF;AACA,sBAAsB,oDAAwD;AAC9E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,qDAAyD;AACjF;AACA;AACA;AACA;AACA,iBAAiB,8DAAkE;AACnF,mBAAmB,8DAAkE;AACrF;AACA,sBAAsB,oDAAwD;AAC9E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -7,6 +7,8 @@ var lit = require('lit');
7
7
  var decorators = require('lit/decorators');
8
8
  var phoenix_light_lit_element = require('../../../../../core/phoenix_light_lit_element/phoenix_light_lit_element.js');
9
9
  var phoenix_custom_element = require('../../../../../core/decorators/phoenix_custom_element.js');
10
+ var observer = require('../../../../../core/classes/observer/observer.js');
11
+ var context_consumer_controller = require('../../../../../core/context/context_consumer_controller.js');
10
12
  var when = require('../../../../../../../../external/lit-html/directives/when.js');
11
13
  var search_constants = require('../../search_constants.js');
12
14
  var repeat = require('../../../../../../../../external/lit-html/directives/repeat.js');
@@ -14,7 +16,9 @@ var repeat = require('../../../../../../../../external/lit-html/directives/repea
14
16
  exports.HSearchSuggestionContent = class HSearchSuggestionContent extends phoenix_light_lit_element.PhoenixLightLitElement {
15
17
  constructor() {
16
18
  super(...arguments);
19
+ this.initialItemIds = {};
17
20
  this.translations = {};
21
+ this._searchPhrase = '';
18
22
  this._suggestionsData = [];
19
23
  this._updateSearchPhrase = (ev, suggestion) => {
20
24
  ev.stopPropagation();
@@ -23,29 +27,40 @@ exports.HSearchSuggestionContent = class HSearchSuggestionContent extends phoeni
23
27
  }
24
28
  async connectedCallback() {
25
29
  super.connectedCallback();
26
- this._setupSuggestionData();
30
+ try {
31
+ this._searchContextConsumer = new context_consumer_controller.ContextConsumerController(this);
32
+ this._searchContext$ = await this._searchContextConsumer.consumeAsync(this.moduleInstanceId);
33
+ this._searchContextObserver = new observer.Observer((searchData) => {
34
+ this._searchPhrase = searchData.searchPhrase;
35
+ this._setupSuggestionData(searchData.results);
36
+ });
37
+ this._searchContext$.subscribe(this._searchContextObserver);
38
+ }
39
+ catch (_a) {
40
+ console.error('Search context is not provided');
41
+ }
27
42
  }
28
- _setupSuggestionData() {
43
+ _setupSuggestionData(results) {
29
44
  let suggestionsData = [];
30
- if (this.suggestions.length) {
31
- this.suggestions.forEach((suggestion, index) => {
45
+ if (results.suggestions.length) {
46
+ results.suggestions.forEach((suggestion, index) => {
32
47
  suggestionsData.push({ suggestionName: suggestion, type: search_constants.SUGGESTIONS_TYPE.suggestion });
33
48
  if (index)
34
49
  return;
35
- const isProductInTheCategory = this.products.length;
50
+ const isProductInTheCategory = results.products.length;
36
51
  if (isProductInTheCategory) {
37
52
  const lang = this.locale.split('_')[0];
38
53
  suggestionsData.push({
39
54
  suggestionName: suggestion,
40
- categoryName: this.products[0].category.breadcrumbs,
55
+ categoryName: results.products[0].category.breadcrumbs,
41
56
  type: search_constants.SUGGESTIONS_TYPE.suggestionInCategory,
42
- url: `/${lang}/c/${this.products[0].category.name}/${this.products[0].category.categoryId}/1/${this.view}/1/searchquery/${suggestion}`
57
+ url: `/${lang}/c/${results.products[0].category.name}/${results.products[0].category.categoryId}/1/${this.view}/1/searchquery/${suggestion}`
43
58
  });
44
59
  }
45
- if (this.categories.length) {
60
+ if (results.categories.length) {
46
61
  suggestionsData = [
47
62
  ...suggestionsData,
48
- ...this.categories.map((category) => ({
63
+ ...results.categories.map((category) => ({
49
64
  categoryName: category.name,
50
65
  url: category.url,
51
66
  type: search_constants.SUGGESTIONS_TYPE.category
@@ -54,9 +69,9 @@ exports.HSearchSuggestionContent = class HSearchSuggestionContent extends phoeni
54
69
  }
55
70
  });
56
71
  }
57
- else if (this.categories.length) {
72
+ else if (results.categories.length) {
58
73
  suggestionsData = [
59
- ...this.categories.map((category) => ({
74
+ ...results.categories.map((category) => ({
60
75
  categoryName: category.name,
61
76
  url: category.url,
62
77
  type: search_constants.SUGGESTIONS_TYPE.category
@@ -65,11 +80,6 @@ exports.HSearchSuggestionContent = class HSearchSuggestionContent extends phoeni
65
80
  }
66
81
  this._suggestionsData = suggestionsData;
67
82
  }
68
- _handleSuggestionWithKeyboard(ev, suggestion, suggestionType) {
69
- if (ev.key !== 'Enter' && ev.key !== ' ')
70
- return;
71
- this._handleSuggestion(suggestion, suggestionType);
72
- }
73
83
  _handleSuggestion(suggestion, suggestionType) {
74
84
  if (suggestionType !== search_constants.SUGGESTIONS_TYPE.suggestion)
75
85
  return;
@@ -84,10 +94,10 @@ exports.HSearchSuggestionContent = class HSearchSuggestionContent extends phoeni
84
94
  });
85
95
  }
86
96
  _getMatchedPhrase(phrase) {
87
- const phraseIncludesSearchPhrase = phrase.toLowerCase().includes(this.searchPhrase);
97
+ const phraseIncludesSearchPhrase = phrase.toLowerCase().includes(this._searchPhrase);
88
98
  if (!phraseIncludesSearchPhrase)
89
99
  return lit.html `${phrase}`;
90
- const index = phrase.toLowerCase().indexOf(this.searchPhrase) + this.searchPhrase.length;
100
+ const index = phrase.toLowerCase().indexOf(this._searchPhrase) + this._searchPhrase.length;
91
101
  return lit.html `${phrase.substring(0, index)}<strong>${phrase.substring(index)}</strong>`;
92
102
  }
93
103
  render() {
@@ -97,7 +107,6 @@ exports.HSearchSuggestionContent = class HSearchSuggestionContent extends phoeni
97
107
  <ul>
98
108
  ${repeat.repeat(this._suggestionsData, (suggestion, index) => lit.html `<li
99
109
  @click=${() => this._handleSuggestion(suggestion.suggestionName, suggestion.type)}
100
- @keydown=${(ev) => this._handleSuggestionWithKeyboard(ev, suggestion.suggestionName, suggestion.type)}
101
110
  class="${search_constants.SEARCH_CLASS_NAMES.item} ${search_constants.SEARCH_CLASS_NAMES.itemHoverable} ${String(index) === this.activeItemId
102
111
  ? search_constants.SEARCH_CLASS_NAMES.itemActive
103
112
  : ''}"
@@ -106,7 +115,7 @@ exports.HSearchSuggestionContent = class HSearchSuggestionContent extends phoeni
106
115
  aria-label="${this.suggestionAriaLabel ?
107
116
  `${this.suggestionAriaLabel} ${suggestion.suggestionName || suggestion.categoryName}` :
108
117
  ''}"
109
- tabindex=${this.closest('.search_mobile-opened, [display-mode="dropdown"]') || suggestion.type === search_constants.SUGGESTIONS_TYPE.suggestion ? '0' : undefined}
118
+ tabindex="0"
110
119
  role="option"
111
120
  >
112
121
  ${when.when(suggestion.type === search_constants.SUGGESTIONS_TYPE.suggestion, () => lit.html ` <span> ${this._getMatchedPhrase(suggestion.suggestionName)} </span>
@@ -137,6 +146,10 @@ tslib_es6.__decorate([
137
146
  decorators.property({ type: String, attribute: 'search-id' }),
138
147
  tslib_es6.__metadata("design:type", String)
139
148
  ], exports.HSearchSuggestionContent.prototype, "searchId", void 0);
149
+ tslib_es6.__decorate([
150
+ decorators.property({ type: Object, reflect: true }),
151
+ tslib_es6.__metadata("design:type", Object)
152
+ ], exports.HSearchSuggestionContent.prototype, "initialItemIds", void 0);
140
153
  tslib_es6.__decorate([
141
154
  decorators.property({ type: Object }),
142
155
  tslib_es6.__metadata("design:type", Object)
@@ -153,26 +166,14 @@ tslib_es6.__decorate([
153
166
  decorators.property({ type: String, attribute: 'module-instance-id' }),
154
167
  tslib_es6.__metadata("design:type", String)
155
168
  ], exports.HSearchSuggestionContent.prototype, "moduleInstanceId", void 0);
156
- tslib_es6.__decorate([
157
- decorators.property({ type: String, attribute: 'search-phrase' }),
158
- tslib_es6.__metadata("design:type", String)
159
- ], exports.HSearchSuggestionContent.prototype, "searchPhrase", void 0);
160
- tslib_es6.__decorate([
161
- decorators.property({ type: Object }),
162
- tslib_es6.__metadata("design:type", Array)
163
- ], exports.HSearchSuggestionContent.prototype, "suggestions", void 0);
164
- tslib_es6.__decorate([
165
- decorators.property({ type: Object }),
166
- tslib_es6.__metadata("design:type", Array)
167
- ], exports.HSearchSuggestionContent.prototype, "products", void 0);
168
- tslib_es6.__decorate([
169
- decorators.property({ type: Object, attribute: false }),
170
- tslib_es6.__metadata("design:type", Array)
171
- ], exports.HSearchSuggestionContent.prototype, "categories", void 0);
172
169
  tslib_es6.__decorate([
173
170
  decorators.property({ type: String }),
174
171
  tslib_es6.__metadata("design:type", String)
175
172
  ], exports.HSearchSuggestionContent.prototype, "suggestionAriaLabel", void 0);
173
+ tslib_es6.__decorate([
174
+ decorators.state(),
175
+ tslib_es6.__metadata("design:type", String)
176
+ ], exports.HSearchSuggestionContent.prototype, "_searchPhrase", void 0);
176
177
  tslib_es6.__decorate([
177
178
  decorators.state(),
178
179
  tslib_es6.__metadata("design:type", Array)
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,qDAAyD;AACjF;AACA;AACA;AACA;AACA,mBAAmB,8DAAkE;AACrF;AACA,qBAAqB,gEAAoE;AACzF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,qDAAyD;AACjF;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,8DAAkE;AACrF;AACA,qBAAqB,gEAAoE;AACzF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -72,10 +72,6 @@ let HSearchResults = class HSearchResults extends PhoenixLightLitElement {
72
72
  locale="${this.locale}"
73
73
  view="${this.view}"
74
74
  module-instance-id="${this.moduleInstanceId}"
75
- search-phrase="${this.searchPhrase}"
76
- .suggestions="${this.results.suggestions}"
77
- .products="${this.results.products}"
78
- .categories="${this.results.categories}"
79
75
  .suggestionAriaLabel=${this.settings.suggesterItemAriaLabel}
80
76
  >
81
77
  </h-search-suggestion-content>`)}
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,uCAAuC,qDAAyD;AAChG;AACA;AACA;AACA;AACA,eAAe,8DAAkE;AACjF,0BAA0B,8DAAkE;AAC5F;AACA,sBAAsB,oDAAwD;AAC9E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,uCAAuC,qDAAyD;AAChG;AACA;AACA;AACA;AACA,eAAe,8DAAkE;AACjF,0BAA0B,8DAAkE;AAC5F;AACA,sBAAsB,oDAAwD;AAC9E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -1,22 +1,21 @@
1
1
  import { TemplateResult } from 'lit';
2
2
  import { PhoenixLightLitElement } from "../../../../../core/phoenix_light_lit_element/phoenix_light_lit_element";
3
- import type { TCategory, TProduct } from "../../search_types";
4
3
  export declare class HSearchSuggestionContent extends PhoenixLightLitElement {
4
+ private _searchContextConsumer;
5
+ private _searchContext$;
6
+ private _searchContextObserver;
5
7
  activeItemId: string;
6
8
  searchId: string;
9
+ initialItemIds: Record<string, number>;
7
10
  translations: Record<string, string>;
8
11
  view: string;
9
12
  locale: string;
10
13
  moduleInstanceId: string;
11
- searchPhrase: string;
12
- suggestions: string[];
13
- products: TProduct[];
14
- categories: TCategory[];
15
14
  suggestionAriaLabel?: string;
15
+ private _searchPhrase;
16
16
  private _suggestionsData;
17
17
  connectedCallback(): Promise<void>;
18
18
  private _setupSuggestionData;
19
- private _handleSuggestionWithKeyboard;
20
19
  private _handleSuggestion;
21
20
  private _dispatchEventWithSearchPhrase;
22
21
  private _getMatchedPhrase;
@@ -3,6 +3,8 @@ import { html } from 'lit';
3
3
  import { property, state } from 'lit/decorators';
4
4
  import { PhoenixLightLitElement } from '../../../../../core/phoenix_light_lit_element/phoenix_light_lit_element.js';
5
5
  import { phoenixCustomElement } from '../../../../../core/decorators/phoenix_custom_element.js';
6
+ import { Observer } from '../../../../../core/classes/observer/observer.js';
7
+ import { ContextConsumerController } from '../../../../../core/context/context_consumer_controller.js';
6
8
  import { when as n } from '../../../../../../../../external/lit-html/directives/when.js';
7
9
  import { SEARCH_CUSTOM_EVENT_NAMES, SUGGESTIONS_TYPE, SEARCH_CLASS_NAMES, SEARCH_COMPONENT_NAMES } from '../../search_constants.js';
8
10
  import { repeat as c } from '../../../../../../../../external/lit-html/directives/repeat.js';
@@ -10,7 +12,9 @@ import { repeat as c } from '../../../../../../../../external/lit-html/directive
10
12
  let HSearchSuggestionContent = class HSearchSuggestionContent extends PhoenixLightLitElement {
11
13
  constructor() {
12
14
  super(...arguments);
15
+ this.initialItemIds = {};
13
16
  this.translations = {};
17
+ this._searchPhrase = '';
14
18
  this._suggestionsData = [];
15
19
  this._updateSearchPhrase = (ev, suggestion) => {
16
20
  ev.stopPropagation();
@@ -19,29 +23,40 @@ let HSearchSuggestionContent = class HSearchSuggestionContent extends PhoenixLig
19
23
  }
20
24
  async connectedCallback() {
21
25
  super.connectedCallback();
22
- this._setupSuggestionData();
26
+ try {
27
+ this._searchContextConsumer = new ContextConsumerController(this);
28
+ this._searchContext$ = await this._searchContextConsumer.consumeAsync(this.moduleInstanceId);
29
+ this._searchContextObserver = new Observer((searchData) => {
30
+ this._searchPhrase = searchData.searchPhrase;
31
+ this._setupSuggestionData(searchData.results);
32
+ });
33
+ this._searchContext$.subscribe(this._searchContextObserver);
34
+ }
35
+ catch (_a) {
36
+ console.error('Search context is not provided');
37
+ }
23
38
  }
24
- _setupSuggestionData() {
39
+ _setupSuggestionData(results) {
25
40
  let suggestionsData = [];
26
- if (this.suggestions.length) {
27
- this.suggestions.forEach((suggestion, index) => {
41
+ if (results.suggestions.length) {
42
+ results.suggestions.forEach((suggestion, index) => {
28
43
  suggestionsData.push({ suggestionName: suggestion, type: SUGGESTIONS_TYPE.suggestion });
29
44
  if (index)
30
45
  return;
31
- const isProductInTheCategory = this.products.length;
46
+ const isProductInTheCategory = results.products.length;
32
47
  if (isProductInTheCategory) {
33
48
  const lang = this.locale.split('_')[0];
34
49
  suggestionsData.push({
35
50
  suggestionName: suggestion,
36
- categoryName: this.products[0].category.breadcrumbs,
51
+ categoryName: results.products[0].category.breadcrumbs,
37
52
  type: SUGGESTIONS_TYPE.suggestionInCategory,
38
- url: `/${lang}/c/${this.products[0].category.name}/${this.products[0].category.categoryId}/1/${this.view}/1/searchquery/${suggestion}`
53
+ url: `/${lang}/c/${results.products[0].category.name}/${results.products[0].category.categoryId}/1/${this.view}/1/searchquery/${suggestion}`
39
54
  });
40
55
  }
41
- if (this.categories.length) {
56
+ if (results.categories.length) {
42
57
  suggestionsData = [
43
58
  ...suggestionsData,
44
- ...this.categories.map((category) => ({
59
+ ...results.categories.map((category) => ({
45
60
  categoryName: category.name,
46
61
  url: category.url,
47
62
  type: SUGGESTIONS_TYPE.category
@@ -50,9 +65,9 @@ let HSearchSuggestionContent = class HSearchSuggestionContent extends PhoenixLig
50
65
  }
51
66
  });
52
67
  }
53
- else if (this.categories.length) {
68
+ else if (results.categories.length) {
54
69
  suggestionsData = [
55
- ...this.categories.map((category) => ({
70
+ ...results.categories.map((category) => ({
56
71
  categoryName: category.name,
57
72
  url: category.url,
58
73
  type: SUGGESTIONS_TYPE.category
@@ -61,11 +76,6 @@ let HSearchSuggestionContent = class HSearchSuggestionContent extends PhoenixLig
61
76
  }
62
77
  this._suggestionsData = suggestionsData;
63
78
  }
64
- _handleSuggestionWithKeyboard(ev, suggestion, suggestionType) {
65
- if (ev.key !== 'Enter' && ev.key !== ' ')
66
- return;
67
- this._handleSuggestion(suggestion, suggestionType);
68
- }
69
79
  _handleSuggestion(suggestion, suggestionType) {
70
80
  if (suggestionType !== SUGGESTIONS_TYPE.suggestion)
71
81
  return;
@@ -80,10 +90,10 @@ let HSearchSuggestionContent = class HSearchSuggestionContent extends PhoenixLig
80
90
  });
81
91
  }
82
92
  _getMatchedPhrase(phrase) {
83
- const phraseIncludesSearchPhrase = phrase.toLowerCase().includes(this.searchPhrase);
93
+ const phraseIncludesSearchPhrase = phrase.toLowerCase().includes(this._searchPhrase);
84
94
  if (!phraseIncludesSearchPhrase)
85
95
  return html `${phrase}`;
86
- const index = phrase.toLowerCase().indexOf(this.searchPhrase) + this.searchPhrase.length;
96
+ const index = phrase.toLowerCase().indexOf(this._searchPhrase) + this._searchPhrase.length;
87
97
  return html `${phrase.substring(0, index)}<strong>${phrase.substring(index)}</strong>`;
88
98
  }
89
99
  render() {
@@ -93,7 +103,6 @@ let HSearchSuggestionContent = class HSearchSuggestionContent extends PhoenixLig
93
103
  <ul>
94
104
  ${c(this._suggestionsData, (suggestion, index) => html `<li
95
105
  @click=${() => this._handleSuggestion(suggestion.suggestionName, suggestion.type)}
96
- @keydown=${(ev) => this._handleSuggestionWithKeyboard(ev, suggestion.suggestionName, suggestion.type)}
97
106
  class="${SEARCH_CLASS_NAMES.item} ${SEARCH_CLASS_NAMES.itemHoverable} ${String(index) === this.activeItemId
98
107
  ? SEARCH_CLASS_NAMES.itemActive
99
108
  : ''}"
@@ -102,7 +111,7 @@ let HSearchSuggestionContent = class HSearchSuggestionContent extends PhoenixLig
102
111
  aria-label="${this.suggestionAriaLabel ?
103
112
  `${this.suggestionAriaLabel} ${suggestion.suggestionName || suggestion.categoryName}` :
104
113
  ''}"
105
- tabindex=${this.closest('.search_mobile-opened, [display-mode="dropdown"]') || suggestion.type === SUGGESTIONS_TYPE.suggestion ? '0' : undefined}
114
+ tabindex="0"
106
115
  role="option"
107
116
  >
108
117
  ${n(suggestion.type === SUGGESTIONS_TYPE.suggestion, () => html ` <span> ${this._getMatchedPhrase(suggestion.suggestionName)} </span>
@@ -133,6 +142,10 @@ __decorate([
133
142
  property({ type: String, attribute: 'search-id' }),
134
143
  __metadata("design:type", String)
135
144
  ], HSearchSuggestionContent.prototype, "searchId", void 0);
145
+ __decorate([
146
+ property({ type: Object, reflect: true }),
147
+ __metadata("design:type", Object)
148
+ ], HSearchSuggestionContent.prototype, "initialItemIds", void 0);
136
149
  __decorate([
137
150
  property({ type: Object }),
138
151
  __metadata("design:type", Object)
@@ -149,26 +162,14 @@ __decorate([
149
162
  property({ type: String, attribute: 'module-instance-id' }),
150
163
  __metadata("design:type", String)
151
164
  ], HSearchSuggestionContent.prototype, "moduleInstanceId", void 0);
152
- __decorate([
153
- property({ type: String, attribute: 'search-phrase' }),
154
- __metadata("design:type", String)
155
- ], HSearchSuggestionContent.prototype, "searchPhrase", void 0);
156
- __decorate([
157
- property({ type: Object }),
158
- __metadata("design:type", Array)
159
- ], HSearchSuggestionContent.prototype, "suggestions", void 0);
160
- __decorate([
161
- property({ type: Object }),
162
- __metadata("design:type", Array)
163
- ], HSearchSuggestionContent.prototype, "products", void 0);
164
- __decorate([
165
- property({ type: Object, attribute: false }),
166
- __metadata("design:type", Array)
167
- ], HSearchSuggestionContent.prototype, "categories", void 0);
168
165
  __decorate([
169
166
  property({ type: String }),
170
167
  __metadata("design:type", String)
171
168
  ], HSearchSuggestionContent.prototype, "suggestionAriaLabel", void 0);
169
+ __decorate([
170
+ state(),
171
+ __metadata("design:type", String)
172
+ ], HSearchSuggestionContent.prototype, "_searchPhrase", void 0);
172
173
  __decorate([
173
174
  state(),
174
175
  __metadata("design:type", Array)
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,uCAAuC,qDAAyD;AAChG;AACA;AACA;AACA;AACA,0BAA0B,8DAAkE;AAC5F;AACA,4BAA4B,gEAAoE;AAChG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,uCAAuC,qDAAyD;AAChG;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,8DAAkE;AAC5F;AACA,4BAA4B,gEAAoE;AAChG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@shoper/phoenix_design_system",
3
3
  "packageManager": "yarn@3.2.0",
4
4
  "sideEffects": false,
5
- "version": "1.17.16-4",
5
+ "version": "1.17.16-6",
6
6
  "description": "phoenix design system",
7
7
  "author": "zefirek",
8
8
  "license": "MIT",