@coveo/atomic 3.34.0-pre.15af8fb61b → 3.34.0-pre.1ad38ff1e4

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 (100) hide show
  1. package/dist/atomic/_atomic.esm.js +1 -1
  2. package/dist/atomic/atomic.esm.js.map +1 -1
  3. package/dist/atomic/components/_index.d.ts +2 -0
  4. package/dist/atomic/components/_index.js +1 -0
  5. package/dist/atomic/components/analytics-config.js +1 -1
  6. package/dist/atomic/components/atomic-insight-history-toggle.js +2 -2
  7. package/dist/atomic/components/atomic-insight-history-toggle.js.map +1 -1
  8. package/dist/atomic/components/atomic-insight-user-actions-toggle.js +2 -2
  9. package/dist/atomic/components/atomic-insight-user-actions-toggle.js.map +1 -1
  10. package/dist/atomic/components/atomic-search-box-recent-queries.d.ts +11 -0
  11. package/dist/atomic/components/atomic-search-box-recent-queries.js +8 -0
  12. package/dist/atomic/components/atomic-search-box-recent-queries.js.map +1 -0
  13. package/dist/atomic/components/atomic-search-box-recent-queries2.js +183 -0
  14. package/dist/atomic/components/atomic-search-box-recent-queries2.js.map +1 -0
  15. package/dist/atomic/components/atomic-search-box.js +8 -2
  16. package/dist/atomic/components/atomic-search-box.js.map +1 -1
  17. package/dist/atomic/components/atomic-smart-snippet-feedback-modal2.js +2 -2
  18. package/dist/atomic/components/atomic-tab-manager.js +1 -1
  19. package/dist/atomic/components/clock.js +2 -2
  20. package/dist/atomic/components/components/commerce/atomic-product/atomic-product.js +41 -56
  21. package/dist/atomic/components/components/common/layout/custom-render-controller.js +48 -0
  22. package/dist/atomic/components/components/common/layout/item-layout-controller.js +105 -0
  23. package/dist/atomic/components/components/search/index.js +0 -1
  24. package/dist/atomic/components/components/search/lazy-index.js +0 -1
  25. package/dist/atomic/components/global/environment.js +1 -1
  26. package/dist/atomic/components/index.js.map +1 -1
  27. package/dist/atomic/{p-11b094f7.entry.js → p-0c5fff04.entry.js} +2 -2
  28. package/dist/atomic/{p-bf81c1d3.js → p-1b364176.js} +2 -2
  29. package/dist/atomic/{p-ca3dc59b.entry.js → p-20764605.entry.js} +2 -2
  30. package/dist/atomic/{p-6078667f.entry.js → p-406a288c.entry.js} +2 -2
  31. package/dist/atomic/{p-9239be63.entry.js → p-6289adc7.entry.js} +2 -2
  32. package/dist/atomic/{p-5a710350.entry.js → p-88af4470.entry.js} +2 -2
  33. package/dist/atomic/{p-1d10c438.entry.js → p-8c47cfdb.entry.js} +2 -2
  34. package/dist/atomic/{p-e1cc5150.js → p-c280cd05.js} +1 -1
  35. package/dist/atomic/p-df4397ab.entry.js +2 -0
  36. package/dist/atomic/p-df4397ab.entry.js.map +1 -0
  37. package/dist/cjs/_loader.cjs.js +1 -1
  38. package/dist/cjs/{analytics-config-f40518ec.js → analytics-config-83f4fb5d.js} +2 -2
  39. package/dist/cjs/{analytics-config-f40518ec.js.map → analytics-config-83f4fb5d.js.map} +1 -1
  40. package/dist/cjs/atomic-insight-history-toggle.cjs.entry.js +2 -2
  41. package/dist/cjs/atomic-insight-history-toggle.cjs.entry.js.map +1 -1
  42. package/dist/cjs/atomic-insight-interface.cjs.entry.js +1 -1
  43. package/dist/cjs/atomic-insight-user-actions-toggle.cjs.entry.js +2 -2
  44. package/dist/cjs/atomic-insight-user-actions-toggle.cjs.entry.js.map +1 -1
  45. package/dist/cjs/atomic-recs-interface.cjs.entry.js +1 -1
  46. package/dist/cjs/atomic-search-box-query-suggestions_2.cjs.entry.js +234 -0
  47. package/dist/cjs/atomic-search-box-query-suggestions_2.cjs.entry.js.map +1 -0
  48. package/dist/cjs/atomic-smart-snippet-feedback-modal.cjs.entry.js +2 -2
  49. package/dist/cjs/atomic-tab-manager.cjs.entry.js +1 -1
  50. package/dist/cjs/atomic.cjs.js +1 -1
  51. package/dist/cjs/clock-f03ff827.js +7 -0
  52. package/dist/cjs/clock-f03ff827.js.map +1 -0
  53. package/dist/cjs/index-757bc886.js +2 -2
  54. package/dist/cjs/version.cjs.js +1 -1
  55. package/dist/esm/_loader.js +1 -1
  56. package/dist/esm/{analytics-config-49aa97b1.js → analytics-config-b6bd56be.js} +2 -2
  57. package/dist/esm/{analytics-config-49aa97b1.js.map → analytics-config-b6bd56be.js.map} +1 -1
  58. package/dist/esm/atomic-insight-history-toggle.entry.js +2 -2
  59. package/dist/esm/atomic-insight-history-toggle.entry.js.map +1 -1
  60. package/dist/esm/atomic-insight-interface.entry.js +1 -1
  61. package/dist/esm/atomic-insight-user-actions-toggle.entry.js +2 -2
  62. package/dist/esm/atomic-insight-user-actions-toggle.entry.js.map +1 -1
  63. package/dist/esm/atomic-recs-interface.entry.js +1 -1
  64. package/dist/esm/atomic-search-box-query-suggestions_2.entry.js +229 -0
  65. package/dist/esm/atomic-search-box-query-suggestions_2.entry.js.map +1 -0
  66. package/dist/esm/atomic-smart-snippet-feedback-modal.entry.js +2 -2
  67. package/dist/esm/atomic-tab-manager.entry.js +1 -1
  68. package/dist/esm/atomic.js +1 -1
  69. package/dist/esm/clock-add3e9a5.js +5 -0
  70. package/dist/esm/clock-add3e9a5.js.map +1 -0
  71. package/dist/esm/index-3f35faca.js +2 -2
  72. package/dist/esm/version.js +1 -1
  73. package/dist/types/components/commerce/atomic-product/atomic-product.d.ts +10 -13
  74. package/dist/types/components/common/layout/custom-render-controller.d.ts +28 -0
  75. package/dist/types/components/common/layout/item-layout-controller.d.ts +46 -0
  76. package/dist/types/components/search/index.d.ts +0 -1
  77. package/dist/types/components/search/search-box-suggestions/atomic-search-box-recent-queries/atomic-search-box-recent-queries.d.ts +37 -0
  78. package/dist/types/components.d.ts +49 -0
  79. package/docs/atomic-docs.json +98 -1
  80. package/package.json +1 -1
  81. package/dist/atomic/components/components/search/atomic-search-box-recent-queries/atomic-search-box-recent-queries.js +0 -137
  82. package/dist/atomic/p-899d19ef.entry.js +0 -2
  83. package/dist/atomic/p-899d19ef.entry.js.map +0 -1
  84. package/dist/cjs/atomic-search-box-query-suggestions.cjs.entry.js +0 -76
  85. package/dist/cjs/atomic-search-box-query-suggestions.cjs.entry.js.map +0 -1
  86. package/dist/cjs/clock-7aeb19d0.js +0 -7
  87. package/dist/cjs/clock-7aeb19d0.js.map +0 -1
  88. package/dist/esm/atomic-search-box-query-suggestions.entry.js +0 -72
  89. package/dist/esm/atomic-search-box-query-suggestions.entry.js.map +0 -1
  90. package/dist/esm/clock-b1f5d7f7.js +0 -5
  91. package/dist/esm/clock-b1f5d7f7.js.map +0 -1
  92. package/dist/types/components/search/atomic-search-box-recent-queries/atomic-search-box-recent-queries.d.ts +0 -45
  93. /package/dist/atomic/{p-11b094f7.entry.js.map → p-0c5fff04.entry.js.map} +0 -0
  94. /package/dist/atomic/{p-bf81c1d3.js.map → p-1b364176.js.map} +0 -0
  95. /package/dist/atomic/{p-ca3dc59b.entry.js.map → p-20764605.entry.js.map} +0 -0
  96. /package/dist/atomic/{p-6078667f.entry.js.map → p-406a288c.entry.js.map} +0 -0
  97. /package/dist/atomic/{p-9239be63.entry.js.map → p-6289adc7.entry.js.map} +0 -0
  98. /package/dist/atomic/{p-5a710350.entry.js.map → p-88af4470.entry.js.map} +0 -0
  99. /package/dist/atomic/{p-1d10c438.entry.js.map → p-8c47cfdb.entry.js.map} +0 -0
  100. /package/dist/atomic/{p-e1cc5150.js.map → p-c280cd05.js.map} +0 -0
