@coveo/atomic 3.34.0-pre.64accaaf5d → 3.34.0-pre.657371a547
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.
- package/dist/atomic/_atomic.esm.js +1 -1
- package/dist/atomic/components/analytics-config.js +1 -1
- package/dist/atomic/components/atomic-category-facet.js +7 -17
- package/dist/atomic/components/atomic-category-facet.js.map +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-category-facet/atomic-commerce-category-facet.js +0 -3
- package/dist/atomic/components/components/commerce/atomic-product/atomic-product.js +26 -58
- package/dist/atomic/components/components/common/facets/category-facet/all-categories-button.js +2 -3
- package/dist/atomic/components/components/common/facets/category-facet/search-value.js +1 -6
- package/dist/atomic/components/components/common/layout/custom-render-controller.js +37 -0
- package/dist/atomic/components/components/common/layout/item-layout-controller.js +103 -0
- package/dist/atomic/components/global/environment.js +1 -1
- package/dist/atomic/{p-6e0a147c.js → p-0fd03343.js} +2 -2
- package/dist/atomic/{p-a5da1add.entry.js → p-14d42bfd.entry.js} +2 -2
- package/dist/atomic/{p-bdbab2bb.entry.js → p-613e1145.entry.js} +2 -2
- package/dist/atomic/{p-4e2f8a73.entry.js → p-b6ae0244.entry.js} +2 -2
- package/dist/atomic/p-b6ae0244.entry.js.map +1 -0
- package/dist/cjs/{analytics-config-72cc04ac.js → analytics-config-031509bc.js} +2 -2
- package/dist/cjs/{analytics-config-72cc04ac.js.map → analytics-config-031509bc.js.map} +1 -1
- package/dist/cjs/atomic-category-facet.cjs.entry.js +7 -17
- package/dist/cjs/atomic-category-facet.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-insight-interface.cjs.entry.js +1 -1
- package/dist/cjs/atomic-recs-interface.cjs.entry.js +1 -1
- package/dist/cjs/version.cjs.js +2 -2
- package/dist/esm/{analytics-config-a7235d19.js → analytics-config-cccaa8c4.js} +2 -2
- package/dist/esm/{analytics-config-a7235d19.js.map → analytics-config-cccaa8c4.js.map} +1 -1
- package/dist/esm/atomic-category-facet.entry.js +7 -17
- package/dist/esm/atomic-category-facet.entry.js.map +1 -1
- package/dist/esm/atomic-insight-interface.entry.js +1 -1
- package/dist/esm/atomic-recs-interface.entry.js +1 -1
- package/dist/esm/version.js +2 -2
- package/dist/types/components/commerce/atomic-product/atomic-product.d.ts +4 -16
- package/dist/types/components/common/facets/category-facet/all-categories-button.d.ts +0 -2
- package/dist/types/components/common/facets/category-facet/search-value.d.ts +0 -1
- package/dist/types/components/common/facets/category-facet/stencil-all-categories-button.d.ts +0 -2
- package/dist/types/components/common/facets/category-facet/stencil-search-value.d.ts +0 -1
- package/dist/types/components/common/layout/custom-render-controller.d.ts +25 -0
- package/dist/types/components/common/layout/item-layout-controller.d.ts +47 -0
- package/docs/atomic-docs.json +1 -1
- package/package.json +7 -7
- package/dist/atomic/components/components/common/facets/category-facet/all-categories-localized-label.js +0 -9
- package/dist/atomic/p-4e2f8a73.entry.js.map +0 -1
- package/dist/types/components/common/facets/category-facet/all-categories-localized-label.d.ts +0 -6
- /package/dist/atomic/{p-6e0a147c.js.map → p-0fd03343.js.map} +0 -0
- /package/dist/atomic/{p-a5da1add.entry.js.map → p-14d42bfd.entry.js.map} +0 -0
- /package/dist/atomic/{p-bdbab2bb.entry.js.map → p-613e1145.entry.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 {
|
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
|
*
|
@@ -84,11 +84,26 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
|
|
84
84
|
}
|
85
85
|
async connectedCallback() {
|
86
86
|
super.connectedCallback();
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
87
|
+
new CustomRenderController(this, {
|
88
|
+
renderingFunction: () => this.renderingFunction,
|
89
|
+
itemData: () => this.product,
|
90
|
+
rootElementRef: () => this.productRootRef,
|
91
|
+
linkContainerRef: () => this.linkContainerRef,
|
92
|
+
onRenderComplete: (element, output) => {
|
93
|
+
this.itemLayoutController.applyLayoutClassesToElement(element, output);
|
94
|
+
},
|
95
|
+
});
|
96
|
+
this.itemLayoutController = new ItemLayoutController(this, {
|
97
|
+
elementPrefix: 'atomic-product',
|
98
|
+
renderingFunction: () => this.renderingFunction,
|
99
|
+
content: () => this.content,
|
100
|
+
layoutConfig: () => ({
|
101
|
+
display: this.display,
|
102
|
+
density: this.density,
|
103
|
+
imageSize: this.imageSize,
|
104
|
+
}),
|
105
|
+
itemClasses: () => this.classes,
|
106
|
+
});
|
92
107
|
this.addEventListener('atomic/resolveResult', this.resolveProduct);
|
93
108
|
this.addEventListener('atomic/resolveInteractiveResult', this.resolveInteractiveProduct);
|
94
109
|
this.addEventListener('atomic/resolveStopPropagation', this.resolveStopPropagation);
|
@@ -105,12 +120,9 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
|
|
105
120
|
this.removeEventListener('atomic/resolveResultDisplayConfig', this.resolveProductDisplayConfig);
|
106
121
|
this.removeEventListener('click', this.handleClick);
|
107
122
|
}
|
108
|
-
get isCustomRenderFunctionMode() {
|
109
|
-
return this.renderingFunction !== undefined;
|
110
|
-
}
|
111
123
|
getContentHTML() {
|
112
124
|
if (!this.content) {
|
113
|
-
console.warn('
|
125
|
+
console.warn('atomic-product: content property is undefined. Cannot get content HTML.', this);
|
114
126
|
return '';
|
115
127
|
}
|
116
128
|
return parentNodeToString(this.content);
|
@@ -118,13 +130,8 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
|
|
118
130
|
getLinkHTML() {
|
119
131
|
return parentNodeToString(this.linkContent ?? new HTMLElement());
|
120
132
|
}
|
121
|
-
shouldExecuteRenderFunction() {
|
122
|
-
return (this.isCustomRenderFunctionMode &&
|
123
|
-
this.productRootRef &&
|
124
|
-
!this.executedRenderingFunctionOnce);
|
125
|
-
}
|
126
133
|
render() {
|
127
|
-
if (this.
|
134
|
+
if (this.renderingFunction !== undefined) {
|
128
135
|
return html `
|
129
136
|
<div class=${resultComponentClass}>
|
130
137
|
<div
|
@@ -143,16 +150,13 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
|
|
143
150
|
`;
|
144
151
|
}
|
145
152
|
// Handle case where content is undefined and layout was not created
|
146
|
-
if (!this.
|
153
|
+
if (!this.itemLayoutController.getLayout()) {
|
147
154
|
return html `<div class=${resultComponentClass}></div>`;
|
148
155
|
}
|
149
156
|
return html `
|
150
157
|
<div class=${resultComponentClass}>
|
151
158
|
<div
|
152
|
-
class="result-root ${this.
|
153
|
-
.getClasses()
|
154
|
-
.concat(this.classes)
|
155
|
-
.join(' ')}"
|
159
|
+
class="result-root ${this.itemLayoutController.getCombinedClasses().join(' ')}"
|
156
160
|
.innerHTML=${this.getContentHTML()}
|
157
161
|
></div>
|
158
162
|
<div class="link-container" .innerHTML=${this.getLinkHTML()}></div>
|
@@ -164,42 +168,6 @@ let AtomicProduct = class AtomicProduct extends ChildrenUpdateCompleteMixin(LitE
|
|
164
168
|
this.store.unsetLoadingFlag(this.loadingFlag);
|
165
169
|
}
|
166
170
|
}
|
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
|
-
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
|
-
}
|
202
|
-
}
|
203
171
|
};
|
204
172
|
AtomicProduct.styles = styles;
|
205
173
|
__decorate([
|
package/dist/atomic/components/components/common/facets/category-facet/all-categories-button.js
CHANGED
@@ -2,9 +2,8 @@ import "../../atomic-icon/atomic-icon";
|
|
2
2
|
import { html } from 'lit';
|
3
3
|
import { renderButton } from "../../button";
|
4
4
|
const LeftArrow = "<svg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"m11.5 4.8-4.3 4.5c-.3.4-.3.9 0 1.3l4.3 4.6c.3.4.9.4 1.2 0s.3-.9 0-1.3l-3.7-4 3.7-3.9c.3-.4.3-.9 0-1.3-.3-.3-.9-.3-1.2.1z\"/></svg>";
|
5
|
-
|
6
|
-
|
7
|
-
const allCategories = getAllCategoriesLocalizedLabel({ facetId, field, i18n });
|
5
|
+
export const renderCategoryFacetAllCategoryButton = ({ props: { i18n, onClick } }) => {
|
6
|
+
const allCategories = i18n.t('all-categories');
|
8
7
|
return html `
|
9
8
|
${renderButton({
|
10
9
|
props: {
|
@@ -4,17 +4,12 @@ import { renderButton } from "../../button";
|
|
4
4
|
import { renderFacetValueLabelHighlight } from "../facet-value-label-highlight/facet-value-label-highlight";
|
5
5
|
import { hierarchicalPath } from "../../../../directives/hierarchical-path";
|
6
6
|
import { getFieldValueCaption } from "../../../../utils/field-utils";
|
7
|
-
import { getAllCategoriesLocalizedLabel } from './all-categories-localized-label';
|
8
7
|
const SEPARATOR = '/';
|
9
8
|
const PATH_MAX_LENGTH = 3;
|
10
9
|
export const renderCategoryFacetSearchValue = ({ props }) => {
|
11
10
|
const count = props.value.count.toLocaleString(props.i18n.language);
|
12
11
|
const inLabel = props.i18n.t('in');
|
13
|
-
const allCategories =
|
14
|
-
facetId: props.facetId,
|
15
|
-
field: props.field,
|
16
|
-
i18n: props.i18n,
|
17
|
-
});
|
12
|
+
const allCategories = props.i18n.t('all-categories');
|
18
13
|
const localizedPath = props.value.path.length
|
19
14
|
? props.value.path.map((value) => getFieldValueCaption(props.field, value, props.i18n))
|
20
15
|
: [allCategories];
|
@@ -0,0 +1,37 @@
|
|
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
|
+
this.executeRenderFunction();
|
19
|
+
}
|
20
|
+
resetRenderState() {
|
21
|
+
this.hasExecutedRenderFunction = false;
|
22
|
+
}
|
23
|
+
executeRenderFunction() {
|
24
|
+
const renderingFunction = this.options.renderingFunction();
|
25
|
+
const itemData = this.options.itemData();
|
26
|
+
const rootElementRef = this.options.rootElementRef();
|
27
|
+
if (!renderingFunction ||
|
28
|
+
!itemData ||
|
29
|
+
!rootElementRef ||
|
30
|
+
this.hasExecutedRenderFunction) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
const customRenderOutput = renderingFunction(itemData, rootElementRef, this.options.linkContainerRef());
|
34
|
+
this.options.onRenderComplete(rootElementRef, customRenderOutput);
|
35
|
+
this.hasExecutedRenderFunction = true;
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,103 @@
|
|
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
|
+
...options,
|
11
|
+
};
|
12
|
+
host.addController(this);
|
13
|
+
}
|
14
|
+
hostConnected() {
|
15
|
+
this.createLayout();
|
16
|
+
}
|
17
|
+
hostUpdated() {
|
18
|
+
this.applyLayoutClasses();
|
19
|
+
}
|
20
|
+
/**
|
21
|
+
* Gets the current layout instance
|
22
|
+
*/
|
23
|
+
getLayout() {
|
24
|
+
return this.layoutInstance;
|
25
|
+
}
|
26
|
+
/**
|
27
|
+
* Gets combined layout and extra classes
|
28
|
+
*/
|
29
|
+
getCombinedClasses(additionalContent) {
|
30
|
+
const layout = this.getLayout();
|
31
|
+
const layoutClasses = layout ? layout.getClasses(additionalContent) : [];
|
32
|
+
const itemClasses = this.options
|
33
|
+
.itemClasses()
|
34
|
+
.split(/\s+/)
|
35
|
+
.filter((c) => c);
|
36
|
+
return [...layoutClasses, ...itemClasses];
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* Applies layout classes to a specific element (useful for custom rendering)
|
40
|
+
*/
|
41
|
+
applyLayoutClassesToElement(element, additionalContent) {
|
42
|
+
const layout = this.getLayout();
|
43
|
+
if (!layout) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
const classes = this.getCombinedClasses(additionalContent);
|
47
|
+
if (classes.length > 0) {
|
48
|
+
element.classList.add(...classes);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
applyLayoutClasses() {
|
52
|
+
const layout = this.getLayout();
|
53
|
+
if (!layout) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
const classes = this.getCombinedClasses();
|
57
|
+
const root = this.host.shadowRoot?.querySelector('.result-root');
|
58
|
+
if (!root || classes.length === 0) {
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
if (this.hasCustomRenderFunction()) {
|
62
|
+
this.observeAndApplyClasses(root, classes);
|
63
|
+
}
|
64
|
+
else {
|
65
|
+
this.addClassesToElements(root, classes);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
createLayout() {
|
69
|
+
const content = this.options.content();
|
70
|
+
if (!content) {
|
71
|
+
console.warn(`${this.options.elementPrefix}: content property is undefined. Cannot create layout.`, this.host);
|
72
|
+
this.layoutInstance = null;
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
const config = this.options.layoutConfig();
|
76
|
+
this.layoutInstance = new ItemLayout(content.children, config.display, config.density, config.imageSize);
|
77
|
+
}
|
78
|
+
hasCustomRenderFunction() {
|
79
|
+
return this.options.renderingFunction() !== undefined;
|
80
|
+
}
|
81
|
+
addClassesToElements(root, classes) {
|
82
|
+
if (classes.length === 0) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
const elements = root.querySelectorAll('*');
|
86
|
+
elements.forEach((element) => {
|
87
|
+
const tagName = element.tagName.toLowerCase();
|
88
|
+
if (tagName.startsWith(`${this.options.elementPrefix}-`)) {
|
89
|
+
element.classList.add(...classes);
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
observeAndApplyClasses(root, classes) {
|
94
|
+
const observer = new MutationObserver((mutations) => {
|
95
|
+
const hasNewElements = mutations.some((mutation) => mutation.type === 'childList' && mutation.addedNodes.length > 0);
|
96
|
+
if (hasNewElements) {
|
97
|
+
this.addClassesToElements(root, classes);
|
98
|
+
observer.disconnect();
|
99
|
+
}
|
100
|
+
});
|
101
|
+
observer.observe(root, { childList: true, subtree: true });
|
102
|
+
}
|
103
|
+
}
|