@coveo/atomic 3.28.0-pre.df6c8a3eb3 → 3.28.0-pre.e87aa33543
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/atomic.esm.js.map +1 -1
- package/dist/atomic/components/_index.d.ts +0 -6
- package/dist/atomic/components/_index.js +0 -3
- package/dist/atomic/components/atomic-product-children.js +1 -7
- package/dist/atomic/components/atomic-product-children.js.map +1 -1
- package/dist/atomic/components/atomic-product-description.js +1 -13
- package/dist/atomic/components/atomic-product-description.js.map +1 -1
- package/dist/atomic/components/atomic-product-excerpt.js +1 -13
- package/dist/atomic/components/atomic-product-excerpt.js.map +1 -1
- package/dist/atomic/components/atomic-product-link.js +1 -13
- package/dist/atomic/components/atomic-product-link.js.map +1 -1
- package/dist/atomic/components/atomic-result-text2.js +45 -2
- package/dist/atomic/components/atomic-result-text2.js.map +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-text/atomic-commerce-text.js +54 -0
- package/dist/atomic/components/components/commerce/atomic-product-template/atomic-product-template.js +2 -0
- package/dist/atomic/components/components/commerce/atomic-product-text/atomic-product-text.js +135 -0
- package/dist/atomic/components/components/commerce/index.js +2 -0
- package/dist/atomic/components/components/commerce/lazy-index.js +2 -0
- package/dist/atomic/components/components/commerce/product-template-component-utils/error.js +6 -0
- package/dist/atomic/components/components/commerce/product-template-component-utils/product-utils.js +35 -0
- package/dist/atomic/components/components/common/atomic-layout-section/atomic-layout-section.js +31 -0
- package/dist/atomic/components/components/common/index.js +1 -0
- package/dist/atomic/components/components/common/item-text/field-warning.js +6 -0
- package/dist/atomic/components/components/common/item-text/item-text-fallback.js +15 -0
- package/dist/atomic/components/components/common/item-text/item-text-highlighted.js +17 -0
- package/dist/atomic/components/components/common/item-text/render-highlights.js +13 -0
- package/dist/atomic/components/components/common/lazy-index.js +1 -0
- package/dist/atomic/components/global/environment.js +1 -1
- package/dist/atomic/components/index.js.map +1 -1
- package/dist/atomic/components/interface-common-stencil.js +1 -1
- package/dist/atomic/components/product-utils.js +1 -8
- package/dist/atomic/components/product-utils.js.map +1 -1
- package/dist/atomic/components/sections.js.map +1 -1
- package/dist/atomic/components/utils/object-utils.js +13 -0
- package/dist/atomic/{p-c0b3720d.entry.js → p-191ac0fe.entry.js} +2 -2
- package/dist/atomic/{p-3195fa42.entry.js → p-545f7fb1.entry.js} +2 -2
- package/dist/atomic/{p-e46517e9.entry.js → p-8a3f0405.entry.js} +2 -2
- package/dist/atomic/{p-f68cee5d.entry.js → p-8f1ab6ff.entry.js} +2 -2
- package/dist/atomic/{p-5e73a3e8.js → p-8fa5129d.js} +2 -2
- package/dist/atomic/p-9c7dbbdf.js.map +1 -1
- package/dist/atomic/p-a1c4ac09.js +2 -0
- package/dist/atomic/p-a1c4ac09.js.map +1 -0
- package/dist/atomic/{p-7ed31f46.js → p-b64f4619.js} +2 -2
- package/dist/atomic/p-d76c5232.entry.js +2 -0
- package/dist/atomic/{p-22a0d1b9.entry.js → p-ea5d2736.entry.js} +2 -2
- package/dist/atomic/p-f1bbe060.entry.js +2 -0
- package/dist/atomic/p-f1bbe060.entry.js.map +1 -0
- package/dist/atomic/{p-3cc601ad.entry.js → p-f67a6ad6.entry.js} +2 -2
- package/dist/cjs/_loader.cjs.js +1 -1
- package/dist/cjs/{analytics-config-f82932e2.js → analytics-config-f331427b.js} +2 -2
- package/dist/cjs/{analytics-config-f82932e2.js.map → analytics-config-f331427b.js.map} +1 -1
- package/dist/cjs/atomic-commerce-recommendation-interface.cjs.entry.js +1 -1
- package/dist/cjs/atomic-insight-interface.cjs.entry.js +2 -2
- package/dist/cjs/atomic-product-link.cjs.entry.js +1 -1
- package/dist/cjs/atomic-product-numeric-field-value.cjs.entry.js +1 -1
- package/dist/cjs/atomic-product-price.cjs.entry.js +1 -1
- package/dist/cjs/atomic-recs-interface.cjs.entry.js +2 -2
- package/dist/cjs/atomic-result-text_2.cjs.entry.js +46 -4
- package/dist/cjs/atomic-result-text_2.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-search-interface.cjs.entry.js +2 -2
- package/dist/cjs/atomic.cjs.js +1 -1
- package/dist/cjs/index-757bc886.js +0 -8
- package/dist/cjs/{interface-common-stencil-98f073f6.js → interface-common-stencil-c2474e53.js} +2 -2
- package/dist/cjs/{interface-common-stencil-98f073f6.js.map → interface-common-stencil-c2474e53.js.map} +1 -1
- package/dist/cjs/{product-utils-9507462c.js → product-utils-f6c780e3.js} +1 -9
- package/dist/cjs/product-utils-f6c780e3.js.map +1 -0
- package/dist/cjs/sections-4b4af2f8.js.map +1 -1
- package/dist/cjs/version.cjs.js +1 -1
- package/dist/esm/_loader.js +1 -1
- package/dist/esm/{analytics-config-253004a0.js → analytics-config-6dc04e7b.js} +2 -2
- package/dist/esm/{analytics-config-253004a0.js.map → analytics-config-6dc04e7b.js.map} +1 -1
- package/dist/esm/atomic-commerce-recommendation-interface.entry.js +1 -1
- package/dist/esm/atomic-insight-interface.entry.js +2 -2
- package/dist/esm/atomic-product-link.entry.js +1 -1
- package/dist/esm/atomic-product-numeric-field-value.entry.js +1 -1
- package/dist/esm/atomic-product-price.entry.js +1 -1
- package/dist/esm/atomic-recs-interface.entry.js +2 -2
- package/dist/esm/atomic-result-text_2.entry.js +45 -3
- package/dist/esm/atomic-result-text_2.entry.js.map +1 -1
- package/dist/esm/atomic-search-interface.entry.js +2 -2
- package/dist/esm/atomic.js +1 -1
- package/dist/esm/index-3f35faca.js +0 -8
- package/dist/esm/{interface-common-stencil-4bb4d80c.js → interface-common-stencil-185b53eb.js} +2 -2
- package/dist/esm/{interface-common-stencil-4bb4d80c.js.map → interface-common-stencil-185b53eb.js.map} +1 -1
- package/dist/esm/{product-utils-8348689f.js → product-utils-85109d2e.js} +2 -9
- package/dist/esm/product-utils-85109d2e.js.map +1 -0
- package/dist/esm/sections-ae00b53a.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/components/commerce/atomic-commerce-text/atomic-commerce-text.d.ts +13 -5
- package/dist/types/components/commerce/atomic-product-template/atomic-product-template.d.ts +2 -0
- package/dist/types/components/commerce/atomic-product-text/atomic-product-text.d.ts +29 -15
- package/dist/types/components/commerce/index.d.ts +2 -0
- package/dist/types/components/common/atomic-layout-section/atomic-layout-section.d.ts +11 -2
- package/dist/types/components/common/atomic-layout-section/sections.d.ts +2 -1
- package/dist/types/components/common/index.d.ts +1 -0
- package/dist/types/components.d.ts +0 -143
- package/docs/atomic-docs.json +9 -364
- package/package.json +1 -1
- package/dist/atomic/components/atomic-commerce-text.d.ts +0 -11
- package/dist/atomic/components/atomic-commerce-text.js +0 -8
- package/dist/atomic/components/atomic-commerce-text.js.map +0 -1
- package/dist/atomic/components/atomic-commerce-text2.js +0 -60
- package/dist/atomic/components/atomic-commerce-text2.js.map +0 -1
- package/dist/atomic/components/atomic-layout-section.d.ts +0 -11
- package/dist/atomic/components/atomic-layout-section.js +0 -35
- package/dist/atomic/components/atomic-layout-section.js.map +0 -1
- package/dist/atomic/components/atomic-product-text.d.ts +0 -11
- package/dist/atomic/components/atomic-product-text.js +0 -8
- package/dist/atomic/components/atomic-product-text.js.map +0 -1
- package/dist/atomic/components/atomic-product-text2.js +0 -83
- package/dist/atomic/components/atomic-product-text2.js.map +0 -1
- package/dist/atomic/components/stencil-item-text-highlighted.js +0 -49
- package/dist/atomic/components/stencil-item-text-highlighted.js.map +0 -1
- package/dist/atomic/p-39223a2a.entry.js +0 -2
- package/dist/atomic/p-39223a2a.entry.js.map +0 -1
- package/dist/atomic/p-5cf5bb98.entry.js +0 -2
- package/dist/atomic/p-67ef14ac.entry.js +0 -2
- package/dist/atomic/p-67ef14ac.entry.js.map +0 -1
- package/dist/atomic/p-733252f1.entry.js +0 -2
- package/dist/atomic/p-733252f1.entry.js.map +0 -1
- package/dist/atomic/p-b1a7d837.js +0 -2
- package/dist/atomic/p-b1a7d837.js.map +0 -1
- package/dist/atomic/p-bb081d4e.js +0 -2
- package/dist/atomic/p-bb081d4e.js.map +0 -1
- package/dist/cjs/atomic-commerce-text_2.cjs.entry.js +0 -106
- package/dist/cjs/atomic-commerce-text_2.cjs.entry.js.map +0 -1
- package/dist/cjs/atomic-layout-section.cjs.entry.js +0 -18
- package/dist/cjs/atomic-layout-section.cjs.entry.js.map +0 -1
- package/dist/cjs/product-utils-9507462c.js.map +0 -1
- package/dist/cjs/stencil-item-text-highlighted-91fd0fe8.js +0 -52
- package/dist/cjs/stencil-item-text-highlighted-91fd0fe8.js.map +0 -1
- package/dist/esm/atomic-commerce-text_2.entry.js +0 -101
- package/dist/esm/atomic-commerce-text_2.entry.js.map +0 -1
- package/dist/esm/atomic-layout-section.entry.js +0 -14
- package/dist/esm/atomic-layout-section.entry.js.map +0 -1
- package/dist/esm/product-utils-8348689f.js.map +0 -1
- package/dist/esm/stencil-item-text-highlighted-0e1c6c08.js +0 -49
- package/dist/esm/stencil-item-text-highlighted-0e1c6c08.js.map +0 -1
- /package/dist/atomic/{p-c0b3720d.entry.js.map → p-191ac0fe.entry.js.map} +0 -0
- /package/dist/atomic/{p-3195fa42.entry.js.map → p-545f7fb1.entry.js.map} +0 -0
- /package/dist/atomic/{p-e46517e9.entry.js.map → p-8a3f0405.entry.js.map} +0 -0
- /package/dist/atomic/{p-f68cee5d.entry.js.map → p-8f1ab6ff.entry.js.map} +0 -0
- /package/dist/atomic/{p-5e73a3e8.js.map → p-8fa5129d.js.map} +0 -0
- /package/dist/atomic/{p-7ed31f46.js.map → p-b64f4619.js.map} +0 -0
- /package/dist/atomic/{p-5cf5bb98.entry.js.map → p-d76c5232.entry.js.map} +0 -0
- /package/dist/atomic/{p-22a0d1b9.entry.js.map → p-ea5d2736.entry.js.map} +0 -0
- /package/dist/atomic/{p-3cc601ad.entry.js.map → p-f67a6ad6.entry.js.map} +0 -0
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
|
|
2
|
-
import { ProductTemplatesHelpers, HighlightUtils } from '@coveo/headless/commerce';
|
|
3
|
-
import { g as getFieldValueCaption } from './field-utils.js';
|
|
4
|
-
import { I as InitializeBindings } from './initialization-utils.js';
|
|
5
|
-
import { I as ItemTextFallback, a as ItemTextHighlighted } from './stencil-item-text-highlighted.js';
|
|
6
|
-
import { g as getStringValueFromProductOrNull } from './product-utils.js';
|
|
7
|
-
import { P as ProductContext } from './stencil-product-template-decorators.js';
|
|
8
|
-
import { d as defineCustomElement$1 } from './atomic-commerce-text2.js';
|
|
9
|
-
|
|
10
|
-
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
11
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
13
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
14
|
-
else
|
|
15
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
16
|
-
if (d = decorators[i])
|
|
17
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
};
|
|
20
|
-
const AtomicProductText = /*@__PURE__*/ proxyCustomElement(class AtomicProductText extends HTMLElement {
|
|
21
|
-
constructor() {
|
|
22
|
-
super();
|
|
23
|
-
this.__registerHost();
|
|
24
|
-
/**
|
|
25
|
-
* When this is set to `true`, the component attempts to highlight text based on the highlighting properties provided by the search API response.
|
|
26
|
-
* This property only works for the product excerpt and the ec_name field.
|
|
27
|
-
*/
|
|
28
|
-
this.shouldHighlight = true;
|
|
29
|
-
this.error = undefined;
|
|
30
|
-
this.field = undefined;
|
|
31
|
-
this.shouldHighlight = true;
|
|
32
|
-
this.default = undefined;
|
|
33
|
-
}
|
|
34
|
-
get shouldRenderHighlights() {
|
|
35
|
-
return this.shouldHighlight && this.isFieldSupportedForHighlighting();
|
|
36
|
-
}
|
|
37
|
-
isFieldSupportedForHighlighting() {
|
|
38
|
-
return ['ec_name', 'excerpt'].includes(this.field);
|
|
39
|
-
}
|
|
40
|
-
render() {
|
|
41
|
-
const productValueAsString = getStringValueFromProductOrNull(this.product, this.field);
|
|
42
|
-
if (productValueAsString === null) {
|
|
43
|
-
return (h(ItemTextFallback, { field: this.field, host: this.host, logger: this.bindings.engine.logger, defaultValue: this.default, item: this.product, getProperty: ProductTemplatesHelpers.getProductProperty }, h("atomic-commerce-text", { value: getFieldValueCaption(this.field, this.default, this.bindings.i18n) })));
|
|
44
|
-
}
|
|
45
|
-
const textValue = `${productValueAsString}`;
|
|
46
|
-
const highlightKeywords = ProductTemplatesHelpers.getProductProperty(this.product, this.field === 'ec_name' ? 'nameHighlights' : 'excerptHighlights');
|
|
47
|
-
return this.shouldRenderHighlights && highlightKeywords ? (h(ItemTextHighlighted, { textValue: textValue, highlightKeywords: highlightKeywords, highlightString: HighlightUtils.highlightString, onError: (error) => (this.error = error) })) : (h("atomic-commerce-text", { value: getFieldValueCaption(this.field, textValue, this.bindings.i18n) }));
|
|
48
|
-
}
|
|
49
|
-
get host() { return this; }
|
|
50
|
-
}, [0, "atomic-product-text", {
|
|
51
|
-
"field": [513],
|
|
52
|
-
"shouldHighlight": [516, "should-highlight"],
|
|
53
|
-
"default": [513],
|
|
54
|
-
"error": [32]
|
|
55
|
-
}]);
|
|
56
|
-
__decorate([
|
|
57
|
-
InitializeBindings()
|
|
58
|
-
], AtomicProductText.prototype, "bindings", void 0);
|
|
59
|
-
__decorate([
|
|
60
|
-
ProductContext()
|
|
61
|
-
], AtomicProductText.prototype, "product", void 0);
|
|
62
|
-
function defineCustomElement() {
|
|
63
|
-
if (typeof customElements === "undefined") {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const components = ["atomic-product-text", "atomic-commerce-text"];
|
|
67
|
-
components.forEach(tagName => { switch (tagName) {
|
|
68
|
-
case "atomic-product-text":
|
|
69
|
-
if (!customElements.get(tagName)) {
|
|
70
|
-
customElements.define(tagName, AtomicProductText);
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
case "atomic-commerce-text":
|
|
74
|
-
if (!customElements.get(tagName)) {
|
|
75
|
-
defineCustomElement$1();
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
} });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export { AtomicProductText as A, defineCustomElement as d };
|
|
82
|
-
|
|
83
|
-
//# sourceMappingURL=atomic-product-text2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"atomic-product-text2.js","mappings":";;;;;;;;;;;;;;;;;;;MAyBa,iBAAiB;;;;;;;;QAmBE,oBAAe,GAAG,IAAI,CAAC;;;+BAAL,IAAI;;;IAMpD,IAAY,sBAAsB;QAChC,OAAO,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,+BAA+B,EAAE,CAAC;KACvE;IAEM,+BAA+B;QACpC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACpD;IAEM,MAAM;QACX,MAAM,oBAAoB,GAAG,+BAA+B,CAC1D,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,CACX,CAAC;QAEF,IAAI,oBAAoB,KAAK,IAAI,EAAE;YACjC,QACE,EAAC,gBAAgB,IACf,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EACnC,YAAY,EAAE,IAAI,CAAC,OAAO,EAC1B,IAAI,EAAE,IAAI,CAAC,OAAO,EAClB,WAAW,EAAE,uBAAuB,CAAC,kBAAkB,IAEvD,4BACE,KAAK,EAAE,oBAAoB,CACzB,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,OAAQ,EACb,IAAI,CAAC,QAAQ,CAAC,IAAI,CACnB,GACqB,CACP,EACnB;SACH;QAED,MAAM,SAAS,GAAG,GAAG,oBAAoB,EAAE,CAAC;QAC5C,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,kBAAkB,CAClE,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,KAAK,SAAS,GAAG,gBAAgB,GAAG,mBAAmB,CAC7B,CAAC;QAEvC,OAAO,IAAI,CAAC,sBAAsB,IAAI,iBAAiB,IACrD,EAAC,mBAAmB,IAClB,SAAS,EAAE,SAAS,EACpB,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,EAAE,cAAc,CAAC,eAAe,EAC/C,OAAO,EAAE,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,GACnB,KAEvB,4BACE,KAAK,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAChD,CACzB,CAAC;KACH;;;;;;;;AA3E4B;IAA5B,kBAAkB,EAAE;mDAAoC;AAG/B;IAAzB,cAAc,EAAE;kDAA2B;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/commerce/atomic-product-text/atomic-product-text.tsx"],"sourcesContent":["import {\n Product,\n ProductTemplatesHelpers,\n HighlightUtils,\n} from '@coveo/headless/commerce';\nimport {Component, h, Prop, Element, State} from '@stencil/core';\nimport {getFieldValueCaption} from '../../../utils/field-utils';\nimport {\n InitializableComponent,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {ItemTextFallback} from '../../common/item-text/stencil-item-text-fallback';\nimport {ItemTextHighlighted} from '../../common/item-text/stencil-item-text-highlighted';\nimport {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-interface';\nimport {getStringValueFromProductOrNull} from '../product-template-component-utils/product-utils';\nimport {ProductContext} from '../product-template-component-utils/stencil-product-template-decorators';\n\n/**\n * @alpha\n * The `atomic-product-text` component renders the value of a string product field.\n */\n@Component({\n tag: 'atomic-product-text',\n shadow: false,\n})\nexport class AtomicProductText\n implements InitializableComponent<CommerceBindings>\n{\n @InitializeBindings() public bindings!: CommerceBindings;\n @State() public error!: Error;\n\n @ProductContext() private product!: Product;\n\n @Element() private host!: HTMLElement;\n\n /**\n * The product field which the component should use.\n * This will look in the Product object first, and then in the product.additionalFields object for the fields.\n */\n @Prop({reflect: true}) public field!: string;\n /**\n * When this is set to `true`, the component attempts to highlight text based on the highlighting properties provided by the search API response.\n * This property only works for the product excerpt and the ec_name field.\n */\n @Prop({reflect: true}) public shouldHighlight = true;\n /**\n * The locale key for the text to display when the configured field has no value.\n */\n @Prop({reflect: true}) public default?: string;\n\n private get shouldRenderHighlights() {\n return this.shouldHighlight && this.isFieldSupportedForHighlighting();\n }\n\n public isFieldSupportedForHighlighting() {\n return ['ec_name', 'excerpt'].includes(this.field);\n }\n\n public render() {\n const productValueAsString = getStringValueFromProductOrNull(\n this.product,\n this.field\n );\n\n if (productValueAsString === null) {\n return (\n <ItemTextFallback\n field={this.field}\n host={this.host}\n logger={this.bindings.engine.logger}\n defaultValue={this.default}\n item={this.product}\n getProperty={ProductTemplatesHelpers.getProductProperty}\n >\n <atomic-commerce-text\n value={getFieldValueCaption(\n this.field,\n this.default!,\n this.bindings.i18n\n )}\n ></atomic-commerce-text>\n </ItemTextFallback>\n );\n }\n\n const textValue = `${productValueAsString}`;\n const highlightKeywords = ProductTemplatesHelpers.getProductProperty(\n this.product,\n this.field === 'ec_name' ? 'nameHighlights' : 'excerptHighlights'\n ) as HighlightUtils.HighlightKeyword[];\n\n return this.shouldRenderHighlights && highlightKeywords ? (\n <ItemTextHighlighted\n textValue={textValue}\n highlightKeywords={highlightKeywords}\n highlightString={HighlightUtils.highlightString}\n onError={(error) => (this.error = error)}\n ></ItemTextHighlighted>\n ) : (\n <atomic-commerce-text\n value={getFieldValueCaption(this.field, textValue, this.bindings.i18n)}\n ></atomic-commerce-text>\n );\n }\n}\n"],"version":3}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { isArray, isUndefined } from '@coveo/bueno';
|
|
2
|
-
import { h, Fragment, Host } from '@stencil/core/internal/client';
|
|
3
|
-
|
|
4
|
-
function possiblyWarnOnBadFieldType(field, itemValueRaw, host, logger) {
|
|
5
|
-
if (isArray(itemValueRaw)) {
|
|
6
|
-
logger.error(`${host.nodeName.toLowerCase()} cannot be used with multi value field "${field}" with values "${itemValueRaw}".`, host);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const ItemTextFallback = ({ field, host, logger, defaultValue, item, getProperty }, children) => {
|
|
11
|
-
const raw = getProperty(item, field);
|
|
12
|
-
possiblyWarnOnBadFieldType(field, raw, host, logger);
|
|
13
|
-
if (isUndefined(defaultValue)) {
|
|
14
|
-
host.remove();
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
return h(Fragment, null, children);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function renderWithHighlights(value, highlights, highlightString) {
|
|
23
|
-
const openingDelimiter = '_openingDelimiter_';
|
|
24
|
-
const closingDelimiter = '_closingDelimiter_';
|
|
25
|
-
const highlightedValue = highlightString({
|
|
26
|
-
content: value,
|
|
27
|
-
openingDelimiter,
|
|
28
|
-
closingDelimiter,
|
|
29
|
-
highlights,
|
|
30
|
-
});
|
|
31
|
-
return highlightedValue
|
|
32
|
-
.replace(new RegExp(openingDelimiter, 'g'), '<b>')
|
|
33
|
-
.replace(new RegExp(closingDelimiter, 'g'), '</b>');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const ItemTextHighlighted = ({ highlightKeywords, highlightString, onError, textValue }) => {
|
|
37
|
-
try {
|
|
38
|
-
const highlightedValue = renderWithHighlights(textValue, highlightKeywords, highlightString);
|
|
39
|
-
// deepcode ignore ReactSetInnerHtml: This is not React code
|
|
40
|
-
return h(Host, { innerHTML: highlightedValue });
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
onError(error);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export { ItemTextFallback as I, ItemTextHighlighted as a };
|
|
48
|
-
|
|
49
|
-
//# sourceMappingURL=stencil-item-text-highlighted.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"stencil-item-text-highlighted.js","mappings":";;;SAEgB,0BAA0B,CACxC,KAAa,EACb,YAAqB,EACrB,IAAiB,EACjB,MAA8B;IAE9B,IAAI,OAAO,CAAC,YAAY,CAAC,EAAE;QACzB,MAAM,CAAC,KAAK,CACV,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,2CAA2C,KAAK,kBAAkB,YAAY,IAAI,EAChH,IAAI,CACL,CAAC;KACH;AACH;;MCDa,gBAAgB,GAAG,CAC9B,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAmB,EACxE,QAAiB;IAEjB,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,0BAA0B,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAErD,IAAI,WAAW,CAAC,YAAY,CAAC,EAAE;QAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;KACb;SAAM;QACL,OAAO,EAAC,QAAQ,QAAE,QAAQ,CAAY,CAAC;KACxC;AACH;;SCdgB,oBAAoB,CAClC,KAAa,EACb,UAA+B,EAC/B,eAAgC;IAEhC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;IAC9C,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;IAC9C,MAAM,gBAAgB,GAAG,eAAe,CAAC;QACvC,OAAO,EAAE,KAAK;QACd,gBAAgB;QAChB,gBAAgB;QAChB,UAAU;KACX,CAAC,CAAC;IACH,OAAO,gBAAgB;SACpB,OAAO,CAAC,IAAI,MAAM,CAAC,gBAAgB,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC;SACjD,OAAO,CAAC,IAAI,MAAM,CAAC,gBAAgB,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;AACxD;;MCda,mBAAmB,GAE5B,CAAC,EAAC,iBAAiB,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAC;IAC3D,IAAI;QACF,MAAM,gBAAgB,GAAG,oBAAoB,CAC3C,SAAS,EACT,iBAAiB,EACjB,eAAe,CAChB,CAAC;;QAGF,OAAO,EAAC,IAAI,IAAC,SAAS,EAAE,gBAAgB,GAAS,CAAC;KACnD;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAc,CAAC,CAAC;KACzB;AACH;;;;","names":[],"sources":["src/components/common/item-text/field-warning.ts","src/components/common/item-text/stencil-item-text-fallback.tsx","src/components/common/item-text/render-highlights.ts","src/components/common/item-text/stencil-item-text-highlighted.tsx"],"sourcesContent":["import {isArray} from '@coveo/bueno';\n\nexport function possiblyWarnOnBadFieldType(\n field: string,\n itemValueRaw: unknown,\n host: HTMLElement,\n logger: Pick<Console, 'error'>\n) {\n if (isArray(itemValueRaw)) {\n logger.error(\n `${host.nodeName.toLowerCase()} cannot be used with multi value field \"${field}\" with values \"${itemValueRaw}\".`,\n host\n );\n }\n}\n","import {isUndefined} from '@coveo/bueno';\nimport {Fragment, FunctionalComponent, VNode, h} from '@stencil/core';\nimport {possiblyWarnOnBadFieldType} from './field-warning';\n\nexport interface ItemTextProps<T> {\n logger: Pick<Console, 'error'>;\n host: HTMLElement;\n defaultValue: string | undefined;\n field: string;\n item: T;\n getProperty: (result: T, property: string) => unknown;\n}\n\nexport const ItemTextFallback = <T,>(\n {field, host, logger, defaultValue, item, getProperty}: ItemTextProps<T>,\n children: VNode[]\n): FunctionalComponent<ItemTextProps<T>> | null => {\n const raw = getProperty(item, field);\n possiblyWarnOnBadFieldType(field, raw, host, logger);\n\n if (isUndefined(defaultValue)) {\n host.remove();\n return null;\n } else {\n return <Fragment>{children}</Fragment>;\n }\n};\n","export type HighlightKeywords = {\n offset: number;\n length: number;\n};\n\nexport type HighlightString = (params: {\n content: string;\n openingDelimiter: string;\n closingDelimiter: string;\n highlights: HighlightKeywords[];\n}) => string;\n\nexport function renderWithHighlights(\n value: string,\n highlights: HighlightKeywords[],\n highlightString: HighlightString\n) {\n const openingDelimiter = '_openingDelimiter_';\n const closingDelimiter = '_closingDelimiter_';\n const highlightedValue = highlightString({\n content: value,\n openingDelimiter,\n closingDelimiter,\n highlights,\n });\n return highlightedValue\n .replace(new RegExp(openingDelimiter, 'g'), '<b>')\n .replace(new RegExp(closingDelimiter, 'g'), '</b>');\n}\n","import {FunctionalComponent, h, Host} from '@stencil/core';\nimport {\n HighlightKeywords,\n HighlightString,\n renderWithHighlights,\n} from './render-highlights';\n\nexport interface ItemTextHighlightedProps {\n textValue: string;\n highlightKeywords: HighlightKeywords[];\n onError: (error: Error) => void;\n highlightString: HighlightString;\n}\n\nexport const ItemTextHighlighted: FunctionalComponent<\n ItemTextHighlightedProps\n> = ({highlightKeywords, highlightString, onError, textValue}) => {\n try {\n const highlightedValue = renderWithHighlights(\n textValue,\n highlightKeywords,\n highlightString\n );\n\n // deepcode ignore ReactSetInnerHtml: This is not React code\n return <Host innerHTML={highlightedValue}></Host>;\n } catch (error) {\n onError(error as Error);\n }\n};\n"],"version":3}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["AtomicLayoutSection"],"sources":["src/components/common/atomic-layout-section/atomic-layout-section.tsx"],"sourcesContent":["import {Component, Prop} from '@stencil/core';\nimport {Section} from './sections';\n\n/**\n * The `atomic-layout-section` lets you identify various sections for the related `atomic-layout` component.\n */\n@Component({\n tag: 'atomic-layout-section',\n shadow: false,\n})\nexport class AtomicLayoutSection {\n /**\n * The name of the layout section.\n */\n @Prop({reflect: true}) public section!: Section;\n /**\n * For column sections, the minimum horizontal space it should take.\n * E.g. '300px'\n */\n @Prop({reflect: true}) public minWidth?: string;\n /**\n * For column sections, the maximum horizontal space it should take.\n * E.g. '300px'\n */\n @Prop({reflect: true}) public maxWidth?: string;\n}\n"],"mappings":"0CAUaA,EAAmB,M","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as t,g as i}from"./p-dc3df5ce.js";import{I as e}from"./p-d6e6dbc3.js";import{b as s}from"./p-25a96534.js";import{p as r}from"./p-bb081d4e.js";import{P as o}from"./p-c58eda89.js";import"./p-c9074946.js";import"./p-1580513b.js";import"./p-05de7ca3.js";import"./p-f77160c6.js";import"./p-c32fca86.js";import"@coveo/headless/commerce";import"./p-b1b751a5.js";import"./p-3dc06261.js";var p=undefined&&undefined.__decorate||function(t,i,e,s){var r=arguments.length,o=r<3?i:s===null?s=Object.getOwnPropertyDescriptor(i,e):s,p;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")o=Reflect.decorate(t,i,e,s);else for(var c=t.length-1;c>=0;c--)if(p=t[c])o=(r<3?p(o):r>3?p(i,e,o):p(i,e))||o;return r>3&&o&&Object.defineProperty(i,e,o),o};const c=class{constructor(i){t(this,i);this.formatter=s;this.valueToDisplay=null;this.error=undefined;this.field=undefined;this.formatter=s;this.valueToDisplay=null}setFormat(t){t.preventDefault();t.stopPropagation();this.formatter=t.detail}formatValue(t){try{return this.formatter(t,this.bindings.i18n.languages)}catch(i){this.error=i;return t.toString()}}updateValueToDisplay(){const t=r(this.product,this.field);if(t!==null){this.valueToDisplay=this.formatValue(t)}}componentWillRender(){this.updateValueToDisplay()}render(){if(this.valueToDisplay===null){this.host.remove();return}return this.valueToDisplay}get host(){return i(this)}};p([e()],c.prototype,"bindings",void 0);p([o()],c.prototype,"product",void 0);export{c as atomic_product_numeric_field_value};
|
|
2
|
-
//# sourceMappingURL=p-5cf5bb98.entry.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as t,h as e,g as i}from"./p-dc3df5ce.js";import{I as s}from"./p-d6e6dbc3.js";import{ProductTemplatesHelpers as r,HighlightUtils as o}from"@coveo/headless/commerce";import{g as n}from"./p-55d2bcf3.js";import{I as c,a as h}from"./p-b1a7d837.js";import{g as d}from"./p-bb081d4e.js";import{P as f}from"./p-c58eda89.js";import"./p-c9074946.js";import"./p-1580513b.js";import"./p-05de7ca3.js";import"./p-f77160c6.js";import"@coveo/bueno";import"./p-c32fca86.js";import"./p-b1b751a5.js";import"./p-3dc06261.js";var u=undefined&&undefined.__decorate||function(t,e,i,s){var r=arguments.length,o=r<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,i):s,n;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")o=Reflect.decorate(t,e,i,s);else for(var c=t.length-1;c>=0;c--)if(n=t[c])o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o;return r>3&&o&&Object.defineProperty(e,i,o),o};const a=class{constructor(e){t(this,e);this.strings={value:()=>this.bindings.i18n.t(this.value,{count:this.count})};this.error=undefined;this.value=undefined;this.count=undefined}connectedCallback(){if(!this.value){this.error=new Error('The "value" attribute must be defined.')}}render(){return this.strings.value()}};u([s()],a.prototype,"bindings",void 0);var p=undefined&&undefined.__decorate||function(t,e,i,s){var r=arguments.length,o=r<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,i):s,n;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")o=Reflect.decorate(t,e,i,s);else for(var c=t.length-1;c>=0;c--)if(n=t[c])o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o;return r>3&&o&&Object.defineProperty(e,i,o),o};const m=class{constructor(e){t(this,e);this.shouldHighlight=true;this.error=undefined;this.field=undefined;this.shouldHighlight=true;this.default=undefined}get shouldRenderHighlights(){return this.shouldHighlight&&this.isFieldSupportedForHighlighting()}isFieldSupportedForHighlighting(){return["ec_name","excerpt"].includes(this.field)}render(){const t=d(this.product,this.field);if(t===null){return e(c,{field:this.field,host:this.host,logger:this.bindings.engine.logger,defaultValue:this.default,item:this.product,getProperty:r.getProductProperty},e("atomic-commerce-text",{value:n(this.field,this.default,this.bindings.i18n)}))}const i=`${t}`;const s=r.getProductProperty(this.product,this.field==="ec_name"?"nameHighlights":"excerptHighlights");return this.shouldRenderHighlights&&s?e(h,{textValue:i,highlightKeywords:s,highlightString:o.highlightString,onError:t=>this.error=t}):e("atomic-commerce-text",{value:n(this.field,i,this.bindings.i18n)})}get host(){return i(this)}};p([s()],m.prototype,"bindings",void 0);p([f()],m.prototype,"product",void 0);export{a as atomic_commerce_text,m as atomic_product_text};
|
|
2
|
-
//# sourceMappingURL=p-67ef14ac.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["AtomicCommerceText","this","strings","value","bindings","i18n","t","count","connectedCallback","error","Error","render","__decorate","InitializeBindings","AtomicProductText","shouldHighlight","shouldRenderHighlights","isFieldSupportedForHighlighting","includes","field","productValueAsString","getStringValueFromProductOrNull","product","h","ItemTextFallback","host","logger","engine","defaultValue","default","item","getProperty","ProductTemplatesHelpers","getProductProperty","getFieldValueCaption","textValue","highlightKeywords","ItemTextHighlighted","highlightString","HighlightUtils","onError","ProductContext"],"sources":["src/components/commerce/atomic-commerce-text/atomic-commerce-text.tsx","src/components/commerce/atomic-product-text/atomic-product-text.tsx"],"sourcesContent":["import {Component, Prop, State} from '@stencil/core';\nimport {\n InitializableComponent,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-interface';\n\n/**\n * @alpha\n * The `atomic-commerce-text` component leverages the I18n translation module through the atomic-commerce-interface.\n */\n@Component({\n tag: 'atomic-commerce-text',\n shadow: true,\n})\nexport class AtomicCommerceText\n implements InitializableComponent<CommerceBindings>\n{\n @InitializeBindings() public bindings!: CommerceBindings;\n\n private strings = {\n value: () =>\n this.bindings.i18n.t(this.value, {\n count: this.count,\n }),\n };\n @State() public error!: Error;\n\n /**\n * The string key value.\n */\n @Prop({reflect: true}) public value!: string;\n /**\n * The count value used for plurals.\n * @type {number}\n */\n @Prop({reflect: true}) public count?: number;\n\n public connectedCallback() {\n if (!this.value) {\n this.error = new Error('The \"value\" attribute must be defined.');\n }\n }\n\n public render() {\n return this.strings.value();\n }\n}\n","import {\n Product,\n ProductTemplatesHelpers,\n HighlightUtils,\n} from '@coveo/headless/commerce';\nimport {Component, h, Prop, Element, State} from '@stencil/core';\nimport {getFieldValueCaption} from '../../../utils/field-utils';\nimport {\n InitializableComponent,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {ItemTextFallback} from '../../common/item-text/stencil-item-text-fallback';\nimport {ItemTextHighlighted} from '../../common/item-text/stencil-item-text-highlighted';\nimport {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-interface';\nimport {getStringValueFromProductOrNull} from '../product-template-component-utils/product-utils';\nimport {ProductContext} from '../product-template-component-utils/stencil-product-template-decorators';\n\n/**\n * @alpha\n * The `atomic-product-text` component renders the value of a string product field.\n */\n@Component({\n tag: 'atomic-product-text',\n shadow: false,\n})\nexport class AtomicProductText\n implements InitializableComponent<CommerceBindings>\n{\n @InitializeBindings() public bindings!: CommerceBindings;\n @State() public error!: Error;\n\n @ProductContext() private product!: Product;\n\n @Element() private host!: HTMLElement;\n\n /**\n * The product field which the component should use.\n * This will look in the Product object first, and then in the product.additionalFields object for the fields.\n */\n @Prop({reflect: true}) public field!: string;\n /**\n * When this is set to `true`, the component attempts to highlight text based on the highlighting properties provided by the search API response.\n * This property only works for the product excerpt and the ec_name field.\n */\n @Prop({reflect: true}) public shouldHighlight = true;\n /**\n * The locale key for the text to display when the configured field has no value.\n */\n @Prop({reflect: true}) public default?: string;\n\n private get shouldRenderHighlights() {\n return this.shouldHighlight && this.isFieldSupportedForHighlighting();\n }\n\n public isFieldSupportedForHighlighting() {\n return ['ec_name', 'excerpt'].includes(this.field);\n }\n\n public render() {\n const productValueAsString = getStringValueFromProductOrNull(\n this.product,\n this.field\n );\n\n if (productValueAsString === null) {\n return (\n <ItemTextFallback\n field={this.field}\n host={this.host}\n logger={this.bindings.engine.logger}\n defaultValue={this.default}\n item={this.product}\n getProperty={ProductTemplatesHelpers.getProductProperty}\n >\n <atomic-commerce-text\n value={getFieldValueCaption(\n this.field,\n this.default!,\n this.bindings.i18n\n )}\n ></atomic-commerce-text>\n </ItemTextFallback>\n );\n }\n\n const textValue = `${productValueAsString}`;\n const highlightKeywords = ProductTemplatesHelpers.getProductProperty(\n this.product,\n this.field === 'ec_name' ? 'nameHighlights' : 'excerptHighlights'\n ) as HighlightUtils.HighlightKeyword[];\n\n return this.shouldRenderHighlights && highlightKeywords ? (\n <ItemTextHighlighted\n textValue={textValue}\n highlightKeywords={highlightKeywords}\n highlightString={HighlightUtils.highlightString}\n onError={(error) => (this.error = error)}\n ></ItemTextHighlighted>\n ) : (\n <atomic-commerce-text\n value={getFieldValueCaption(this.field, textValue, this.bindings.i18n)}\n ></atomic-commerce-text>\n );\n }\n}\n"],"mappings":"k3BAeaA,EAAkB,M,yBAKrBC,KAAAC,QAAU,CAChBC,MAAO,IACLF,KAAKG,SAASC,KAAKC,EAAEL,KAAKE,MAAO,CAC/BI,MAAON,KAAKM,S,+DAeX,iBAAAC,GACL,IAAKP,KAAKE,MAAO,CACfF,KAAKQ,MAAQ,IAAIC,MAAM,yC,EAIpB,MAAAC,GACL,OAAOV,KAAKC,QAAQC,O,GA3BOS,GAA5BC,K,gZCOUC,EAAiB,M,yBAmBEb,KAAAc,gBAAkB,K,+DAAA,K,uBAMhD,0BAAYC,GACV,OAAOf,KAAKc,iBAAmBd,KAAKgB,iC,CAG/B,+BAAAA,GACL,MAAO,CAAC,UAAW,WAAWC,SAASjB,KAAKkB,M,CAGvC,MAAAR,GACL,MAAMS,EAAuBC,EAC3BpB,KAAKqB,QACLrB,KAAKkB,OAGP,GAAIC,IAAyB,KAAM,CACjC,OACEG,EAACC,EAAgB,CACfL,MAAOlB,KAAKkB,MACZM,KAAMxB,KAAKwB,KACXC,OAAQzB,KAAKG,SAASuB,OAAOD,OAC7BE,aAAc3B,KAAK4B,QACnBC,KAAM7B,KAAKqB,QACXS,YAAaC,EAAwBC,oBAErCV,EAAA,wBACEpB,MAAO+B,EACLjC,KAAKkB,MACLlB,KAAK4B,QACL5B,KAAKG,SAASC,Q,CAOxB,MAAM8B,EAAY,GAAGf,IACrB,MAAMgB,EAAoBJ,EAAwBC,mBAChDhC,KAAKqB,QACLrB,KAAKkB,QAAU,UAAY,iBAAmB,qBAGhD,OAAOlB,KAAKe,wBAA0BoB,EACpCb,EAACc,EAAmB,CAClBF,UAAWA,EACXC,kBAAmBA,EACnBE,gBAAiBC,EAAeD,gBAChCE,QAAU/B,GAAWR,KAAKQ,MAAQA,IAGpCc,EAAA,wBACEpB,MAAO+B,EAAqBjC,KAAKkB,MAAOgB,EAAWlC,KAAKG,SAASC,O,6BAxE1CO,EAAA,CAA5BC,K,+BAGyBD,EAAA,CAAzB6B,K","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as t,h as e,g as i}from"./p-dc3df5ce.js";import{ResultTemplatesHelpers as s,HighlightUtils as r}from"@coveo/headless";import{g as o}from"./p-55d2bcf3.js";import{I as n}from"./p-d6e6dbc3.js";import{g as c}from"./p-f3dd836a.js";import{I as f,a as h}from"./p-b1a7d837.js";import{R as d}from"./p-18684d4c.js";import"./p-c9074946.js";import"./p-1580513b.js";import"./p-05de7ca3.js";import"./p-f77160c6.js";import"./p-c32fca86.js";import"@coveo/bueno";import"./p-3dc06261.js";var u=undefined&&undefined.__decorate||function(t,e,i,s){var r=arguments.length,o=r<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,i):s,n;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")o=Reflect.decorate(t,e,i,s);else for(var c=t.length-1;c>=0;c--)if(n=t[c])o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o;return r>3&&o&&Object.defineProperty(e,i,o),o};const a=class{constructor(e){t(this,e);this.shouldHighlight=true;this.error=undefined;this.field=undefined;this.shouldHighlight=true;this.default=undefined}render(){const t=c(this.result,this.field);if(t===null){return e(f,{field:this.field,host:this.host,logger:this.bindings.engine.logger,defaultValue:this.default,item:this.result,getProperty:s.getResultProperty},e("atomic-text",{value:o(this.field,this.default,this.bindings.i18n)}))}const i=`${t}`;const n=s.getResultProperty(this.result,`${this.field}Highlights`);return this.shouldHighlight&&n?e(h,{textValue:i,highlightKeywords:n,highlightString:r.highlightString,onError:t=>this.error=t}):o(this.field,i,this.bindings.i18n)}get host(){return i(this)}};u([n()],a.prototype,"bindings",void 0);u([d()],a.prototype,"result",void 0);var l=undefined&&undefined.__decorate||function(t,e,i,s){var r=arguments.length,o=r<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,i):s,n;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")o=Reflect.decorate(t,e,i,s);else for(var c=t.length-1;c>=0;c--)if(n=t[c])o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o;return r>3&&o&&Object.defineProperty(e,i,o),o};const p=class{constructor(e){t(this,e);this.strings={value:()=>this.bindings.i18n.t(this.value,{count:this.count})};this.error=undefined;this.value=undefined;this.count=undefined}connectedCallback(){if(!this.value){this.error=new Error('The "value" attribute must be defined.')}}render(){return this.strings.value()}};l([n()],p.prototype,"bindings",void 0);export{a as atomic_result_text,p as atomic_text};
|
|
2
|
-
//# sourceMappingURL=p-733252f1.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["AtomicResultText","this","shouldHighlight","render","resultValueAsString","getStringValueFromResultOrNull","result","field","h","ItemTextFallback","host","logger","bindings","engine","defaultValue","default","item","getProperty","ResultTemplatesHelpers","getResultProperty","value","getFieldValueCaption","i18n","textValue","highlightKeywords","ItemTextHighlighted","highlightString","HighlightUtils","onError","error","__decorate","InitializeBindings","ResultContext","AtomicText","strings","t","count","connectedCallback","Error"],"sources":["src/components/search/result-template-components/atomic-result-text/atomic-result-text.tsx","src/components/search/atomic-text/atomic-text.tsx"],"sourcesContent":["import {HighlightUtils, Result, ResultTemplatesHelpers} from '@coveo/headless';\nimport {Component, Prop, h, Element, State} from '@stencil/core';\nimport {getFieldValueCaption} from '../../../../utils/field-utils';\nimport {\n InitializableComponent,\n InitializeBindings,\n} from '../../../../utils/initialization-utils';\nimport {getStringValueFromResultOrNull} from '../../../../utils/result-utils';\nimport {ItemTextFallback} from '../../../common/item-text/stencil-item-text-fallback';\nimport {ItemTextHighlighted} from '../../../common/item-text/stencil-item-text-highlighted';\nimport {Bindings} from '../../atomic-search-interface/atomic-search-interface';\nimport {ResultContext} from '../result-template-decorators';\n\n/**\n * The `atomic-result-text` component renders the value of a string result field.\n */\n@Component({\n tag: 'atomic-result-text',\n shadow: false,\n})\nexport class AtomicResultText implements InitializableComponent {\n @InitializeBindings() public bindings!: Bindings;\n @ResultContext() private result!: Result;\n\n @Element() private host!: HTMLElement;\n\n @State() public error!: Error;\n\n /**\n * The result field which the component should use.\n * This will look in the Result object first, and then in the Result.raw object for the fields.\n * It is important to include the necessary field in the `atomic-search-interface` component.\n */\n @Prop({reflect: true}) public field!: string;\n /**\n * When this is set to `true`, the component attempts to highlight text based on the highlighting properties provided by the search API response.\n */\n @Prop({reflect: true}) public shouldHighlight = true;\n\n /**\n * The locale key for the text to display when the configured field has no value.\n */\n @Prop({reflect: true}) public default?: string;\n\n public render() {\n const resultValueAsString = getStringValueFromResultOrNull(\n this.result,\n this.field\n );\n\n if (resultValueAsString === null) {\n return (\n <ItemTextFallback\n field={this.field}\n host={this.host}\n logger={this.bindings.engine.logger}\n defaultValue={this.default}\n item={this.result}\n getProperty={ResultTemplatesHelpers.getResultProperty}\n >\n <atomic-text\n value={getFieldValueCaption(\n this.field,\n this.default!,\n this.bindings.i18n\n )}\n ></atomic-text>\n </ItemTextFallback>\n );\n }\n\n const textValue = `${resultValueAsString}`;\n const highlightKeywords = ResultTemplatesHelpers.getResultProperty(\n this.result,\n `${this.field}Highlights`\n ) as HighlightUtils.HighlightKeyword[];\n\n return this.shouldHighlight && highlightKeywords ? (\n <ItemTextHighlighted\n textValue={textValue}\n highlightKeywords={highlightKeywords}\n highlightString={HighlightUtils.highlightString}\n onError={(error) => (this.error = error)}\n ></ItemTextHighlighted>\n ) : (\n getFieldValueCaption(this.field, textValue, this.bindings.i18n)\n );\n }\n}\n","import {Component, Prop, State} from '@stencil/core';\nimport {\n InitializableComponent,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {Bindings} from '../atomic-search-interface/atomic-search-interface';\n\n/**\n * The `atomic-text` component leverages the I18n translation module through the atomic-search-interface.\n */\n@Component({\n tag: 'atomic-text',\n shadow: true,\n})\nexport class AtomicText implements InitializableComponent {\n @InitializeBindings() public bindings!: Bindings;\n\n private strings = {\n value: () =>\n this.bindings.i18n.t(this.value, {\n count: this.count,\n }),\n };\n @State() public error!: Error;\n\n /**\n * The string key value.\n */\n @Prop({reflect: true}) public value!: string;\n /**\n * The count value used for plurals.\n */\n @Prop({reflect: true}) public count?: number;\n\n public connectedCallback() {\n if (!this.value) {\n this.error = new Error('The \"value\" attribute must be defined.');\n }\n }\n\n public render() {\n return this.strings.value();\n }\n}\n"],"mappings":"g1BAoBaA,EAAgB,M,yBAiBGC,KAAAC,gBAAkB,K,+DAAA,K,uBAOzC,MAAAC,GACL,MAAMC,EAAsBC,EAC1BJ,KAAKK,OACLL,KAAKM,OAGP,GAAIH,IAAwB,KAAM,CAChC,OACEI,EAACC,EAAgB,CACfF,MAAON,KAAKM,MACZG,KAAMT,KAAKS,KACXC,OAAQV,KAAKW,SAASC,OAAOF,OAC7BG,aAAcb,KAAKc,QACnBC,KAAMf,KAAKK,OACXW,YAAaC,EAAuBC,mBAEpCX,EAAA,eACEY,MAAOC,EACLpB,KAAKM,MACLN,KAAKc,QACLd,KAAKW,SAASU,Q,CAOxB,MAAMC,EAAY,GAAGnB,IACrB,MAAMoB,EAAoBN,EAAuBC,kBAC/ClB,KAAKK,OACL,GAAGL,KAAKM,mBAGV,OAAON,KAAKC,iBAAmBsB,EAC7BhB,EAACiB,EAAmB,CAClBF,UAAWA,EACXC,kBAAmBA,EACnBE,gBAAiBC,EAAeD,gBAChCE,QAAUC,GAAW5B,KAAK4B,MAAQA,IAGpCR,EAAqBpB,KAAKM,MAAOgB,EAAWtB,KAAKW,SAASU,K,6BAhEjCQ,GAA5BC,K,+BACwBD,GAAxBE,K,8YCRUC,EAAU,M,yBAGbhC,KAAAiC,QAAU,CAChBd,MAAO,IACLnB,KAAKW,SAASU,KAAKa,EAAElC,KAAKmB,MAAO,CAC/BgB,MAAOnC,KAAKmC,S,+DAcX,iBAAAC,GACL,IAAKpC,KAAKmB,MAAO,CACfnB,KAAK4B,MAAQ,IAAIS,MAAM,yC,EAIpB,MAAAnC,GACL,OAAOF,KAAKiC,QAAQd,O,GA1BOU,EAAA,CAA5BC,K","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{isArray as e,isUndefined as t}from"@coveo/bueno";import{h as n,F as i,H as o}from"./p-dc3df5ce.js";function r(t,n,i,o){if(e(n)){o.error(`${i.nodeName.toLowerCase()} cannot be used with multi value field "${t}" with values "${n}".`,i)}}const l=({field:e,host:o,logger:l,defaultValue:s,item:c,getProperty:g},u)=>{const h=g(c,e);r(e,h,o,l);if(t(s)){o.remove();return null}else{return n(i,null,u)}};function s(e,t,n){const i="_openingDelimiter_";const o="_closingDelimiter_";const r=n({content:e,openingDelimiter:i,closingDelimiter:o,highlights:t});return r.replace(new RegExp(i,"g"),"<b>").replace(new RegExp(o,"g"),"</b>")}const c=({highlightKeywords:e,highlightString:t,onError:i,textValue:r})=>{try{const i=s(r,e,t);return n(o,{innerHTML:i})}catch(e){i(e)}};export{l as I,c as a};
|
|
2
|
-
//# sourceMappingURL=p-b1a7d837.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["possiblyWarnOnBadFieldType","field","itemValueRaw","host","logger","isArray","error","nodeName","toLowerCase","ItemTextFallback","defaultValue","item","getProperty","children","raw","isUndefined","remove","h","Fragment","renderWithHighlights","value","highlights","highlightString","openingDelimiter","closingDelimiter","highlightedValue","content","replace","RegExp","ItemTextHighlighted","highlightKeywords","onError","textValue","Host","innerHTML"],"sources":["src/components/common/item-text/field-warning.ts","src/components/common/item-text/stencil-item-text-fallback.tsx","src/components/common/item-text/render-highlights.ts","src/components/common/item-text/stencil-item-text-highlighted.tsx"],"sourcesContent":["import {isArray} from '@coveo/bueno';\n\nexport function possiblyWarnOnBadFieldType(\n field: string,\n itemValueRaw: unknown,\n host: HTMLElement,\n logger: Pick<Console, 'error'>\n) {\n if (isArray(itemValueRaw)) {\n logger.error(\n `${host.nodeName.toLowerCase()} cannot be used with multi value field \"${field}\" with values \"${itemValueRaw}\".`,\n host\n );\n }\n}\n","import {isUndefined} from '@coveo/bueno';\nimport {Fragment, FunctionalComponent, VNode, h} from '@stencil/core';\nimport {possiblyWarnOnBadFieldType} from './field-warning';\n\nexport interface ItemTextProps<T> {\n logger: Pick<Console, 'error'>;\n host: HTMLElement;\n defaultValue: string | undefined;\n field: string;\n item: T;\n getProperty: (result: T, property: string) => unknown;\n}\n\nexport const ItemTextFallback = <T,>(\n {field, host, logger, defaultValue, item, getProperty}: ItemTextProps<T>,\n children: VNode[]\n): FunctionalComponent<ItemTextProps<T>> | null => {\n const raw = getProperty(item, field);\n possiblyWarnOnBadFieldType(field, raw, host, logger);\n\n if (isUndefined(defaultValue)) {\n host.remove();\n return null;\n } else {\n return <Fragment>{children}</Fragment>;\n }\n};\n","export type HighlightKeywords = {\n offset: number;\n length: number;\n};\n\nexport type HighlightString = (params: {\n content: string;\n openingDelimiter: string;\n closingDelimiter: string;\n highlights: HighlightKeywords[];\n}) => string;\n\nexport function renderWithHighlights(\n value: string,\n highlights: HighlightKeywords[],\n highlightString: HighlightString\n) {\n const openingDelimiter = '_openingDelimiter_';\n const closingDelimiter = '_closingDelimiter_';\n const highlightedValue = highlightString({\n content: value,\n openingDelimiter,\n closingDelimiter,\n highlights,\n });\n return highlightedValue\n .replace(new RegExp(openingDelimiter, 'g'), '<b>')\n .replace(new RegExp(closingDelimiter, 'g'), '</b>');\n}\n","import {FunctionalComponent, h, Host} from '@stencil/core';\nimport {\n HighlightKeywords,\n HighlightString,\n renderWithHighlights,\n} from './render-highlights';\n\nexport interface ItemTextHighlightedProps {\n textValue: string;\n highlightKeywords: HighlightKeywords[];\n onError: (error: Error) => void;\n highlightString: HighlightString;\n}\n\nexport const ItemTextHighlighted: FunctionalComponent<\n ItemTextHighlightedProps\n> = ({highlightKeywords, highlightString, onError, textValue}) => {\n try {\n const highlightedValue = renderWithHighlights(\n textValue,\n highlightKeywords,\n highlightString\n );\n\n // deepcode ignore ReactSetInnerHtml: This is not React code\n return <Host innerHTML={highlightedValue}></Host>;\n } catch (error) {\n onError(error as Error);\n }\n};\n"],"mappings":"mHAEgBA,EACdC,EACAC,EACAC,EACAC,GAEA,GAAIC,EAAQH,GAAe,CACzBE,EAAOE,MACL,GAAGH,EAAKI,SAASC,wDAAwDP,mBAAuBC,MAChGC,E,CAGN,C,MCDaM,EAAmB,EAC7BR,QAAOE,OAAMC,SAAQM,eAAcC,OAAMC,eAC1CC,KAEA,MAAMC,EAAMF,EAAYD,EAAMV,GAC9BD,EAA2BC,EAAOa,EAAKX,EAAMC,GAE7C,GAAIW,EAAYL,GAAe,CAC7BP,EAAKa,SACL,OAAO,I,KACF,CACL,OAAOC,EAACC,EAAQ,KAAEL,E,YCZNM,EACdC,EACAC,EACAC,GAEA,MAAMC,EAAmB,qBACzB,MAAMC,EAAmB,qBACzB,MAAMC,EAAmBH,EAAgB,CACvCI,QAASN,EACTG,mBACAC,mBACAH,eAEF,OAAOI,EACJE,QAAQ,IAAIC,OAAOL,EAAkB,KAAM,OAC3CI,QAAQ,IAAIC,OAAOJ,EAAkB,KAAM,OAChD,C,MCdaK,EAET,EAAEC,oBAAmBR,kBAAiBS,UAASC,gBACjD,IACE,MAAMP,EAAmBN,EACvBa,EACAF,EACAR,GAIF,OAAOL,EAACgB,EAAI,CAACC,UAAWT,G,CACxB,MAAOnB,GACPyB,EAAQzB,E","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as n}from"./p-c32fca86.js";import{ProductTemplatesHelpers as t}from"@coveo/headless/commerce";import{F as e}from"./p-b1b751a5.js";function o(n,o){const r=t.getProductProperty(n,o);if(r===null){return null}const i=parseFloat(`${r}`);if(Number.isNaN(i)){throw new e(o,r)}return i}function r(n,e){const o=t.getProductProperty(n,e);if(typeof o!=="string"||o.trim()===""){return null}return o}function i(t,e,o){return t.replace(/\${(.*?)}/g,(t=>{const r=t.substring(2,t.length-1);let i=n(e,r);if(!i&&typeof window!=="undefined"){i=n(window,r)}if(!i){o.engine.logger.warn(`${r} used in the href template is undefined for this product: ${e.permanentid} and could not be found in the window object.`);return""}return i}))}export{i as b,r as g,o as p};
|
|
2
|
-
//# sourceMappingURL=p-bb081d4e.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["parseValue","product","field","value","ProductTemplatesHelpers","getProductProperty","valueAsNumber","parseFloat","Number","isNaN","FieldValueIsNaNError","getStringValueFromProductOrNull","trim","buildStringTemplateFromProduct","template","bindings","replace","key","substring","length","newValue","readFromObject","window","engine","logger","warn","permanentid"],"sources":["src/components/commerce/product-template-component-utils/product-utils.ts"],"sourcesContent":["import {readFromObject} from '@/src/utils/object-utils';\nimport {Product, ProductTemplatesHelpers} from '@coveo/headless/commerce';\nimport {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-interface';\nimport {FieldValueIsNaNError} from './error';\n\nexport function parseValue(product: Product, field: string) {\n const value = ProductTemplatesHelpers.getProductProperty(product, field);\n if (value === null) {\n return null;\n }\n const valueAsNumber = parseFloat(`${value}`);\n if (Number.isNaN(valueAsNumber)) {\n throw new FieldValueIsNaNError(field, value);\n }\n return valueAsNumber;\n}\n\nexport function getStringValueFromProductOrNull(\n product: Product,\n field: string\n) {\n const value = ProductTemplatesHelpers.getProductProperty(product, field);\n\n if (typeof value !== 'string' || value.trim() === '') {\n return null;\n }\n\n return value;\n}\n\nexport function buildStringTemplateFromProduct(\n template: string,\n product: Product,\n bindings: CommerceBindings\n) {\n return template.replace(/\\${(.*?)}/g, (value: string) => {\n const key = value.substring(2, value.length - 1);\n let newValue = readFromObject(product, key);\n if (!newValue && typeof window !== 'undefined') {\n newValue = readFromObject(window, key);\n }\n\n if (!newValue) {\n bindings.engine.logger.warn(\n `${key} used in the href template is undefined for this product: ${product.permanentid} and could not be found in the window object.`\n );\n return '';\n }\n\n return newValue;\n });\n}\n"],"mappings":"oJAKgBA,EAAWC,EAAkBC,GAC3C,MAAMC,EAAQC,EAAwBC,mBAAmBJ,EAASC,GAClE,GAAIC,IAAU,KAAM,CAClB,OAAO,I,CAET,MAAMG,EAAgBC,WAAW,GAAGJ,KACpC,GAAIK,OAAOC,MAAMH,GAAgB,CAC/B,MAAM,IAAII,EAAqBR,EAAOC,E,CAExC,OAAOG,CACT,C,SAEgBK,EACdV,EACAC,GAEA,MAAMC,EAAQC,EAAwBC,mBAAmBJ,EAASC,GAElE,UAAWC,IAAU,UAAYA,EAAMS,SAAW,GAAI,CACpD,OAAO,I,CAGT,OAAOT,CACT,C,SAEgBU,EACdC,EACAb,EACAc,GAEA,OAAOD,EAASE,QAAQ,cAAeb,IACrC,MAAMc,EAAMd,EAAMe,UAAU,EAAGf,EAAMgB,OAAS,GAC9C,IAAIC,EAAWC,EAAepB,EAASgB,GACvC,IAAKG,UAAmBE,SAAW,YAAa,CAC9CF,EAAWC,EAAeC,OAAQL,E,CAGpC,IAAKG,EAAU,CACbL,EAASQ,OAAOC,OAAOC,KACrB,GAAGR,8DAAgEhB,EAAQyB,4DAE7E,MAAO,E,CAGT,OAAON,CAAQ,GAEnB,Q","ignoreList":[]}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const index = require('./index-757bc886.js');
|
|
6
|
-
const initializationUtils = require('./initialization-utils-62dc9852.js');
|
|
7
|
-
const commerce = require('@coveo/headless/commerce');
|
|
8
|
-
const fieldUtils = require('./field-utils-a715deca.js');
|
|
9
|
-
const stencilItemTextHighlighted = require('./stencil-item-text-highlighted-91fd0fe8.js');
|
|
10
|
-
const productUtils = require('./product-utils-9507462c.js');
|
|
11
|
-
const stencilProductTemplateDecorators = require('./stencil-product-template-decorators-8c9cf847.js');
|
|
12
|
-
require('./dom-utils-d4790328.js');
|
|
13
|
-
require('./event-utils-9bfcf3c5.js');
|
|
14
|
-
require('./init-queue-a18aa323.js');
|
|
15
|
-
require('./initialization-lit-stencil-common-utils-24279cfa.js');
|
|
16
|
-
require('@coveo/bueno');
|
|
17
|
-
require('./object-utils-799780d3.js');
|
|
18
|
-
require('./error-ad501bd7.js');
|
|
19
|
-
require('./stencil-item-decorators-43a96f33.js');
|
|
20
|
-
|
|
21
|
-
var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
22
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
23
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
24
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
-
else
|
|
26
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
27
|
-
if (d = decorators[i])
|
|
28
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
29
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
30
|
-
};
|
|
31
|
-
const AtomicCommerceText = class {
|
|
32
|
-
constructor(hostRef) {
|
|
33
|
-
index.registerInstance(this, hostRef);
|
|
34
|
-
this.strings = {
|
|
35
|
-
value: () => this.bindings.i18n.t(this.value, {
|
|
36
|
-
count: this.count,
|
|
37
|
-
}),
|
|
38
|
-
};
|
|
39
|
-
this.error = undefined;
|
|
40
|
-
this.value = undefined;
|
|
41
|
-
this.count = undefined;
|
|
42
|
-
}
|
|
43
|
-
connectedCallback() {
|
|
44
|
-
if (!this.value) {
|
|
45
|
-
this.error = new Error('The "value" attribute must be defined.');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
render() {
|
|
49
|
-
return this.strings.value();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
__decorate$1([
|
|
53
|
-
initializationUtils.InitializeBindings()
|
|
54
|
-
], AtomicCommerceText.prototype, "bindings", void 0);
|
|
55
|
-
|
|
56
|
-
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
57
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
58
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
59
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
60
|
-
else
|
|
61
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
62
|
-
if (d = decorators[i])
|
|
63
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
64
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
65
|
-
};
|
|
66
|
-
const AtomicProductText = class {
|
|
67
|
-
constructor(hostRef) {
|
|
68
|
-
index.registerInstance(this, hostRef);
|
|
69
|
-
/**
|
|
70
|
-
* When this is set to `true`, the component attempts to highlight text based on the highlighting properties provided by the search API response.
|
|
71
|
-
* This property only works for the product excerpt and the ec_name field.
|
|
72
|
-
*/
|
|
73
|
-
this.shouldHighlight = true;
|
|
74
|
-
this.error = undefined;
|
|
75
|
-
this.field = undefined;
|
|
76
|
-
this.shouldHighlight = true;
|
|
77
|
-
this.default = undefined;
|
|
78
|
-
}
|
|
79
|
-
get shouldRenderHighlights() {
|
|
80
|
-
return this.shouldHighlight && this.isFieldSupportedForHighlighting();
|
|
81
|
-
}
|
|
82
|
-
isFieldSupportedForHighlighting() {
|
|
83
|
-
return ['ec_name', 'excerpt'].includes(this.field);
|
|
84
|
-
}
|
|
85
|
-
render() {
|
|
86
|
-
const productValueAsString = productUtils.getStringValueFromProductOrNull(this.product, this.field);
|
|
87
|
-
if (productValueAsString === null) {
|
|
88
|
-
return (index.h(stencilItemTextHighlighted.ItemTextFallback, { field: this.field, host: this.host, logger: this.bindings.engine.logger, defaultValue: this.default, item: this.product, getProperty: commerce.ProductTemplatesHelpers.getProductProperty }, index.h("atomic-commerce-text", { value: fieldUtils.getFieldValueCaption(this.field, this.default, this.bindings.i18n) })));
|
|
89
|
-
}
|
|
90
|
-
const textValue = `${productValueAsString}`;
|
|
91
|
-
const highlightKeywords = commerce.ProductTemplatesHelpers.getProductProperty(this.product, this.field === 'ec_name' ? 'nameHighlights' : 'excerptHighlights');
|
|
92
|
-
return this.shouldRenderHighlights && highlightKeywords ? (index.h(stencilItemTextHighlighted.ItemTextHighlighted, { textValue: textValue, highlightKeywords: highlightKeywords, highlightString: commerce.HighlightUtils.highlightString, onError: (error) => (this.error = error) })) : (index.h("atomic-commerce-text", { value: fieldUtils.getFieldValueCaption(this.field, textValue, this.bindings.i18n) }));
|
|
93
|
-
}
|
|
94
|
-
get host() { return index.getElement(this); }
|
|
95
|
-
};
|
|
96
|
-
__decorate([
|
|
97
|
-
initializationUtils.InitializeBindings()
|
|
98
|
-
], AtomicProductText.prototype, "bindings", void 0);
|
|
99
|
-
__decorate([
|
|
100
|
-
stencilProductTemplateDecorators.ProductContext()
|
|
101
|
-
], AtomicProductText.prototype, "product", void 0);
|
|
102
|
-
|
|
103
|
-
exports.atomic_commerce_text = AtomicCommerceText;
|
|
104
|
-
exports.atomic_product_text = AtomicProductText;
|
|
105
|
-
|
|
106
|
-
//# sourceMappingURL=atomic-commerce-text_2.cjs.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"atomic-commerce-text.atomic-product-text.entry.cjs.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAea,kBAAkB;;;QAKrB,YAAO,GAAG;YAChB,KAAK,EAAE,MACL,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE;gBAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC;SACL,CAAC;;;;;IAaK,iBAAiB;QACtB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;SAClE;KACF;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;KAC7B;;AA5B4BA;IAA5BC,sCAAkB,EAAE;oDAAoC;;;;;;;;;;;;MCO9C,iBAAiB;;;;;;;QAmBE,oBAAe,GAAG,IAAI,CAAC;;;+BAAL,IAAI;;;IAMpD,IAAY,sBAAsB;QAChC,OAAO,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,+BAA+B,EAAE,CAAC;KACvE;IAEM,+BAA+B;QACpC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACpD;IAEM,MAAM;QACX,MAAM,oBAAoB,GAAGC,4CAA+B,CAC1D,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,CACX,CAAC;QAEF,IAAI,oBAAoB,KAAK,IAAI,EAAE;YACjC,QACEC,QAACC,2CAAgB,IACf,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EACnC,YAAY,EAAE,IAAI,CAAC,OAAO,EAC1B,IAAI,EAAE,IAAI,CAAC,OAAO,EAClB,WAAW,EAAEC,gCAAuB,CAAC,kBAAkB,IAEvDF,kCACE,KAAK,EAAEG,+BAAoB,CACzB,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,OAAQ,EACb,IAAI,CAAC,QAAQ,CAAC,IAAI,CACnB,GACqB,CACP,EACnB;SACH;QAED,MAAM,SAAS,GAAG,GAAG,oBAAoB,EAAE,CAAC;QAC5C,MAAM,iBAAiB,GAAGD,gCAAuB,CAAC,kBAAkB,CAClE,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,KAAK,SAAS,GAAG,gBAAgB,GAAG,mBAAmB,CAC7B,CAAC;QAEvC,OAAO,IAAI,CAAC,sBAAsB,IAAI,iBAAiB,IACrDF,QAACI,8CAAmB,IAClB,SAAS,EAAE,SAAS,EACpB,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,EAAEC,uBAAc,CAAC,eAAe,EAC/C,OAAO,EAAE,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,GACnB,KAEvBL,kCACE,KAAK,EAAEG,+BAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAChD,CACzB,CAAC;KACH;;;AA3E4B;IAA5BL,sCAAkB,EAAE;mDAAoC;AAG/B;IAAzBQ,+CAAc,EAAE;kDAA2B;;;;;","names":["__decorate","InitializeBindings","getStringValueFromProductOrNull","h","ItemTextFallback","ProductTemplatesHelpers","getFieldValueCaption","ItemTextHighlighted","HighlightUtils","ProductContext"],"sources":["src/components/commerce/atomic-commerce-text/atomic-commerce-text.tsx","src/components/commerce/atomic-product-text/atomic-product-text.tsx"],"sourcesContent":["import {Component, Prop, State} from '@stencil/core';\nimport {\n InitializableComponent,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-interface';\n\n/**\n * @alpha\n * The `atomic-commerce-text` component leverages the I18n translation module through the atomic-commerce-interface.\n */\n@Component({\n tag: 'atomic-commerce-text',\n shadow: true,\n})\nexport class AtomicCommerceText\n implements InitializableComponent<CommerceBindings>\n{\n @InitializeBindings() public bindings!: CommerceBindings;\n\n private strings = {\n value: () =>\n this.bindings.i18n.t(this.value, {\n count: this.count,\n }),\n };\n @State() public error!: Error;\n\n /**\n * The string key value.\n */\n @Prop({reflect: true}) public value!: string;\n /**\n * The count value used for plurals.\n * @type {number}\n */\n @Prop({reflect: true}) public count?: number;\n\n public connectedCallback() {\n if (!this.value) {\n this.error = new Error('The \"value\" attribute must be defined.');\n }\n }\n\n public render() {\n return this.strings.value();\n }\n}\n","import {\n Product,\n ProductTemplatesHelpers,\n HighlightUtils,\n} from '@coveo/headless/commerce';\nimport {Component, h, Prop, Element, State} from '@stencil/core';\nimport {getFieldValueCaption} from '../../../utils/field-utils';\nimport {\n InitializableComponent,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {ItemTextFallback} from '../../common/item-text/stencil-item-text-fallback';\nimport {ItemTextHighlighted} from '../../common/item-text/stencil-item-text-highlighted';\nimport {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-interface';\nimport {getStringValueFromProductOrNull} from '../product-template-component-utils/product-utils';\nimport {ProductContext} from '../product-template-component-utils/stencil-product-template-decorators';\n\n/**\n * @alpha\n * The `atomic-product-text` component renders the value of a string product field.\n */\n@Component({\n tag: 'atomic-product-text',\n shadow: false,\n})\nexport class AtomicProductText\n implements InitializableComponent<CommerceBindings>\n{\n @InitializeBindings() public bindings!: CommerceBindings;\n @State() public error!: Error;\n\n @ProductContext() private product!: Product;\n\n @Element() private host!: HTMLElement;\n\n /**\n * The product field which the component should use.\n * This will look in the Product object first, and then in the product.additionalFields object for the fields.\n */\n @Prop({reflect: true}) public field!: string;\n /**\n * When this is set to `true`, the component attempts to highlight text based on the highlighting properties provided by the search API response.\n * This property only works for the product excerpt and the ec_name field.\n */\n @Prop({reflect: true}) public shouldHighlight = true;\n /**\n * The locale key for the text to display when the configured field has no value.\n */\n @Prop({reflect: true}) public default?: string;\n\n private get shouldRenderHighlights() {\n return this.shouldHighlight && this.isFieldSupportedForHighlighting();\n }\n\n public isFieldSupportedForHighlighting() {\n return ['ec_name', 'excerpt'].includes(this.field);\n }\n\n public render() {\n const productValueAsString = getStringValueFromProductOrNull(\n this.product,\n this.field\n );\n\n if (productValueAsString === null) {\n return (\n <ItemTextFallback\n field={this.field}\n host={this.host}\n logger={this.bindings.engine.logger}\n defaultValue={this.default}\n item={this.product}\n getProperty={ProductTemplatesHelpers.getProductProperty}\n >\n <atomic-commerce-text\n value={getFieldValueCaption(\n this.field,\n this.default!,\n this.bindings.i18n\n )}\n ></atomic-commerce-text>\n </ItemTextFallback>\n );\n }\n\n const textValue = `${productValueAsString}`;\n const highlightKeywords = ProductTemplatesHelpers.getProductProperty(\n this.product,\n this.field === 'ec_name' ? 'nameHighlights' : 'excerptHighlights'\n ) as HighlightUtils.HighlightKeyword[];\n\n return this.shouldRenderHighlights && highlightKeywords ? (\n <ItemTextHighlighted\n textValue={textValue}\n highlightKeywords={highlightKeywords}\n highlightString={HighlightUtils.highlightString}\n onError={(error) => (this.error = error)}\n ></ItemTextHighlighted>\n ) : (\n <atomic-commerce-text\n value={getFieldValueCaption(this.field, textValue, this.bindings.i18n)}\n ></atomic-commerce-text>\n );\n }\n}\n"],"version":3}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const index = require('./index-757bc886.js');
|
|
6
|
-
|
|
7
|
-
const AtomicLayoutSection = class {
|
|
8
|
-
constructor(hostRef) {
|
|
9
|
-
index.registerInstance(this, hostRef);
|
|
10
|
-
this.section = undefined;
|
|
11
|
-
this.minWidth = undefined;
|
|
12
|
-
this.maxWidth = undefined;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
exports.atomic_layout_section = AtomicLayoutSection;
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=atomic-layout-section.cjs.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"atomic-layout-section.entry.cjs.js","mappings":";;;;;;MAUa,mBAAmB;;;;;;;;;;;","names":[],"sources":["src/components/common/atomic-layout-section/atomic-layout-section.tsx"],"sourcesContent":["import {Component, Prop} from '@stencil/core';\nimport {Section} from './sections';\n\n/**\n * The `atomic-layout-section` lets you identify various sections for the related `atomic-layout` component.\n */\n@Component({\n tag: 'atomic-layout-section',\n shadow: false,\n})\nexport class AtomicLayoutSection {\n /**\n * The name of the layout section.\n */\n @Prop({reflect: true}) public section!: Section;\n /**\n * For column sections, the minimum horizontal space it should take.\n * E.g. '300px'\n */\n @Prop({reflect: true}) public minWidth?: string;\n /**\n * For column sections, the maximum horizontal space it should take.\n * E.g. '300px'\n */\n @Prop({reflect: true}) public maxWidth?: string;\n}\n"],"version":3}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"product-utils-9507462c.js","mappings":";;;;;;SAKgB,UAAU,CAAC,OAAgB,EAAE,KAAa;IACxD,MAAM,KAAK,GAAGA,gCAAuB,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACzE,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;IACD,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;IAC7C,IAAI,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;QAC/B,MAAM,IAAIC,0BAAoB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;KAC9C;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;SAEe,+BAA+B,CAC7C,OAAgB,EAChB,KAAa;IAEb,MAAM,KAAK,GAAGD,gCAAuB,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAEzE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACpD,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC;SAEe,8BAA8B,CAC5C,QAAgB,EAChB,OAAgB,EAChB,QAA0B;IAE1B,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAa;QAClD,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACjD,IAAI,QAAQ,GAAGE,0BAAc,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YAC9C,QAAQ,GAAGA,0BAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;SACxC;QAED,IAAI,CAAC,QAAQ,EAAE;YACb,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CACzB,GAAG,GAAG,6DAA6D,OAAO,CAAC,WAAW,+CAA+C,CACtI,CAAC;YACF,OAAO,EAAE,CAAC;SACX;QAED,OAAO,QAAQ,CAAC;KACjB,CAAC,CAAC;AACL;;;;;;","names":["ProductTemplatesHelpers","FieldValueIsNaNError","readFromObject"],"sources":["src/components/commerce/product-template-component-utils/product-utils.ts"],"sourcesContent":["import {readFromObject} from '@/src/utils/object-utils';\nimport {Product, ProductTemplatesHelpers} from '@coveo/headless/commerce';\nimport {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-interface';\nimport {FieldValueIsNaNError} from './error';\n\nexport function parseValue(product: Product, field: string) {\n const value = ProductTemplatesHelpers.getProductProperty(product, field);\n if (value === null) {\n return null;\n }\n const valueAsNumber = parseFloat(`${value}`);\n if (Number.isNaN(valueAsNumber)) {\n throw new FieldValueIsNaNError(field, value);\n }\n return valueAsNumber;\n}\n\nexport function getStringValueFromProductOrNull(\n product: Product,\n field: string\n) {\n const value = ProductTemplatesHelpers.getProductProperty(product, field);\n\n if (typeof value !== 'string' || value.trim() === '') {\n return null;\n }\n\n return value;\n}\n\nexport function buildStringTemplateFromProduct(\n template: string,\n product: Product,\n bindings: CommerceBindings\n) {\n return template.replace(/\\${(.*?)}/g, (value: string) => {\n const key = value.substring(2, value.length - 1);\n let newValue = readFromObject(product, key);\n if (!newValue && typeof window !== 'undefined') {\n newValue = readFromObject(window, key);\n }\n\n if (!newValue) {\n bindings.engine.logger.warn(\n `${key} used in the href template is undefined for this product: ${product.permanentid} and could not be found in the window object.`\n );\n return '';\n }\n\n return newValue;\n });\n}\n"],"version":3}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const bueno = require('@coveo/bueno');
|
|
4
|
-
const index = require('./index-757bc886.js');
|
|
5
|
-
|
|
6
|
-
function possiblyWarnOnBadFieldType(field, itemValueRaw, host, logger) {
|
|
7
|
-
if (bueno.isArray(itemValueRaw)) {
|
|
8
|
-
logger.error(`${host.nodeName.toLowerCase()} cannot be used with multi value field "${field}" with values "${itemValueRaw}".`, host);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const ItemTextFallback = ({ field, host, logger, defaultValue, item, getProperty }, children) => {
|
|
13
|
-
const raw = getProperty(item, field);
|
|
14
|
-
possiblyWarnOnBadFieldType(field, raw, host, logger);
|
|
15
|
-
if (bueno.isUndefined(defaultValue)) {
|
|
16
|
-
host.remove();
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
return index.h(index.Fragment, null, children);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function renderWithHighlights(value, highlights, highlightString) {
|
|
25
|
-
const openingDelimiter = '_openingDelimiter_';
|
|
26
|
-
const closingDelimiter = '_closingDelimiter_';
|
|
27
|
-
const highlightedValue = highlightString({
|
|
28
|
-
content: value,
|
|
29
|
-
openingDelimiter,
|
|
30
|
-
closingDelimiter,
|
|
31
|
-
highlights,
|
|
32
|
-
});
|
|
33
|
-
return highlightedValue
|
|
34
|
-
.replace(new RegExp(openingDelimiter, 'g'), '<b>')
|
|
35
|
-
.replace(new RegExp(closingDelimiter, 'g'), '</b>');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const ItemTextHighlighted = ({ highlightKeywords, highlightString, onError, textValue }) => {
|
|
39
|
-
try {
|
|
40
|
-
const highlightedValue = renderWithHighlights(textValue, highlightKeywords, highlightString);
|
|
41
|
-
// deepcode ignore ReactSetInnerHtml: This is not React code
|
|
42
|
-
return index.h(index.Host, { innerHTML: highlightedValue });
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
onError(error);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
exports.ItemTextFallback = ItemTextFallback;
|
|
50
|
-
exports.ItemTextHighlighted = ItemTextHighlighted;
|
|
51
|
-
|
|
52
|
-
//# sourceMappingURL=stencil-item-text-highlighted-91fd0fe8.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"stencil-item-text-highlighted-91fd0fe8.js","mappings":";;;;;SAEgB,0BAA0B,CACxC,KAAa,EACb,YAAqB,EACrB,IAAiB,EACjB,MAA8B;IAE9B,IAAIA,aAAO,CAAC,YAAY,CAAC,EAAE;QACzB,MAAM,CAAC,KAAK,CACV,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,2CAA2C,KAAK,kBAAkB,YAAY,IAAI,EAChH,IAAI,CACL,CAAC;KACH;AACH;;MCDa,gBAAgB,GAAG,CAC9B,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAmB,EACxE,QAAiB;IAEjB,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,0BAA0B,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAErD,IAAIC,iBAAW,CAAC,YAAY,CAAC,EAAE;QAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;KACb;SAAM;QACL,OAAOC,QAACC,cAAQ,QAAE,QAAQ,CAAY,CAAC;KACxC;AACH;;SCdgB,oBAAoB,CAClC,KAAa,EACb,UAA+B,EAC/B,eAAgC;IAEhC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;IAC9C,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;IAC9C,MAAM,gBAAgB,GAAG,eAAe,CAAC;QACvC,OAAO,EAAE,KAAK;QACd,gBAAgB;QAChB,gBAAgB;QAChB,UAAU;KACX,CAAC,CAAC;IACH,OAAO,gBAAgB;SACpB,OAAO,CAAC,IAAI,MAAM,CAAC,gBAAgB,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC;SACjD,OAAO,CAAC,IAAI,MAAM,CAAC,gBAAgB,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;AACxD;;MCda,mBAAmB,GAE5B,CAAC,EAAC,iBAAiB,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAC;IAC3D,IAAI;QACF,MAAM,gBAAgB,GAAG,oBAAoB,CAC3C,SAAS,EACT,iBAAiB,EACjB,eAAe,CAChB,CAAC;;QAGF,OAAOD,QAACE,UAAI,IAAC,SAAS,EAAE,gBAAgB,GAAS,CAAC;KACnD;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAc,CAAC,CAAC;KACzB;AACH;;;;;","names":["isArray","isUndefined","h","Fragment","Host"],"sources":["src/components/common/item-text/field-warning.ts","src/components/common/item-text/stencil-item-text-fallback.tsx","src/components/common/item-text/render-highlights.ts","src/components/common/item-text/stencil-item-text-highlighted.tsx"],"sourcesContent":["import {isArray} from '@coveo/bueno';\n\nexport function possiblyWarnOnBadFieldType(\n field: string,\n itemValueRaw: unknown,\n host: HTMLElement,\n logger: Pick<Console, 'error'>\n) {\n if (isArray(itemValueRaw)) {\n logger.error(\n `${host.nodeName.toLowerCase()} cannot be used with multi value field \"${field}\" with values \"${itemValueRaw}\".`,\n host\n );\n }\n}\n","import {isUndefined} from '@coveo/bueno';\nimport {Fragment, FunctionalComponent, VNode, h} from '@stencil/core';\nimport {possiblyWarnOnBadFieldType} from './field-warning';\n\nexport interface ItemTextProps<T> {\n logger: Pick<Console, 'error'>;\n host: HTMLElement;\n defaultValue: string | undefined;\n field: string;\n item: T;\n getProperty: (result: T, property: string) => unknown;\n}\n\nexport const ItemTextFallback = <T,>(\n {field, host, logger, defaultValue, item, getProperty}: ItemTextProps<T>,\n children: VNode[]\n): FunctionalComponent<ItemTextProps<T>> | null => {\n const raw = getProperty(item, field);\n possiblyWarnOnBadFieldType(field, raw, host, logger);\n\n if (isUndefined(defaultValue)) {\n host.remove();\n return null;\n } else {\n return <Fragment>{children}</Fragment>;\n }\n};\n","export type HighlightKeywords = {\n offset: number;\n length: number;\n};\n\nexport type HighlightString = (params: {\n content: string;\n openingDelimiter: string;\n closingDelimiter: string;\n highlights: HighlightKeywords[];\n}) => string;\n\nexport function renderWithHighlights(\n value: string,\n highlights: HighlightKeywords[],\n highlightString: HighlightString\n) {\n const openingDelimiter = '_openingDelimiter_';\n const closingDelimiter = '_closingDelimiter_';\n const highlightedValue = highlightString({\n content: value,\n openingDelimiter,\n closingDelimiter,\n highlights,\n });\n return highlightedValue\n .replace(new RegExp(openingDelimiter, 'g'), '<b>')\n .replace(new RegExp(closingDelimiter, 'g'), '</b>');\n}\n","import {FunctionalComponent, h, Host} from '@stencil/core';\nimport {\n HighlightKeywords,\n HighlightString,\n renderWithHighlights,\n} from './render-highlights';\n\nexport interface ItemTextHighlightedProps {\n textValue: string;\n highlightKeywords: HighlightKeywords[];\n onError: (error: Error) => void;\n highlightString: HighlightString;\n}\n\nexport const ItemTextHighlighted: FunctionalComponent<\n ItemTextHighlightedProps\n> = ({highlightKeywords, highlightString, onError, textValue}) => {\n try {\n const highlightedValue = renderWithHighlights(\n textValue,\n highlightKeywords,\n highlightString\n );\n\n // deepcode ignore ReactSetInnerHtml: This is not React code\n return <Host innerHTML={highlightedValue}></Host>;\n } catch (error) {\n onError(error as Error);\n }\n};\n"],"version":3}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { r as registerInstance, h, g as getElement } from './index-3f35faca.js';
|
|
2
|
-
import { I as InitializeBindings } from './initialization-utils-ff3edf9a.js';
|
|
3
|
-
import { ProductTemplatesHelpers, HighlightUtils } from '@coveo/headless/commerce';
|
|
4
|
-
import { g as getFieldValueCaption } from './field-utils-f0146383.js';
|
|
5
|
-
import { I as ItemTextFallback, a as ItemTextHighlighted } from './stencil-item-text-highlighted-0e1c6c08.js';
|
|
6
|
-
import { g as getStringValueFromProductOrNull } from './product-utils-8348689f.js';
|
|
7
|
-
import { P as ProductContext } from './stencil-product-template-decorators-0321cc1d.js';
|
|
8
|
-
import './dom-utils-f6086cd3.js';
|
|
9
|
-
import './event-utils-8de63ec3.js';
|
|
10
|
-
import './init-queue-fbe942c3.js';
|
|
11
|
-
import './initialization-lit-stencil-common-utils-9e0c895f.js';
|
|
12
|
-
import '@coveo/bueno';
|
|
13
|
-
import './object-utils-503750a4.js';
|
|
14
|
-
import './error-9520e6d0.js';
|
|
15
|
-
import './stencil-item-decorators-6c453c11.js';
|
|
16
|
-
|
|
17
|
-
var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
20
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else
|
|
22
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
23
|
-
if (d = decorators[i])
|
|
24
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
25
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
|
-
};
|
|
27
|
-
const AtomicCommerceText = class {
|
|
28
|
-
constructor(hostRef) {
|
|
29
|
-
registerInstance(this, hostRef);
|
|
30
|
-
this.strings = {
|
|
31
|
-
value: () => this.bindings.i18n.t(this.value, {
|
|
32
|
-
count: this.count,
|
|
33
|
-
}),
|
|
34
|
-
};
|
|
35
|
-
this.error = undefined;
|
|
36
|
-
this.value = undefined;
|
|
37
|
-
this.count = undefined;
|
|
38
|
-
}
|
|
39
|
-
connectedCallback() {
|
|
40
|
-
if (!this.value) {
|
|
41
|
-
this.error = new Error('The "value" attribute must be defined.');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
render() {
|
|
45
|
-
return this.strings.value();
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
__decorate$1([
|
|
49
|
-
InitializeBindings()
|
|
50
|
-
], AtomicCommerceText.prototype, "bindings", void 0);
|
|
51
|
-
|
|
52
|
-
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
53
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
54
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
55
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
56
|
-
else
|
|
57
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
58
|
-
if (d = decorators[i])
|
|
59
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
60
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
61
|
-
};
|
|
62
|
-
const AtomicProductText = class {
|
|
63
|
-
constructor(hostRef) {
|
|
64
|
-
registerInstance(this, hostRef);
|
|
65
|
-
/**
|
|
66
|
-
* When this is set to `true`, the component attempts to highlight text based on the highlighting properties provided by the search API response.
|
|
67
|
-
* This property only works for the product excerpt and the ec_name field.
|
|
68
|
-
*/
|
|
69
|
-
this.shouldHighlight = true;
|
|
70
|
-
this.error = undefined;
|
|
71
|
-
this.field = undefined;
|
|
72
|
-
this.shouldHighlight = true;
|
|
73
|
-
this.default = undefined;
|
|
74
|
-
}
|
|
75
|
-
get shouldRenderHighlights() {
|
|
76
|
-
return this.shouldHighlight && this.isFieldSupportedForHighlighting();
|
|
77
|
-
}
|
|
78
|
-
isFieldSupportedForHighlighting() {
|
|
79
|
-
return ['ec_name', 'excerpt'].includes(this.field);
|
|
80
|
-
}
|
|
81
|
-
render() {
|
|
82
|
-
const productValueAsString = getStringValueFromProductOrNull(this.product, this.field);
|
|
83
|
-
if (productValueAsString === null) {
|
|
84
|
-
return (h(ItemTextFallback, { field: this.field, host: this.host, logger: this.bindings.engine.logger, defaultValue: this.default, item: this.product, getProperty: ProductTemplatesHelpers.getProductProperty }, h("atomic-commerce-text", { value: getFieldValueCaption(this.field, this.default, this.bindings.i18n) })));
|
|
85
|
-
}
|
|
86
|
-
const textValue = `${productValueAsString}`;
|
|
87
|
-
const highlightKeywords = ProductTemplatesHelpers.getProductProperty(this.product, this.field === 'ec_name' ? 'nameHighlights' : 'excerptHighlights');
|
|
88
|
-
return this.shouldRenderHighlights && highlightKeywords ? (h(ItemTextHighlighted, { textValue: textValue, highlightKeywords: highlightKeywords, highlightString: HighlightUtils.highlightString, onError: (error) => (this.error = error) })) : (h("atomic-commerce-text", { value: getFieldValueCaption(this.field, textValue, this.bindings.i18n) }));
|
|
89
|
-
}
|
|
90
|
-
get host() { return getElement(this); }
|
|
91
|
-
};
|
|
92
|
-
__decorate([
|
|
93
|
-
InitializeBindings()
|
|
94
|
-
], AtomicProductText.prototype, "bindings", void 0);
|
|
95
|
-
__decorate([
|
|
96
|
-
ProductContext()
|
|
97
|
-
], AtomicProductText.prototype, "product", void 0);
|
|
98
|
-
|
|
99
|
-
export { AtomicCommerceText as atomic_commerce_text, AtomicProductText as atomic_product_text };
|
|
100
|
-
|
|
101
|
-
//# sourceMappingURL=atomic-commerce-text_2.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"atomic-commerce-text.atomic-product-text.entry.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;MAea,kBAAkB;;;QAKrB,YAAO,GAAG;YAChB,KAAK,EAAE,MACL,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE;gBAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC;SACL,CAAC;;;;;IAaK,iBAAiB;QACtB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;SAClE;KACF;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;KAC7B;;AA5B4BA;IAA5B,kBAAkB,EAAE;oDAAoC;;;;;;;;;;;;MCO9C,iBAAiB;;;;;;;QAmBE,oBAAe,GAAG,IAAI,CAAC;;;+BAAL,IAAI;;;IAMpD,IAAY,sBAAsB;QAChC,OAAO,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,+BAA+B,EAAE,CAAC;KACvE;IAEM,+BAA+B;QACpC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACpD;IAEM,MAAM;QACX,MAAM,oBAAoB,GAAG,+BAA+B,CAC1D,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,CACX,CAAC;QAEF,IAAI,oBAAoB,KAAK,IAAI,EAAE;YACjC,QACE,EAAC,gBAAgB,IACf,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EACnC,YAAY,EAAE,IAAI,CAAC,OAAO,EAC1B,IAAI,EAAE,IAAI,CAAC,OAAO,EAClB,WAAW,EAAE,uBAAuB,CAAC,kBAAkB,IAEvD,4BACE,KAAK,EAAE,oBAAoB,CACzB,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,OAAQ,EACb,IAAI,CAAC,QAAQ,CAAC,IAAI,CACnB,GACqB,CACP,EACnB;SACH;QAED,MAAM,SAAS,GAAG,GAAG,oBAAoB,EAAE,CAAC;QAC5C,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,kBAAkB,CAClE,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,KAAK,SAAS,GAAG,gBAAgB,GAAG,mBAAmB,CAC7B,CAAC;QAEvC,OAAO,IAAI,CAAC,sBAAsB,IAAI,iBAAiB,IACrD,EAAC,mBAAmB,IAClB,SAAS,EAAE,SAAS,EACpB,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,EAAE,cAAc,CAAC,eAAe,EAC/C,OAAO,EAAE,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,GACnB,KAEvB,4BACE,KAAK,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAChD,CACzB,CAAC;KACH;;;AA3E4B;IAA5B,kBAAkB,EAAE;mDAAoC;AAG/B;IAAzB,cAAc,EAAE;kDAA2B;;;;","names":["__decorate"],"sources":["src/components/commerce/atomic-commerce-text/atomic-commerce-text.tsx","src/components/commerce/atomic-product-text/atomic-product-text.tsx"],"sourcesContent":["import {Component, Prop, State} from '@stencil/core';\nimport {\n InitializableComponent,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-interface';\n\n/**\n * @alpha\n * The `atomic-commerce-text` component leverages the I18n translation module through the atomic-commerce-interface.\n */\n@Component({\n tag: 'atomic-commerce-text',\n shadow: true,\n})\nexport class AtomicCommerceText\n implements InitializableComponent<CommerceBindings>\n{\n @InitializeBindings() public bindings!: CommerceBindings;\n\n private strings = {\n value: () =>\n this.bindings.i18n.t(this.value, {\n count: this.count,\n }),\n };\n @State() public error!: Error;\n\n /**\n * The string key value.\n */\n @Prop({reflect: true}) public value!: string;\n /**\n * The count value used for plurals.\n * @type {number}\n */\n @Prop({reflect: true}) public count?: number;\n\n public connectedCallback() {\n if (!this.value) {\n this.error = new Error('The \"value\" attribute must be defined.');\n }\n }\n\n public render() {\n return this.strings.value();\n }\n}\n","import {\n Product,\n ProductTemplatesHelpers,\n HighlightUtils,\n} from '@coveo/headless/commerce';\nimport {Component, h, Prop, Element, State} from '@stencil/core';\nimport {getFieldValueCaption} from '../../../utils/field-utils';\nimport {\n InitializableComponent,\n InitializeBindings,\n} from '../../../utils/initialization-utils';\nimport {ItemTextFallback} from '../../common/item-text/stencil-item-text-fallback';\nimport {ItemTextHighlighted} from '../../common/item-text/stencil-item-text-highlighted';\nimport {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-interface';\nimport {getStringValueFromProductOrNull} from '../product-template-component-utils/product-utils';\nimport {ProductContext} from '../product-template-component-utils/stencil-product-template-decorators';\n\n/**\n * @alpha\n * The `atomic-product-text` component renders the value of a string product field.\n */\n@Component({\n tag: 'atomic-product-text',\n shadow: false,\n})\nexport class AtomicProductText\n implements InitializableComponent<CommerceBindings>\n{\n @InitializeBindings() public bindings!: CommerceBindings;\n @State() public error!: Error;\n\n @ProductContext() private product!: Product;\n\n @Element() private host!: HTMLElement;\n\n /**\n * The product field which the component should use.\n * This will look in the Product object first, and then in the product.additionalFields object for the fields.\n */\n @Prop({reflect: true}) public field!: string;\n /**\n * When this is set to `true`, the component attempts to highlight text based on the highlighting properties provided by the search API response.\n * This property only works for the product excerpt and the ec_name field.\n */\n @Prop({reflect: true}) public shouldHighlight = true;\n /**\n * The locale key for the text to display when the configured field has no value.\n */\n @Prop({reflect: true}) public default?: string;\n\n private get shouldRenderHighlights() {\n return this.shouldHighlight && this.isFieldSupportedForHighlighting();\n }\n\n public isFieldSupportedForHighlighting() {\n return ['ec_name', 'excerpt'].includes(this.field);\n }\n\n public render() {\n const productValueAsString = getStringValueFromProductOrNull(\n this.product,\n this.field\n );\n\n if (productValueAsString === null) {\n return (\n <ItemTextFallback\n field={this.field}\n host={this.host}\n logger={this.bindings.engine.logger}\n defaultValue={this.default}\n item={this.product}\n getProperty={ProductTemplatesHelpers.getProductProperty}\n >\n <atomic-commerce-text\n value={getFieldValueCaption(\n this.field,\n this.default!,\n this.bindings.i18n\n )}\n ></atomic-commerce-text>\n </ItemTextFallback>\n );\n }\n\n const textValue = `${productValueAsString}`;\n const highlightKeywords = ProductTemplatesHelpers.getProductProperty(\n this.product,\n this.field === 'ec_name' ? 'nameHighlights' : 'excerptHighlights'\n ) as HighlightUtils.HighlightKeyword[];\n\n return this.shouldRenderHighlights && highlightKeywords ? (\n <ItemTextHighlighted\n textValue={textValue}\n highlightKeywords={highlightKeywords}\n highlightString={HighlightUtils.highlightString}\n onError={(error) => (this.error = error)}\n ></ItemTextHighlighted>\n ) : (\n <atomic-commerce-text\n value={getFieldValueCaption(this.field, textValue, this.bindings.i18n)}\n ></atomic-commerce-text>\n );\n }\n}\n"],"version":3}
|