@@ -8,7 +8,8 @@ import { html, LitElement } from 'lit';
8
8
  import { customElement, property } from 'lit/decorators.js';
9
9
  import { ref } from 'lit/directives/ref.js';
10
10
  import { resultComponentClass, } from "../../common/item-list/item-list-common";
11
- import { ItemLayout, } from "../../common/layout/display-options";
11
+ import { CustomRenderController } from "../../common/layout/custom-render-controller";
12
+ import { ItemLayoutController } from "../../common/layout/item-layout-controller";
12
13
  import { booleanConverter } from "../../../converters/boolean-converter";
13
14
  import { withTailwindStyles } from "../../../decorators/with-tailwind-styles";
14
15
  import { ChildrenUpdateCompleteMixin } from "../../../mixins/children-update-complete-mixin";
@@ -20,7 +21,6 @@ import styles from './atomic-product.tw.css';
20
21
  let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitElement) {
21
22
  constructor() {
22
23
  super(...arguments);
23
- this.executedRenderingFunctionOnce = false;
24
24
  /**
25
25
  * The product link to use when the product is clicked in a grid layout.
26
26
  *
@@ -45,6 +45,13 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
45
45
  * The classes to add to the product element.
46
46
  */
47
47
  this.classes = '';
48
+ /**
49
+ * Whether to automatically apply layout classes to rendered elements when using a custom rendering function.
50
+ * When disabled, the component will automatically find and apply layout classes to child elements with 'atomic-product-' prefixes.
51
+ *
52
+ * @internal
53
+ */
54
+ this.disableLayoutClassesForCustomRender = false;
48
55
  this.resolveProduct = (event) => {
49
56
  event.preventDefault();
50
57
  event.stopPropagation();
@@ -84,11 +91,27 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
84
91
  }
85
92
  async connectedCallback() {
86
93
  super.connectedCallback();
87
- if (!this.content) {
88
- console.warn('AtomicProduct: content property is undefined. Cannot create layout.', this);
89
- return;
90
- }
91
- this.layout = new ItemLayout(this.content.children, this.display, this.density, this.imageSize);
94
+ this.customRenderController = new CustomRenderController(this, {
95
+ renderingFunction: () => this.renderingFunction,
96
+ itemData: () => this.product,
97
+ rootElementRef: () => this.productRootRef,
98
+ linkContainerRef: () => this.linkContainerRef,
99
+ onRenderComplete: (element, output) => {
100
+ this.itemLayoutController.applyLayoutClassesToElement(element, output);
101
+ },
102
+ });
103
+ this.itemLayoutController = new ItemLayoutController(this, {
104
+ elementPrefix: 'atomic-product',
105
+ hasCustomRenderFunction: () => this.customRenderController.hasCustomRenderFunction,
106
+ disableLayoutClassesForCustomRender: () => this.disableLayoutClassesForCustomRender,
107
+ content: () => this.content,
108
+ layoutConfig: () => ({
109
+ display: this.display,
110
+ density: this.density,
111
+ imageSize: this.imageSize,
112
+ }),
113
+ itemClasses: () => this.classes,
114
+ });
92
115
  this.addEventListener('atomic/resolveResult', this.resolveProduct);
93
116
  this.addEventListener('atomic/resolveInteractiveResult', this.resolveInteractiveProduct);
94
117
  this.addEventListener('atomic/resolveStopPropagation', this.resolveStopPropagation);
@@ -105,12 +128,9 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
105
128
  this.removeEventListener('atomic/resolveResultDisplayConfig', this.resolveProductDisplayConfig);
106
129
  this.removeEventListener('click', this.handleClick);
107
130
  }
108
- get isCustomRenderFunctionMode() {
109
- return this.renderingFunction !== undefined;
110
- }
111
131
  getContentHTML() {
112
132
  if (!this.content) {
113
- console.warn('AtomicProduct: content property is undefined. Cannot get content HTML.', this);
133
+ console.warn('atomic-product: content property is undefined. Cannot get content HTML.', this);
114
134
  return '';
115
135
  }
116
136
  return parentNodeToString(this.content);
@@ -118,13 +138,8 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
118
138
  getLinkHTML() {
119
139
  return parentNodeToString(this.linkContent ?? new HTMLElement());
120
140
  }
121
- shouldExecuteRenderFunction() {
122
- return (this.isCustomRenderFunctionMode &&
123
- this.productRootRef &&
124
- !this.executedRenderingFunctionOnce);
125
- }
126
141
  render() {
127
- if (this.isCustomRenderFunctionMode) {
142
+ if (this.customRenderController.hasCustomRenderFunction) {
128
143
  return html `
129
144
  <div class=${resultComponentClass}>
130
145
  <div
@@ -143,16 +158,13 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
143
158
  `;
144
159
  }
145
160
  // Handle case where content is undefined and layout was not created
146
- if (!this.layout) {
161
+ if (!this.itemLayoutController.getLayout()) {
147
162
  return html `<div class=${resultComponentClass}></div>`;
148
163
  }
149
164
  return html `
150
165
  <div class=${resultComponentClass}>
151
166
  <div
152
- class="result-root ${this.layout
153
- .getClasses()
154
- .concat(this.classes)
155
- .join(' ')}"
167
+ class="result-root ${this.itemLayoutController.getCombinedClasses().join(' ')}"
156
168
  .innerHTML=${this.getContentHTML()}
157
169
  ></div>
158
170
  <div class="link-container" .innerHTML=${this.getLinkHTML()}></div>
@@ -164,41 +176,8 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
164
176
  this.store.unsetLoadingFlag(this.loadingFlag);
165
177
  }
166
178
  }
167
- getCombinedClasses(additionalContent) {
168
- const layoutClasses = this.layout
169
- ? this.layout.getClasses(additionalContent)
170
- : [];
171
- const extraClasses = this.classes.split(/\s+/).filter((c) => c);
172
- return [...layoutClasses, ...extraClasses];
173
- }
174
- applyClassesToChildren() {
175
- if (!this.layout) {
176
- return;
177
- }
178
- const classes = this.getCombinedClasses();
179
- const root = this.shadowRoot?.querySelector('.result-root');
180
- if (!root) {
181
- return;
182
- }
183
- root.querySelectorAll('*').forEach((el) => {
184
- const tag = el.tagName.toLowerCase();
185
- if (tag.startsWith('atomic-product-')) {
186
- el.classList.add(...classes);
187
- }
188
- });
189
- }
190
179
  updated(_changedProperties) {
191
- if (this.shouldExecuteRenderFunction()) {
192
- const customRenderOutputAsString = this.renderingFunction(this.product, this.productRootRef, this.linkContainerRef);
193
- if (this.layout) {
194
- const classes = this.getCombinedClasses(customRenderOutputAsString);
195
- this.productRootRef.classList.add(...classes);
196
- }
197
- this.executedRenderingFunctionOnce = true;
198
- }
199
- if (!this.isCustomRenderFunctionMode) {
200
- this.applyClassesToChildren();
201
- }
180
+ // Custom rendering is now handled by the ItemLayoutController
202
181
  }
203
182
  };
204
183
  AtomicProduct.styles = styles;
@@ -243,6 +222,12 @@ __decorate([
243
222
  __decorate([
244
223
  property({ type: Object, attribute: 'rendering-function' })
245
224
  ], AtomicProduct.prototype, "renderingFunction", void 0);
225
+ __decorate([
226
+ property({
227
+ attribute: 'disable-layout-classes-for-custom-render',
228
+ type: Boolean,
229
+ })
230
+ ], AtomicProduct.prototype, "disableLayoutClassesForCustomRender", void 0);
246
231
  AtomicProduct = __decorate([
247
232
  customElement('atomic-product'),
248
233
  withTailwindStyles
@@ -0,0 +1,48 @@
1
+ /**
2
+ * A reactive controller that manages custom rendering function execution for item components.
3
+ */
4
+ export class CustomRenderController {
5
+ constructor(host, options) {
6
+ this.hasExecutedRenderFunction = false;
7
+ this.options = {
8
+ linkContainerRef: () => undefined,
9
+ onRenderComplete: () => { },
10
+ ...options,
11
+ };
12
+ host.addController(this);
13
+ }
14
+ hostConnected() {
15
+ this.resetRenderState();
16
+ }
17
+ hostUpdated() {
18
+ if (this.shouldExecuteRenderFunction()) {
19
+ this.executeRenderFunction();
20
+ }
21
+ }
22
+ hostDisconnected() { }
23
+ get hasCustomRenderFunction() {
24
+ return this.options.renderingFunction() !== undefined;
25
+ }
26
+ resetRenderState() {
27
+ this.hasExecutedRenderFunction = false;
28
+ }
29
+ shouldExecuteRenderFunction() {
30
+ const renderingFunction = this.options.renderingFunction();
31
+ const rootElementRef = this.options.rootElementRef();
32
+ return !!(renderingFunction &&
33
+ rootElementRef &&
34
+ !this.hasExecutedRenderFunction);
35
+ }
36
+ executeRenderFunction() {
37
+ const renderingFunction = this.options.renderingFunction();
38
+ const itemData = this.options.itemData();
39
+ const rootElementRef = this.options.rootElementRef();
40
+ const linkContainerRef = this.options.linkContainerRef();
41
+ if (!renderingFunction || !itemData || !rootElementRef) {
42
+ return;
43
+ }
44
+ const customRenderOutput = renderingFunction(itemData, rootElementRef, linkContainerRef);
45
+ this.options.onRenderComplete(rootElementRef, customRenderOutput);
46
+ this.hasExecutedRenderFunction = true;
47
+ }
48
+ }
@@ -0,0 +1,105 @@
1
+ import { ItemLayout, } from './display-options';
2
+ /**
3
+ * A reactive controller that manages layout creation and class application for item components.
4
+ */
5
+ export class ItemLayoutController {
6
+ constructor(host, options) {
7
+ this.layoutInstance = null;
8
+ this.host = host;
9
+ this.options = {
10
+ disableLayoutClassesForCustomRender: () => false,
11
+ ...options,
12
+ };
13
+ host.addController(this);
14
+ }
15
+ hostConnected() {
16
+ this.createLayout();
17
+ }
18
+ hostUpdated() {
19
+ if (!(this.options.hasCustomRenderFunction() &&
20
+ this.options.disableLayoutClassesForCustomRender())) {
21
+ this.applyLayoutClasses();
22
+ }
23
+ }
24
+ hostDisconnected() { }
25
+ /**
26
+ * Gets the current layout instance
27
+ */
28
+ getLayout() {
29
+ return this.layoutInstance;
30
+ }
31
+ /**
32
+ * Gets combined layout and extra classes
33
+ */
34
+ getCombinedClasses(additionalContent) {
35
+ const layout = this.getLayout();
36
+ const layoutClasses = layout ? layout.getClasses(additionalContent) : [];
37
+ const itemClasses = this.options
38
+ .itemClasses()
39
+ .split(/\s+/)
40
+ .filter((c) => c);
41
+ return [...layoutClasses, ...itemClasses];
42
+ }
43
+ /**
44
+ * Applies layout classes to a specific element (useful for custom rendering)
45
+ */
46
+ applyLayoutClassesToElement(element, additionalContent) {
47
+ const layout = this.getLayout();
48
+ if (!layout) {
49
+ return;
50
+ }
51
+ const classes = this.getCombinedClasses(additionalContent);
52
+ if (classes.length > 0) {
53
+ element.classList.add(...classes);
54
+ }
55
+ }
56
+ applyLayoutClasses() {
57
+ const layout = this.getLayout();
58
+ if (!layout) {
59
+ return;
60
+ }
61
+ const classes = this.getCombinedClasses();
62
+ const root = this.host.shadowRoot?.querySelector('.result-root');
63
+ if (!root || classes.length === 0) {
64
+ return;
65
+ }
66
+ if (this.options.hasCustomRenderFunction()) {
67
+ this.observeAndApplyClasses(root, classes);
68
+ }
69
+ else {
70
+ this.addClassesToElements(root, classes);
71
+ }
72
+ }
73
+ createLayout() {
74
+ const content = this.options.content();
75
+ if (!content) {
76
+ console.warn(`${this.options.elementPrefix}: content property is undefined. Cannot create layout.`, this.host);
77
+ this.layoutInstance = null;
78
+ return;
79
+ }
80
+ const config = this.options.layoutConfig();
81
+ this.layoutInstance = new ItemLayout(content.children, config.display, config.density, config.imageSize);
82
+ }
83
+ addClassesToElements(root, classes) {
84
+ if (classes.length === 0) {
85
+ return;
86
+ }
87
+ const elements = root.querySelectorAll('*');
88
+ elements.forEach((element) => {
89
+ const tagName = element.tagName.toLowerCase();
90
+ if (tagName.startsWith(`${this.options.elementPrefix}-`)) {
91
+ element.classList.add(...classes);
92
+ }
93
+ });
94
+ }
95
+ observeAndApplyClasses(root, classes) {
96
+ const observer = new MutationObserver((mutations) => {
97
+ const hasNewElements = mutations.some((mutation) => mutation.type === 'childList' && mutation.addedNodes.length > 0);
98
+ if (hasNewElements) {
99
+ this.addClassesToElements(root, classes);
100
+ observer.disconnect();
101
+ }
102
+ });
103
+ observer.observe(root, { childList: true, subtree: true });
104
+ }
105
+ }
@@ -2,6 +2,5 @@
2
2
  export { AtomicPager } from './atomic-pager/atomic-pager.js';
3
3
  export { AtomicQuerySummary } from './atomic-query-summary/atomic-query-summary.js';
4
4
  export { AtomicResultsPerPage } from './atomic-results-per-page/atomic-results-per-page.js';
5
- export { AtomicSearchBoxRecentQueries } from './atomic-search-box-recent-queries/atomic-search-box-recent-queries.js';
6
5
  export { AtomicSearchInterface } from './atomic-search-interface/atomic-search-interface.js';
7
6
  export { AtomicSearchLayout } from './atomic-search-layout/atomic-search-layout.js';
@@ -3,7 +3,6 @@ export default {
3
3
  'atomic-pager': async () => await import('./atomic-pager/atomic-pager.js'),
4
4
  'atomic-query-summary': async () => await import('./atomic-query-summary/atomic-query-summary.js'),
5
5
  'atomic-results-per-page': async () => await import('./atomic-results-per-page/atomic-results-per-page.js'),
6
- 'atomic-search-box-recent-queries': async () => await import('./atomic-search-box-recent-queries/atomic-search-box-recent-queries.js'),
7
6
  'atomic-search-interface': async () => await import('./atomic-search-interface/atomic-search-interface.js'),
8
7
  'atomic-search-layout': async () => await import('./atomic-search-layout/atomic-search-layout.js'),
9
8
  };
@@ -3,7 +3,7 @@ function getWindow() {
3
3
  }
4
4
  export function getAtomicEnvironment(headlessVersion) {
5
5
  return {
6
- version: "3.34.0-pre.15af8fb61b",
6
+ version: "3.34.0-pre.1ad38ff1e4",
7
7
  headlessVersion,
8
8
  };
9
9
  }
@@ -1 +1 @@
1
- {"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;;;;;;;;SAYgB,cAAc,CAAoB,OAAgB;IAChE,OAAO,WAAW,CAAI,OAAO,EAAE,gBAAgB,CAAC,CAAC;AACnD;;MCHa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,WAAmB,EAAE,UAAkB;QACjD,KAAK,CACH,QAAQ,WAAW,sCAAsC,UAAU,YAAY,CAChF,CAAC;KACH;;;ACfH,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;SAIpC,gBAAgB,CAAI,OAAgB,EAAE,UAAkB;IACtE,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM;QACpC,MAAM,KAAK,GAAG,gBAAgB,CAC5B,oBAAoB,EACpB,CAAC,IAAO;YACN,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;SACtB,CACF,CAAC;QACF,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAE7B,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE;YACjC,MAAM,CACJ,IAAI,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,UAAU,CAAC,CACnE,CAAC;SACH;KACF,CAAC,CAAC;AACL;;ACoDA;;;;;;;;;;SAUgB,mBAAmB,CAAoB,OAAgB;IACrE,OAAO,gBAAgB,CAAI,OAAO,EAAE,gBAAgB,CAAC,CAAC;AACxD;;;;","names":[],"sources":["src/components/commerce/product-template-component-utils/stencil-product-template-decorators.tsx","src/components/common/item-list/context/item-context-controller.ts","src/components/common/item-list/fetch-item-context.ts","src/decorators/commerce/product-template-decorators.ts"],"sourcesContent":["import {Product} from '@coveo/headless/commerce';\nimport {itemContext} from '../../common/item-list/stencil-item-decorators';\n\n/**\n * Retrieves `Product` on a rendered `atomic-product`.\n *\n * This method is useful for building custom product template elements, see [Create a Product List](https://docs.coveo.com/en/atomic/latest/cc-search/create-custom-components/native-components/#custom-product-template-component-example) for more information.\n *\n * You should use the method in the [connectedCallback lifecycle method](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#using_the_lifecycle_callbacks).\n *\n * @param element - The element that the event is dispatched to, which must be the child of a rendered \"atomic-product\".\n * @returns A promise that resolves on initialization of the parent \"atomic-product\" element, or rejects when there is no parent \"atomic-product\" element.\n *\n * @deprecated should only be used for Stencil components. For Lit components, use `fetchProductContext` from \\@/src/decorators/commerce/product-template-decorators.ts\n */\nexport function productContext<T extends Product>(element: Element) {\n return itemContext<T>(element, 'atomic-product');\n}\n","import type {LitElement, ReactiveController, ReactiveControllerHost} from 'lit';\nimport type {InitializableComponent} from '@/src/decorators/types.js';\nimport {buildCustomEvent} from '@/src/utils/event-utils';\n\ntype LitElementWithError = Omit<\n Pick<InitializableComponent, 'error'>,\n 'error'\n> &\n LitElement & {\n error: Error | null;\n };\n\nconst itemContextEventName = 'atomic/resolveResult';\n\nexport class MissingParentError extends Error {\n constructor(elementName: string, parentName: string) {\n super(\n `The \"${elementName}\" element must be the child of an \"${parentName}\" element.`\n );\n }\n}\n\nfunction extractFolded<T = Record<string, unknown>>(\n item: Record<string, unknown>,\n returnFolded: boolean\n): T {\n if (returnFolded) {\n if ('children' in item) {\n return item as T;\n } else {\n return {children: [], result: item} as T;\n }\n }\n\n if ('children' in item && 'result' in item) {\n return item.result as T;\n }\n return item as T;\n}\n\n/**\n * A reactive controller that manages item context data from parent components.\n * Handles fetching item data via custom events and manages error states.\n */\nexport class ItemContextController<T = Record<string, unknown>>\n implements ReactiveController\n{\n private host: ReactiveControllerHost & LitElementWithError;\n private parentName: string;\n private folded: boolean;\n private _item: T | null = null;\n private _error: MissingParentError | null = null;\n\n constructor(\n host: ReactiveControllerHost & LitElementWithError,\n options: {parentName?: string; folded?: boolean} = {}\n ) {\n this.host = host;\n this.parentName = options.parentName ?? 'atomic-result';\n this.folded = options.folded ?? false;\n host.addController(this);\n }\n\n get item(): T | null {\n return this._error ? null : this._item;\n }\n\n get error(): MissingParentError | null {\n return this._error;\n }\n\n get hasError(): boolean {\n return this._error !== null;\n }\n\n hostConnected(): void {\n this._resolveItemContext();\n }\n\n private _resolveItemContext(): void {\n const event = buildCustomEvent(\n itemContextEventName,\n (item: Record<string, unknown>) => {\n this._item = extractFolded<T>(item, this.folded);\n this._error = null;\n this.host.error = null;\n this.host.requestUpdate();\n }\n );\n\n const canceled = this.host.dispatchEvent(event);\n if (canceled) {\n const elementName = (this.host as Element).nodeName.toLowerCase();\n this._error = new MissingParentError(elementName, this.parentName);\n this._item = null;\n this.host.error = this._error;\n this.host.requestUpdate();\n }\n }\n}\n\ntype ItemContextEventHandler<T> = (item: T) => void;\nexport type ItemContextEvent<T> = CustomEvent<ItemContextEventHandler<T>>;\n","import {closest} from '../../../utils/dom-utils.js';\nimport {buildCustomEvent} from '../../../utils/event-utils.js';\nimport {MissingParentError} from './context/item-context-controller.js';\n\nconst itemContextEventName = 'atomic/resolveResult';\n\ntype ItemContextEventHandler<T> = (item: T) => void;\n\nexport function fetchItemContext<T>(element: Element, parentName: string) {\n return new Promise<T>((resolve, reject) => {\n const event = buildCustomEvent<ItemContextEventHandler<T>>(\n itemContextEventName,\n (item: T) => {\n return resolve(item);\n }\n );\n element.dispatchEvent(event);\n\n if (!closest(element, parentName)) {\n reject(\n new MissingParentError(element.nodeName.toLowerCase(), parentName)\n );\n }\n });\n}\n","import type {InteractiveProduct, Product} from '@coveo/headless/commerce';\nimport type {LitElement} from 'lit';\nimport {\n InteractiveItemContextController,\n type InteractiveItemContextEvent,\n} from '@/src/components/common/item-list/context/interactive-item-context-controller';\nimport {\n ItemContextController,\n type ItemContextEvent,\n} from '@/src/components/common/item-list/context/item-context-controller';\nimport {fetchItemContext} from '@/src/components/common/item-list/fetch-item-context';\n\n/**\n * Creates a [Lit reactive controller](https://lit.dev/docs/composition/controllers/) for managing product context in product template components.\n *\n * @param host - The Lit component instance\n * @param options - Configuration options\n * @returns ItemContextController instance configured for atomic-product\n *\n * @example\n * ```typescript\n * @customElement('my-product-component')\n * export class MyProductComponent extends LitElement {\n * private productController = createProductContextController(this);\n *\n * @state() product!: Product;\n *\n * render() {\n * this.product = this.productController.item;\n * return html`<div>${this.product?.ec_name}</div>`;\n * }\n * }\n * ```\n */\nexport function createProductContextController(\n host: LitElement & {error: Error | null},\n options: {folded?: boolean} = {}\n): ItemContextController<Product> {\n return new ItemContextController<Product>(host, {\n parentName: 'atomic-product',\n folded: options.folded ?? false,\n });\n}\n\n/**\n * Creates a [Lit reactive controller](https://lit.dev/docs/composition/controllers/) for managing interactive product context in product template components.\n *\n * @param host - The Lit component instance\n * @returns InteractiveItemContextController instance\n *\n * @example\n * ```typescript\n * @customElement('my-interactive-product-component')\n * export class MyInteractiveProductComponent extends LitElement {\n * private interactiveProductController = createInteractiveProductContextController(this);\n *\n * @state() product!: Product;\n *\n * render() {\n * this.product = this.interactiveProductController.interactiveItem;\n * return html`<div>${this.product?.ec_name}</div>`;\n * }\n * }\n * ```\n */\nexport function createInteractiveProductContextController(\n host: LitElement & {error: Error}\n): InteractiveItemContextController<InteractiveProduct> {\n return new InteractiveItemContextController<InteractiveProduct>(host);\n}\n\nexport type ProductContextEvent<T = Product> = ItemContextEvent<T>;\nexport type InteractiveProductContextEvent<\n T extends InteractiveProduct = InteractiveProduct,\n> = InteractiveItemContextEvent<T>;\n\n/**\n * Retrieves `Product` on a rendered `atomic-product`.\n *\n * This utility function is useful for building custom product template elements, see [Create a Product List](https://docs.coveo.com/en/atomic/latest/cc-search/create-custom-components/native-components/#custom-product-template-component-example) for more information.\n *\n * You should use the utility function in the [`connectedCallback` lifecycle method](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#using_the_lifecycle_callbacks).\n *\n * @param element - The element that the event is dispatched to, which must be the child of a rendered `atomic-product`.\n * @returns A promise that resolves on initialization of the parent `atomic-product` element, or rejects when there is no parent `atomic-product` element.\n */\nexport function fetchProductContext<T extends Product>(element: Element) {\n return fetchItemContext<T>(element, 'atomic-product');\n}\n"],"version":3}
1
+ {"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;;;;;;;;SAYgB,cAAc,CAAoB,OAAgB;IAChE,OAAO,WAAW,CAAI,OAAO,EAAE,gBAAgB,CAAC,CAAC;AACnD;;MCHa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,WAAmB,EAAE,UAAkB;QACjD,KAAK,CACH,QAAQ,WAAW,sCAAsC,UAAU,YAAY,CAChF,CAAC;KACH;;;ACfH,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;SAIpC,gBAAgB,CAAI,OAAgB,EAAE,UAAkB;IACtE,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM;QACpC,MAAM,KAAK,GAAG,gBAAgB,CAC5B,oBAAoB,EACpB,CAAC,IAAO;YACN,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;SACtB,CACF,CAAC;QACF,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAE7B,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE;YACjC,MAAM,CACJ,IAAI,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,UAAU,CAAC,CACnE,CAAC;SACH;KACF,CAAC,CAAC;AACL;;ACoDA;;;;;;;;;;SAUgB,mBAAmB,CAAoB,OAAgB;IACrE,OAAO,gBAAgB,CAAI,OAAO,EAAE,gBAAgB,CAAC,CAAC;AACxD;;;;","names":[],"sources":["src/components/commerce/product-template-component-utils/stencil-product-template-decorators.tsx","src/components/common/item-list/context/item-context-controller.ts","src/components/common/item-list/fetch-item-context.ts","src/decorators/commerce/product-template-decorators.ts"],"sourcesContent":["import {Product} from '@coveo/headless/commerce';\nimport {itemContext} from '../../common/item-list/stencil-item-decorators';\n\n/**\n * Retrieves `Product` on a rendered `atomic-product`.\n *\n * This method is useful for building custom product template elements, see [Create a Product List](https://docs.coveo.com/en/atomic/latest/cc-search/create-custom-components/native-components/#custom-product-template-component-example) for more information.\n *\n * You should use the method in the [connectedCallback lifecycle method](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#using_the_lifecycle_callbacks).\n *\n * @param element - The element that the event is dispatched to, which must be the child of a rendered \"atomic-product\".\n * @returns A promise that resolves on initialization of the parent \"atomic-product\" element, or rejects when there is no parent \"atomic-product\" element.\n *\n * @deprecated should only be used for Stencil components. For Lit components, use `fetchProductContext` from \\@/src/decorators/commerce/product-template-decorators.ts\n */\nexport function productContext<T extends Product>(element: Element) {\n return itemContext<T>(element, 'atomic-product');\n}\n","import type {LitElement, ReactiveController, ReactiveControllerHost} from 'lit';\nimport type {InitializableComponent} from '@/src/decorators/types.js';\nimport {buildCustomEvent} from '@/src/utils/event-utils';\n\ntype LitElementWithError = Omit<\n Pick<InitializableComponent, 'error'>,\n 'error'\n> &\n LitElement & {\n error: Error | null;\n };\n\nconst itemContextEventName = 'atomic/resolveResult';\n\nexport class MissingParentError extends Error {\n constructor(elementName: string, parentName: string) {\n super(\n `The \"${elementName}\" element must be the child of an \"${parentName}\" element.`\n );\n }\n}\n\nfunction extractFolded<T = Record<string, unknown>>(\n item: Record<string, unknown>,\n returnFolded: boolean\n): T {\n if (returnFolded) {\n if ('children' in item) {\n return item as T;\n } else {\n return {children: [], result: item} as T;\n }\n }\n\n if ('children' in item && 'result' in item) {\n return item.result as T;\n }\n return item as T;\n}\n\n/**\n * A reactive controller that manages item context data from parent components.\n * Handles fetching item data via custom events and manages error states.\n */\nexport class ItemContextController<T = Record<string, unknown>>\n implements ReactiveController\n{\n private host: ReactiveControllerHost & LitElementWithError;\n private parentName: string;\n private folded: boolean;\n private _item: T | null = null;\n private _error: MissingParentError | null = null;\n\n constructor(\n host: ReactiveControllerHost & LitElementWithError,\n options: {parentName?: string; folded?: boolean} = {}\n ) {\n this.host = host;\n this.parentName = options.parentName ?? 'atomic-result';\n this.folded = options.folded ?? false;\n host.addController(this);\n }\n\n get item(): T | null {\n return this._error ? null : this._item;\n }\n\n get error(): MissingParentError | null {\n return this._error;\n }\n\n get hasError(): boolean {\n return this._error !== null;\n }\n\n hostConnected(): void {\n this._resolveItemContext();\n }\n\n private _resolveItemContext(): void {\n const event = buildCustomEvent(\n itemContextEventName,\n (item: Record<string, unknown>) => {\n this._item = extractFolded<T>(item, this.folded);\n this._error = null;\n this.host.error = null;\n this.host.requestUpdate();\n }\n );\n\n const canceled = this.host.dispatchEvent(event);\n if (canceled) {\n const elementName = (this.host as Element).nodeName.toLowerCase();\n this._error = new MissingParentError(elementName, this.parentName);\n this._item = null;\n this.host.error = this._error;\n this.host.requestUpdate();\n }\n }\n}\n\ntype ItemContextEventHandler<T> = (item: T) => void;\nexport type ItemContextEvent<T> = CustomEvent<ItemContextEventHandler<T>>;\n","import {closest} from '../../../utils/dom-utils.js';\nimport {buildCustomEvent} from '../../../utils/event-utils.js';\nimport {MissingParentError} from './context/item-context-controller.js';\n\nconst itemContextEventName = 'atomic/resolveResult';\n\ntype ItemContextEventHandler<T> = (item: T) => void;\n\nexport function fetchItemContext<T>(element: Element, parentName: string) {\n return new Promise<T>((resolve, reject) => {\n const event = buildCustomEvent<ItemContextEventHandler<T>>(\n itemContextEventName,\n (item: T) => {\n return resolve(item);\n }\n );\n element.dispatchEvent(event);\n\n if (!closest(element, parentName)) {\n reject(\n new MissingParentError(element.nodeName.toLowerCase(), parentName)\n );\n }\n });\n}\n","import type {InteractiveProduct, Product} from '@coveo/headless/commerce';\nimport type {LitElement} from 'lit';\nimport {\n InteractiveItemContextController,\n type InteractiveItemContextEvent,\n} from '@/src/components/common/item-list/context/interactive-item-context-controller';\nimport {\n ItemContextController,\n type ItemContextEvent,\n} from '@/src/components/common/item-list/context/item-context-controller';\nimport {fetchItemContext} from '@/src/components/common/item-list/fetch-item-context';\n\n/**\n * Creates a [Lit reactive controller](https://lit.dev/docs/composition/controllers/) for managing product context in product template components.\n *\n * @param host - The Lit component instance\n * @param options - Configuration options\n * @returns ItemContextController instance configured for atomic-product\n *\n * @example\n * ```typescript\n * @customElement('my-product-component')\n * export class MyProductComponent extends LitElement {\n * private productController = createProductContextController(this);\n *\n * @state() product!: Product;\n *\n * render() {\n * this.product = this.productController.item;\n * return html`<div>${this.product?.ec_name}</div>`;\n * }\n * }\n * ```\n */\nexport function createProductContextController(\n host: LitElement & {error: Error | null},\n options: {folded?: boolean} = {}\n): ItemContextController<Product> {\n return new ItemContextController<Product>(host, {\n parentName: 'atomic-product',\n folded: options.folded ?? false,\n });\n}\n\n/**\n * Creates a [Lit reactive controller](https://lit.dev/docs/composition/controllers/) for managing interactive product context in product template components.\n *\n * @param host - The Lit component instance\n * @returns InteractiveItemContextController instance\n *\n * @example\n * ```typescript\n * @customElement('my-interactive-product-component')\n * export class MyInteractiveProductComponent extends LitElement {\n * private interactiveProductController = createInteractiveProductContextController(this);\n *\n * @state() product!: Product;\n *\n * render() {\n * this.product = this.interactiveProductController.interactiveItem;\n * return html`<div>${this.product?.ec_name}</div>`;\n * }\n * }\n * ```\n */\nexport function createInteractiveProductContextController(\n host: LitElement & {error: Error}\n): InteractiveItemContextController<InteractiveProduct> {\n return new InteractiveItemContextController<InteractiveProduct>(host);\n}\n\nexport type ProductContextEvent<T = Product> = ItemContextEvent<T>;\nexport type InteractiveProductContextEvent<\n T extends InteractiveProduct = InteractiveProduct,\n> = InteractiveItemContextEvent<T>;\n\n/**\n * Retrieves `Product` on a rendered `atomic-product`.\n *\n * This utility function is useful for building custom product template elements, see [Create a Product List](https://docs.coveo.com/en/atomic/latest/cc-search/create-custom-components/native-components/#custom-product-template-component-example) for more information.\n *\n * You should use the utility function in the [`connectedCallback` lifecycle method](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#using_the_lifecycle_callbacks).\n *\n * @param element - The element that the event is dispatched to, which must be the child of a rendered `atomic-product`.\n * @returns A promise that resolves on initialization of the parent `atomic-product` element, or rejects when there is no parent `atomic-product` element.\n */\nexport function fetchProductContext<T extends Product>(element: Element) {\n return fetchItemContext<T>(element, 'atomic-product');\n}\n"],"version":3}