@coveo/atomic 3.31.2-pre.1707e4b34c → 3.31.2-pre.1c8be76f9e
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 -2
- package/dist/atomic/components/_index.js +0 -1
- package/dist/atomic/components/analytics-config.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-breadbox/atomic-commerce-breadbox.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-interface/atomic-commerce-interface.js +15 -26
- package/dist/atomic/components/components/commerce/atomic-commerce-interface/atomic-commerce-interface.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-layout/atomic-commerce-layout.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-load-more-products/atomic-commerce-load-more-products.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-product-list/atomic-commerce-product-list.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-query-summary/atomic-commerce-query-summary.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-recommendation-interface/atomic-commerce-recommendation-interface.js +16 -35
- package/dist/atomic/components/components/commerce/atomic-commerce-recommendation-interface/atomic-commerce-recommendation-interface.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-refine-modal/atomic-commerce-refine-modal.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-refine-toggle/atomic-commerce-refine-toggle.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-search-box/atomic-commerce-search-box.js +3 -0
- package/dist/atomic/components/components/commerce/atomic-commerce-search-box/atomic-commerce-search-box.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-commerce-sort-dropdown/atomic-commerce-sort-dropdown.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-product/atomic-product.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-product-children/atomic-product-children.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-product-description/atomic-product-description.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-product-excerpt/atomic-product-excerpt.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-product-field-condition/atomic-product-field-condition.js +70 -0
- package/dist/atomic/components/components/commerce/atomic-product-link/atomic-product-link.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-product-multi-value-text/atomic-product-multi-value-text.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-product-price/atomic-product-price.tw.css.js +1 -1
- package/dist/atomic/components/components/commerce/atomic-product-template/atomic-product-template.js +1 -0
- package/dist/atomic/components/components/commerce/index.js +1 -0
- package/dist/atomic/components/components/commerce/lazy-index.js +1 -0
- package/dist/atomic/components/components/common/atomic-icon/atomic-icon.tw.css.js +1 -1
- package/dist/atomic/components/components/common/facets/facet-common.tw.css.js +1 -1
- package/dist/atomic/components/components/common/facets/facet-search/facet-search.tw.css.js +1 -1
- package/dist/atomic/components/components/common/facets/facet-value-box/facet-value-box.tw.css.js +1 -1
- package/dist/atomic/components/components/common/facets/facet-value-checkbox/facet-value-checkbox.tw.css.js +1 -1
- package/dist/atomic/components/components/common/facets/facet-value-exclude/facet-value-exclude.tw.css.js +1 -1
- package/dist/atomic/components/components/common/interface/interface-controller.js +89 -0
- package/dist/atomic/components/components/common/refine-modal/refine-modal-common.tw.css.js +1 -1
- package/dist/atomic/components/global/environment.js +1 -1
- package/dist/atomic/components/global/tailwind.default.css.js +1 -1
- package/dist/atomic/components/index.js.map +1 -1
- package/dist/atomic/components/themes/accessible.css.js +1 -1
- package/dist/atomic/components/themes/coveo.css.js +1 -1
- package/dist/atomic/components/utils/coveo.tw.css.js +1 -1
- package/dist/atomic/components/utils/tailwind-utilities/aspect-square.tw.css.js +1 -1
- package/dist/atomic/components/utils/tailwind-utilities/components.tw.css.js +1 -1
- package/dist/atomic/components/utils/tailwind-utilities/hide-scrollbar.tw.css.js +1 -1
- package/dist/atomic/components/utils/tailwind-utilities/link-style.tw.css.js +1 -1
- package/dist/atomic/components/utils/tailwind-utilities/set-font-size.tw.css.js +1 -1
- package/dist/atomic/components/utils/tailwind-utilities/utilities.tw.css.js +1 -1
- package/dist/atomic/components/utils/tailwind.global.tw.css.js +1 -1
- package/dist/atomic/{p-aaef485e.entry.js → p-16aba904.entry.js} +2 -2
- package/dist/atomic/{p-c996657d.js → p-5cb01552.js} +2 -2
- package/dist/atomic/{p-0577471c.entry.js → p-9e77e09f.entry.js} +2 -2
- package/dist/atomic/{p-222d9586.entry.js → p-b573855a.entry.js} +2 -2
- package/dist/cjs/_loader.cjs.js +1 -1
- package/dist/cjs/{analytics-config-eb93e5ee.js → analytics-config-aabaf235.js} +2 -2
- package/dist/cjs/{analytics-config-eb93e5ee.js.map → analytics-config-aabaf235.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/atomic-search-interface.cjs.entry.js +1 -1
- package/dist/cjs/atomic.cjs.js +1 -1
- package/dist/cjs/index-757bc886.js +0 -4
- package/dist/cjs/version.cjs.js +2 -2
- package/dist/esm/_loader.js +1 -1
- package/dist/esm/{analytics-config-11a6a380.js → analytics-config-8adc1641.js} +2 -2
- package/dist/esm/{analytics-config-11a6a380.js.map → analytics-config-8adc1641.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/atomic-search-interface.entry.js +1 -1
- package/dist/esm/atomic.js +1 -1
- package/dist/esm/index-3f35faca.js +0 -4
- package/dist/esm/version.js +2 -2
- package/dist/types/components/commerce/atomic-commerce-interface/atomic-commerce-interface.d.ts +3 -4
- package/dist/types/components/commerce/atomic-commerce-recommendation-interface/atomic-commerce-recommendation-interface.d.ts +5 -6
- package/dist/types/components/commerce/atomic-commerce-search-box/atomic-commerce-search-box.d.ts +3 -0
- package/dist/types/components/commerce/atomic-product-field-condition/atomic-product-field-condition.d.ts +24 -13
- package/dist/types/components/commerce/atomic-product-template/atomic-product-template.d.ts +1 -0
- package/dist/types/components/commerce/index.d.ts +1 -0
- package/dist/types/components/common/interface/i18n.d.ts +1 -1
- package/dist/types/components/common/interface/{interface-common.d.ts → interface-controller.d.ts} +14 -11
- package/dist/types/components.d.ts +0 -69
- package/docs/atomic-docs.json +31 -164
- package/package.json +3 -3
- package/dist/atomic/components/atomic-product-field-condition.d.ts +0 -11
- package/dist/atomic/components/atomic-product-field-condition.js +0 -131
- package/dist/atomic/components/atomic-product-field-condition.js.map +0 -1
- package/dist/atomic/components/components/common/interface/interface-common.js +0 -95
- package/dist/atomic/p-a0b3c6e2.entry.js +0 -2
- package/dist/atomic/p-a0b3c6e2.entry.js.map +0 -1
- package/dist/cjs/atomic-product-field-condition.cjs.entry.js +0 -119
- package/dist/cjs/atomic-product-field-condition.cjs.entry.js.map +0 -1
- package/dist/esm/atomic-product-field-condition.entry.js +0 -115
- package/dist/esm/atomic-product-field-condition.entry.js.map +0 -1
- /package/dist/atomic/{p-aaef485e.entry.js.map → p-16aba904.entry.js.map} +0 -0
- /package/dist/atomic/{p-c996657d.js.map → p-5cb01552.js.map} +0 -0
- /package/dist/atomic/{p-0577471c.entry.js.map → p-9e77e09f.entry.js.map} +0 -0
- /package/dist/atomic/{p-222d9586.entry.js.map → p-b573855a.entry.js.map} +0 -0
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import "../atomic-component-error/atomic-component-error.js";
|
|
2
|
-
import Backend from 'i18next-http-backend';
|
|
3
|
-
import { html } from 'lit';
|
|
4
|
-
import { i18nBackendOptions, i18nTranslationNamespace, init18n, } from "./i18n.js";
|
|
5
|
-
import { setCoveoGlobal } from "../../../global/environment.js";
|
|
6
|
-
import { loadDayjsLocale } from "../../../utils/dayjs-locales.js";
|
|
7
|
-
export const mismatchedInterfaceAndEnginePropError = (interfaceKind, configurationName) => `A ${configurationName} is configured on the ${interfaceKind} interface element, but the ${interfaceKind} interface was initialized with an engine. You should only configure the ${configurationName} in the target engine.`;
|
|
8
|
-
export class CommonAtomicInterfaceHelper {
|
|
9
|
-
constructor(atomicInterface, globalVariableName) {
|
|
10
|
-
this.atomicInterface = atomicInterface;
|
|
11
|
-
this.hangingComponentsInitialization = [];
|
|
12
|
-
setCoveoGlobal(globalVariableName);
|
|
13
|
-
if ('connectedCallback' in atomicInterface && 'render' in atomicInterface) {
|
|
14
|
-
const { connectedCallback: originalConnectedCallback, render: originalRender, } = atomicInterface;
|
|
15
|
-
atomicInterface.connectedCallback = () => {
|
|
16
|
-
this.i18nPromise = init18n(atomicInterface);
|
|
17
|
-
if (typeof originalConnectedCallback === 'function') {
|
|
18
|
-
return originalConnectedCallback.call(atomicInterface);
|
|
19
|
-
}
|
|
20
|
-
return;
|
|
21
|
-
};
|
|
22
|
-
atomicInterface.render = () => {
|
|
23
|
-
if (atomicInterface.error) {
|
|
24
|
-
return html `<atomic-component-error
|
|
25
|
-
.element=${atomicInterface}
|
|
26
|
-
.error=${atomicInterface.error}
|
|
27
|
-
></atomic-component-error>`;
|
|
28
|
-
}
|
|
29
|
-
return typeof originalRender === 'function'
|
|
30
|
-
? originalRender.call(atomicInterface)
|
|
31
|
-
: null;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this.i18nPromise = init18n(atomicInterface);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
onComponentInitializing(event) {
|
|
39
|
-
event.preventDefault();
|
|
40
|
-
event.stopPropagation();
|
|
41
|
-
if (this.atomicInterface.engine) {
|
|
42
|
-
event.detail(this.atomicInterface.bindings);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
this.hangingComponentsInitialization.push(event);
|
|
46
|
-
}
|
|
47
|
-
async onInitialization(initEngine) {
|
|
48
|
-
if (this.atomicInterface.engine) {
|
|
49
|
-
this.atomicInterface.engine.logger.warn(`The ${this.interfaceTagname} component "initialize" has already been called.`, this.atomicInterface);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
this.atomicInterface.updateIconAssetsPath();
|
|
53
|
-
initEngine();
|
|
54
|
-
if (this.atomicInterface.registerFieldsToInclude) {
|
|
55
|
-
this.atomicInterface.registerFieldsToInclude();
|
|
56
|
-
}
|
|
57
|
-
loadDayjsLocale(this.atomicInterface.language || 'en');
|
|
58
|
-
await this.i18nPromise;
|
|
59
|
-
this.initComponents();
|
|
60
|
-
}
|
|
61
|
-
onAnalyticsChange() {
|
|
62
|
-
const { engine, analytics } = this.atomicInterface;
|
|
63
|
-
if (!this.engineIsCreated(engine)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (!analytics) {
|
|
67
|
-
engine.disableAnalytics();
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
engine.enableAnalytics();
|
|
71
|
-
}
|
|
72
|
-
onLanguageChange(newLanguage) {
|
|
73
|
-
const language = newLanguage ?? this.atomicInterface.language;
|
|
74
|
-
const languageWithFallback = language ?? 'en';
|
|
75
|
-
const { i18n } = this.atomicInterface;
|
|
76
|
-
loadDayjsLocale(languageWithFallback);
|
|
77
|
-
new Backend(i18n.services, i18nBackendOptions(this.atomicInterface)).read(languageWithFallback.split('-')[0], i18nTranslationNamespace, (_, data) => {
|
|
78
|
-
i18n.addResourceBundle(languageWithFallback.split('-')[0], i18nTranslationNamespace, data, true, false);
|
|
79
|
-
i18n.changeLanguage(language);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
engineIsCreated(engine) {
|
|
83
|
-
if (!engine) {
|
|
84
|
-
console.error(`You have to call "initialize" on the ${this.interfaceTagname} component before modifying the props or calling other public methods.`, this.atomicInterface);
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
get interfaceTagname() {
|
|
90
|
-
return this.atomicInterface.tagName.toLowerCase();
|
|
91
|
-
}
|
|
92
|
-
initComponents() {
|
|
93
|
-
this.hangingComponentsInitialization.forEach((event) => event.detail(this.atomicInterface.bindings));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as t,h as o,g as i}from"./p-dc3df5ce.js";import{M as e}from"./p-86428057.js";import"./p-f284897c.js";import{ProductTemplatesHelpers as s}from"@coveo/headless/commerce";import{P as n}from"./p-fe23d27e.js";import"@coveo/bueno";import"./p-bc96b8f6.js";import"./p-0462f723.js";import"./p-3dc06261.js";import"./p-c9074946.js";import"./p-1580513b.js";function r(t,o){const i=new Set;for(const e of t){if(o.has(e)){i.add(e)}}return i}function c(t,o){const i=[];for(const e in t){if(o[e]){const i=new Set(o[e]);const s=new Set(t[e]);const n=r(i,s);if(n.size>0){console.error(`Conflicting match conditions for field ${e}, the template will be ignored.`,n);return[()=>false]}}i.push(s.fieldMustMatch(e,t[e]))}for(const t in o){i.push(s.fieldMustNotMatch(t,o[t]))}return i}function f(t,o){const i=[];if(t){const o=t.split(",");i.push(s.fieldsMustBeDefined(o))}if(o){const t=o.split(",");i.push(s.fieldsMustNotBeDefined(t))}return i}var p=undefined&&undefined.__decorate||function(t,o,i,e){var s=arguments.length,n=s<3?o:e===null?e=Object.getOwnPropertyDescriptor(o,i):e,r;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")n=Reflect.decorate(t,o,i,e);else for(var c=t.length-1;c>=0;c--)if(r=t[c])n=(s<3?r(n):s>3?r(o,i,n):r(o,i))||n;return s>3&&n&&Object.defineProperty(o,i,n),n};const u=class{constructor(o){t(this,o);this.mustMatch={};this.mustNotMatch={};this.conditions=[];this.shouldBeRemoved=false;this.ifDefined=undefined;this.ifNotDefined=undefined;this.mustMatch={};this.mustNotMatch={}}componentWillLoad(){this.conditions=f(this.ifDefined,this.ifNotDefined);this.conditions.push(...c(this.mustMatch,this.mustNotMatch))}render(){if(!this.conditions.every((t=>t(this.product)))){this.shouldBeRemoved=true;return""}return o("slot",null)}componentDidLoad(){this.shouldBeRemoved&&this.host.remove()}get host(){return i(this)}};p([e({splitValues:true})],u.prototype,"mustMatch",void 0);p([e({splitValues:true})],u.prototype,"mustNotMatch",void 0);p([n()],u.prototype,"product",void 0);export{u as atomic_product_field_condition};
|
|
2
|
-
//# sourceMappingURL=p-a0b3c6e2.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["intersection","setA","setB","result","Set","elem","has","add","makeMatchConditions","mustMatch","mustNotMatch","conditions","field","mustNotMatchValues","mustMatchValues","commonValues","size","console","error","push","ProductTemplatesHelpers","fieldMustMatch","fieldMustNotMatch","makeDefinedConditions","ifDefined","ifNotDefined","fieldNames","split","fieldsMustBeDefined","fieldsMustNotBeDefined","AtomicProductFieldCondition","this","shouldBeRemoved","componentWillLoad","render","every","condition","product","h","componentDidLoad","host","remove","__decorate","MapProp","splitValues","ProductContext"],"sources":["src/utils/set.ts","src/components/common/product-template/product-template-common.ts","src/components/common/product-template/stencil-product-template-common.tsx","src/components/commerce/atomic-product-field-condition/atomic-product-field-condition.tsx"],"sourcesContent":["// TODO: Replace by Set.prototype.intersection in July 2025\nexport function intersection<T>(setA: Set<T>, setB: Set<T>): Set<T> {\n const result = new Set<T>();\n for (const elem of setA) {\n if (setB.has(elem)) {\n result.add(elem);\n }\n }\n return result;\n}\n","import {\n type ProductTemplateCondition,\n ProductTemplatesHelpers,\n} from '@coveo/headless/commerce';\nimport {intersection} from '../../../utils/set';\nimport {isElementNode, isVisualNode} from '../../../utils/utils';\nimport {tableElementTagName} from '../../search/atomic-table-result/table-element-utils';\nimport {isResultSectionNode} from '../layout/sections';\n\ntype TemplateNodeType =\n | 'section'\n | 'metadata'\n | 'table-column-definition'\n | 'other';\n\nexport function getTemplateNodeType(node: Node): TemplateNodeType {\n if (isResultSectionNode(node)) {\n return 'section';\n }\n if (!isVisualNode(node)) {\n return 'metadata';\n }\n if (\n isElementNode(node) &&\n node.tagName.toLowerCase() === tableElementTagName\n ) {\n return 'table-column-definition';\n }\n return 'other';\n}\n\nexport function makeMatchConditions(\n mustMatch: Record<string, string[]>,\n mustNotMatch: Record<string, string[]>\n): ProductTemplateCondition[] {\n const conditions: ProductTemplateCondition[] = [];\n for (const field in mustMatch) {\n if (mustNotMatch[field]) {\n const mustNotMatchValues = new Set(mustNotMatch[field]);\n const mustMatchValues = new Set(mustMatch[field]);\n const commonValues = intersection(mustNotMatchValues, mustMatchValues);\n if (commonValues.size > 0) {\n console.error(\n `Conflicting match conditions for field ${field}, the template will be ignored.`,\n commonValues\n );\n return [() => false];\n }\n }\n conditions.push(\n ProductTemplatesHelpers.fieldMustMatch(field, mustMatch[field])\n );\n }\n\n for (const field in mustNotMatch) {\n conditions.push(\n ProductTemplatesHelpers.fieldMustNotMatch(field, mustNotMatch[field])\n );\n }\n return conditions;\n}\n\nexport function makeDefinedConditions(\n ifDefined?: string,\n ifNotDefined?: string\n): ProductTemplateCondition[] {\n const conditions: ProductTemplateCondition[] = [];\n if (ifDefined) {\n const fieldNames = ifDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));\n }\n\n if (ifNotDefined) {\n const fieldNames = ifNotDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));\n }\n return conditions;\n}\n","import {aggregate, isElementNode, isVisualNode} from '@/src/utils/utils';\nimport {\n ProductTemplate,\n ProductTemplateCondition,\n ProductTemplatesHelpers,\n} from '@coveo/headless/commerce';\nimport {h} from '@stencil/core';\nimport {tableElementTagName} from '../../search/atomic-table-result/table-element-utils';\nimport {ItemTarget} from '../layout/display-options';\nimport {isResultSectionNode} from '../layout/sections';\n\nexport {makeMatchConditions} from './product-template-common';\n\nexport type TemplateContent = DocumentFragment;\n\ninterface ProductTemplateCommonProps {\n allowEmpty?: boolean;\n host: HTMLDivElement;\n validParents: string[];\n setError: (error: Error) => void;\n}\n\ntype TemplateNodeType =\n | 'section'\n | 'metadata'\n | 'table-column-definition'\n | 'other';\n\nexport function getTemplateNodeType(node: Node): TemplateNodeType {\n if (isResultSectionNode(node)) {\n return 'section';\n }\n if (!isVisualNode(node)) {\n return 'metadata';\n }\n if (\n isElementNode(node) &&\n node.tagName.toLowerCase() === tableElementTagName\n ) {\n return 'table-column-definition';\n }\n return 'other';\n}\n\nfunction groupNodesByType(nodes: NodeList) {\n return aggregate(Array.from(nodes), (node) => getTemplateNodeType(node));\n}\n\n/**\n * @deprecated Use `ProductTemplateController` Reactive controller instead.\n */\nexport class ProductTemplateCommon {\n private host: HTMLDivElement;\n public matchConditions: ProductTemplateCondition[] = [];\n private gridCellLinkTarget?: ItemTarget;\n\n constructor({\n host,\n setError,\n validParents,\n allowEmpty = false,\n }: ProductTemplateCommonProps) {\n this.host = host;\n this.validateTemplate(host, setError, validParents, allowEmpty);\n }\n\n validateTemplate(\n host: HTMLDivElement,\n setError: (error: Error) => void,\n validParents: string[],\n allowEmpty = true\n ) {\n const hasValidParent = validParents\n .map((p) => p.toUpperCase())\n .includes(host.parentElement?.nodeName || '');\n const tagName = host.nodeName.toLowerCase();\n\n if (!hasValidParent) {\n setError(\n new Error(\n `The \"${tagName}\" component has to be the child of one of the following: ${validParents\n .map((p) => `\"${p.toLowerCase()}\"`)\n .join(', ')}.`\n )\n );\n return;\n }\n\n if (\n host.parentElement?.attributes.getNamedItem('display')?.value === 'grid'\n ) {\n this.gridCellLinkTarget = host.parentElement?.attributes.getNamedItem(\n 'grid-cell-link-target'\n )?.value as ItemTarget;\n }\n\n const template = host.querySelector('template');\n if (!template) {\n setError(\n new Error(\n `The \"${tagName}\" component must contain a \"template\" element as a child.`\n )\n );\n return;\n }\n\n if (!allowEmpty && !template.innerHTML.trim()) {\n setError(\n new Error(`The \"template\" tag inside \"${tagName}\" cannot be empty.`)\n );\n return;\n }\n\n if (template.content.querySelector('script')) {\n console.warn(\n 'Any \"script\" tags defined inside of \"template\" elements are not supported and will not be executed when the products are rendered.',\n host\n );\n }\n\n const {section: sectionNodes, other: otherNodes} = groupNodesByType(\n template.content.childNodes\n );\n if (sectionNodes?.length && otherNodes?.length) {\n console.warn(\n 'Product templates should only contain section elements or non-section elements. Future updates could unpredictably affect this product template.',\n host,\n {sectionNodes, otherNodes}\n );\n }\n }\n\n getTemplate(\n conditions: ProductTemplateCondition[],\n error: Error\n ): ProductTemplate<TemplateContent> | null {\n if (error) {\n return null;\n }\n\n return {\n conditions: conditions.concat(this.matchConditions),\n content: getTemplateElement(this.host).content!,\n linkContent: this.getLinkTemplateElement(this.host).content!,\n priority: 1,\n };\n }\n\n renderIfError(error: Error) {\n if (error) {\n return (\n <atomic-component-error\n element={this.host}\n error={error}\n ></atomic-component-error>\n );\n }\n }\n getDefaultLinkTemplateElement() {\n const linkTemplate = document.createElement('template');\n linkTemplate.innerHTML = `<atomic-product-link>${this.gridCellLinkTarget ? `<a slot=\"attributes\" target=\"${this.gridCellLinkTarget}\"></a>` : ''}</atomic-product-link>`;\n return linkTemplate;\n }\n\n getLinkTemplateElement(host: HTMLElement) {\n return (\n host.querySelector<HTMLTemplateElement>('template[slot=\"link\"]') ??\n this.getDefaultLinkTemplateElement()\n );\n }\n}\n\nfunction getTemplateElement(host: HTMLElement) {\n return host.querySelector<HTMLTemplateElement>('template:not([slot])')!;\n}\n\nexport function makeDefinedConditions(\n ifDefined?: string,\n ifNotDefined?: string\n): ProductTemplateCondition[] {\n const conditions: ProductTemplateCondition[] = [];\n if (ifDefined) {\n const fieldNames = ifDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));\n }\n\n if (ifNotDefined) {\n const fieldNames = ifNotDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));\n }\n return conditions;\n}\n","import {Product, ProductTemplateCondition} from '@coveo/headless/commerce';\nimport {Component, Prop, h, Element} from '@stencil/core';\nimport {MapProp} from '../../../utils/props-utils';\nimport {\n makeDefinedConditions,\n makeMatchConditions,\n} from '../../common/product-template/stencil-product-template-common';\nimport {ProductContext} from '../product-template-component-utils/stencil-product-template-decorators';\n\n/**\n * The `atomic-product-field-condition` component takes a list of conditions that, if fulfilled, apply the template in which it's defined.\n * The condition properties can be based on any top-level product property of the `product` object, not restricted to fields (e.g., `ec_name`).\n * @alpha\n */\n@Component({\n tag: 'atomic-product-field-condition',\n shadow: false,\n})\nexport class AtomicProductFieldCondition {\n @Element() host!: HTMLElement;\n\n /**\n * Verifies whether the specified fields are defined.\n */\n @Prop({reflect: true}) ifDefined?: string;\n /**\n * Verifies whether the specified fields are not defined.\n */\n @Prop({reflect: true}) ifNotDefined?: string;\n\n /**\n * Verifies whether the specified fields match the specified values.\n * @type {Record<string, string[]>}\n */\n @Prop() @MapProp({splitValues: true}) mustMatch: Record<string, string[]> =\n {};\n\n /**\n * Verifies whether the specified fields do not match the specified values.\n * @type {Record<string, string[]>}\n */\n @Prop() @MapProp({splitValues: true}) mustNotMatch: Record<string, string[]> =\n {};\n\n private conditions: ProductTemplateCondition[] = [];\n private shouldBeRemoved = false;\n\n @ProductContext() private product!: Product;\n\n public componentWillLoad() {\n this.conditions = makeDefinedConditions(this.ifDefined, this.ifNotDefined);\n this.conditions.push(\n ...makeMatchConditions(this.mustMatch, this.mustNotMatch)\n );\n }\n\n public render() {\n if (!this.conditions.every((condition) => condition(this.product))) {\n this.shouldBeRemoved = true;\n return '';\n }\n\n return <slot />;\n }\n\n public componentDidLoad() {\n this.shouldBeRemoved && this.host.remove();\n }\n}\n"],"mappings":"2WACgBA,EAAgBC,EAAcC,GAC5C,MAAMC,EAAS,IAAIC,IACnB,IAAK,MAAMC,KAAQJ,EAAM,CACvB,GAAIC,EAAKI,IAAID,GAAO,CAClBF,EAAOI,IAAIF,E,EAGf,OAAOF,CACT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A7BC,EAAQ,CAACC,YAAa,Q,gCAOOF,EAAA,CAA7BC,EAAQ,CAACC,YAAa,Q,mCAMLF,EAAA,CAAzBG,K","ignoreList":[]}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const index = require('./index-757bc886.js');
|
|
6
|
-
const propsUtils = require('./props-utils-1e4ba1b0.js');
|
|
7
|
-
require('./purify-85b542e2.js');
|
|
8
|
-
const commerce = require('@coveo/headless/commerce');
|
|
9
|
-
const stencilProductTemplateDecorators = require('./stencil-product-template-decorators-1edee0eb.js');
|
|
10
|
-
require('@coveo/bueno');
|
|
11
|
-
require('./utils-7153ae6b.js');
|
|
12
|
-
require('./_commonjsHelpers-b3309d7b.js');
|
|
13
|
-
require('./stencil-item-decorators-43a96f33.js');
|
|
14
|
-
require('./dom-utils-d4790328.js');
|
|
15
|
-
require('./event-utils-9bfcf3c5.js');
|
|
16
|
-
|
|
17
|
-
// TODO: Replace by Set.prototype.intersection in July 2025
|
|
18
|
-
function intersection(setA, setB) {
|
|
19
|
-
const result = new Set();
|
|
20
|
-
for (const elem of setA) {
|
|
21
|
-
if (setB.has(elem)) {
|
|
22
|
-
result.add(elem);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function makeMatchConditions(mustMatch, mustNotMatch) {
|
|
29
|
-
const conditions = [];
|
|
30
|
-
for (const field in mustMatch) {
|
|
31
|
-
if (mustNotMatch[field]) {
|
|
32
|
-
const mustNotMatchValues = new Set(mustNotMatch[field]);
|
|
33
|
-
const mustMatchValues = new Set(mustMatch[field]);
|
|
34
|
-
const commonValues = intersection(mustNotMatchValues, mustMatchValues);
|
|
35
|
-
if (commonValues.size > 0) {
|
|
36
|
-
console.error(`Conflicting match conditions for field ${field}, the template will be ignored.`, commonValues);
|
|
37
|
-
return [() => false];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
conditions.push(commerce.ProductTemplatesHelpers.fieldMustMatch(field, mustMatch[field]));
|
|
41
|
-
}
|
|
42
|
-
for (const field in mustNotMatch) {
|
|
43
|
-
conditions.push(commerce.ProductTemplatesHelpers.fieldMustNotMatch(field, mustNotMatch[field]));
|
|
44
|
-
}
|
|
45
|
-
return conditions;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function makeDefinedConditions(ifDefined, ifNotDefined) {
|
|
49
|
-
const conditions = [];
|
|
50
|
-
if (ifDefined) {
|
|
51
|
-
const fieldNames = ifDefined.split(',');
|
|
52
|
-
conditions.push(commerce.ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));
|
|
53
|
-
}
|
|
54
|
-
if (ifNotDefined) {
|
|
55
|
-
const fieldNames = ifNotDefined.split(',');
|
|
56
|
-
conditions.push(commerce.ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));
|
|
57
|
-
}
|
|
58
|
-
return conditions;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
62
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
63
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
64
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
65
|
-
else
|
|
66
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
67
|
-
if (d = decorators[i])
|
|
68
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
69
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
70
|
-
};
|
|
71
|
-
const AtomicProductFieldCondition = class {
|
|
72
|
-
constructor(hostRef) {
|
|
73
|
-
index.registerInstance(this, hostRef);
|
|
74
|
-
/**
|
|
75
|
-
* Verifies whether the specified fields match the specified values.
|
|
76
|
-
* @type {Record<string, string[]>}
|
|
77
|
-
*/
|
|
78
|
-
this.mustMatch = {};
|
|
79
|
-
/**
|
|
80
|
-
* Verifies whether the specified fields do not match the specified values.
|
|
81
|
-
* @type {Record<string, string[]>}
|
|
82
|
-
*/
|
|
83
|
-
this.mustNotMatch = {};
|
|
84
|
-
this.conditions = [];
|
|
85
|
-
this.shouldBeRemoved = false;
|
|
86
|
-
this.ifDefined = undefined;
|
|
87
|
-
this.ifNotDefined = undefined;
|
|
88
|
-
this.mustMatch = {};
|
|
89
|
-
this.mustNotMatch = {};
|
|
90
|
-
}
|
|
91
|
-
componentWillLoad() {
|
|
92
|
-
this.conditions = makeDefinedConditions(this.ifDefined, this.ifNotDefined);
|
|
93
|
-
this.conditions.push(...makeMatchConditions(this.mustMatch, this.mustNotMatch));
|
|
94
|
-
}
|
|
95
|
-
render() {
|
|
96
|
-
if (!this.conditions.every((condition) => condition(this.product))) {
|
|
97
|
-
this.shouldBeRemoved = true;
|
|
98
|
-
return '';
|
|
99
|
-
}
|
|
100
|
-
return index.h("slot", null);
|
|
101
|
-
}
|
|
102
|
-
componentDidLoad() {
|
|
103
|
-
this.shouldBeRemoved && this.host.remove();
|
|
104
|
-
}
|
|
105
|
-
get host() { return index.getElement(this); }
|
|
106
|
-
};
|
|
107
|
-
__decorate([
|
|
108
|
-
propsUtils.MapProp({ splitValues: true })
|
|
109
|
-
], AtomicProductFieldCondition.prototype, "mustMatch", void 0);
|
|
110
|
-
__decorate([
|
|
111
|
-
propsUtils.MapProp({ splitValues: true })
|
|
112
|
-
], AtomicProductFieldCondition.prototype, "mustNotMatch", void 0);
|
|
113
|
-
__decorate([
|
|
114
|
-
stencilProductTemplateDecorators.ProductContext()
|
|
115
|
-
], AtomicProductFieldCondition.prototype, "product", void 0);
|
|
116
|
-
|
|
117
|
-
exports.atomic_product_field_condition = AtomicProductFieldCondition;
|
|
118
|
-
|
|
119
|
-
//# sourceMappingURL=atomic-product-field-condition.cjs.entry.js.map
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M,EAAE,CAAC;KAC5C;;;AAjCqC;IAA7BC,kBAAO,CAAC,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;8DAChC;AAMiC;IAA7BA,kBAAO,CAAC,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;iEAChC;AAKqB;IAAzBC,+CAAc,EAAE;4DAA2B;;;;","names":["ProductTemplatesHelpers","h","MapProp","ProductContext"],"sources":["src/utils/set.ts","src/components/common/product-template/product-template-common.ts","src/components/common/product-template/stencil-product-template-common.tsx","src/components/commerce/atomic-product-field-condition/atomic-product-field-condition.tsx"],"sourcesContent":["// TODO: Replace by Set.prototype.intersection in July 2025\nexport function intersection<T>(setA: Set<T>, setB: Set<T>): Set<T> {\n const result = new Set<T>();\n for (const elem of setA) {\n if (setB.has(elem)) {\n result.add(elem);\n }\n }\n return result;\n}\n","import {\n type ProductTemplateCondition,\n ProductTemplatesHelpers,\n} from '@coveo/headless/commerce';\nimport {intersection} from '../../../utils/set';\nimport {isElementNode, isVisualNode} from '../../../utils/utils';\nimport {tableElementTagName} from '../../search/atomic-table-result/table-element-utils';\nimport {isResultSectionNode} from '../layout/sections';\n\ntype TemplateNodeType =\n | 'section'\n | 'metadata'\n | 'table-column-definition'\n | 'other';\n\nexport function getTemplateNodeType(node: Node): TemplateNodeType {\n if (isResultSectionNode(node)) {\n return 'section';\n }\n if (!isVisualNode(node)) {\n return 'metadata';\n }\n if (\n isElementNode(node) &&\n node.tagName.toLowerCase() === tableElementTagName\n ) {\n return 'table-column-definition';\n }\n return 'other';\n}\n\nexport function makeMatchConditions(\n mustMatch: Record<string, string[]>,\n mustNotMatch: Record<string, string[]>\n): ProductTemplateCondition[] {\n const conditions: ProductTemplateCondition[] = [];\n for (const field in mustMatch) {\n if (mustNotMatch[field]) {\n const mustNotMatchValues = new Set(mustNotMatch[field]);\n const mustMatchValues = new Set(mustMatch[field]);\n const commonValues = intersection(mustNotMatchValues, mustMatchValues);\n if (commonValues.size > 0) {\n console.error(\n `Conflicting match conditions for field ${field}, the template will be ignored.`,\n commonValues\n );\n return [() => false];\n }\n }\n conditions.push(\n ProductTemplatesHelpers.fieldMustMatch(field, mustMatch[field])\n );\n }\n\n for (const field in mustNotMatch) {\n conditions.push(\n ProductTemplatesHelpers.fieldMustNotMatch(field, mustNotMatch[field])\n );\n }\n return conditions;\n}\n\nexport function makeDefinedConditions(\n ifDefined?: string,\n ifNotDefined?: string\n): ProductTemplateCondition[] {\n const conditions: ProductTemplateCondition[] = [];\n if (ifDefined) {\n const fieldNames = ifDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));\n }\n\n if (ifNotDefined) {\n const fieldNames = ifNotDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));\n }\n return conditions;\n}\n","import {aggregate, isElementNode, isVisualNode} from '@/src/utils/utils';\nimport {\n ProductTemplate,\n ProductTemplateCondition,\n ProductTemplatesHelpers,\n} from '@coveo/headless/commerce';\nimport {h} from '@stencil/core';\nimport {tableElementTagName} from '../../search/atomic-table-result/table-element-utils';\nimport {ItemTarget} from '../layout/display-options';\nimport {isResultSectionNode} from '../layout/sections';\n\nexport {makeMatchConditions} from './product-template-common';\n\nexport type TemplateContent = DocumentFragment;\n\ninterface ProductTemplateCommonProps {\n allowEmpty?: boolean;\n host: HTMLDivElement;\n validParents: string[];\n setError: (error: Error) => void;\n}\n\ntype TemplateNodeType =\n | 'section'\n | 'metadata'\n | 'table-column-definition'\n | 'other';\n\nexport function getTemplateNodeType(node: Node): TemplateNodeType {\n if (isResultSectionNode(node)) {\n return 'section';\n }\n if (!isVisualNode(node)) {\n return 'metadata';\n }\n if (\n isElementNode(node) &&\n node.tagName.toLowerCase() === tableElementTagName\n ) {\n return 'table-column-definition';\n }\n return 'other';\n}\n\nfunction groupNodesByType(nodes: NodeList) {\n return aggregate(Array.from(nodes), (node) => getTemplateNodeType(node));\n}\n\n/**\n * @deprecated Use `ProductTemplateController` Reactive controller instead.\n */\nexport class ProductTemplateCommon {\n private host: HTMLDivElement;\n public matchConditions: ProductTemplateCondition[] = [];\n private gridCellLinkTarget?: ItemTarget;\n\n constructor({\n host,\n setError,\n validParents,\n allowEmpty = false,\n }: ProductTemplateCommonProps) {\n this.host = host;\n this.validateTemplate(host, setError, validParents, allowEmpty);\n }\n\n validateTemplate(\n host: HTMLDivElement,\n setError: (error: Error) => void,\n validParents: string[],\n allowEmpty = true\n ) {\n const hasValidParent = validParents\n .map((p) => p.toUpperCase())\n .includes(host.parentElement?.nodeName || '');\n const tagName = host.nodeName.toLowerCase();\n\n if (!hasValidParent) {\n setError(\n new Error(\n `The \"${tagName}\" component has to be the child of one of the following: ${validParents\n .map((p) => `\"${p.toLowerCase()}\"`)\n .join(', ')}.`\n )\n );\n return;\n }\n\n if (\n host.parentElement?.attributes.getNamedItem('display')?.value === 'grid'\n ) {\n this.gridCellLinkTarget = host.parentElement?.attributes.getNamedItem(\n 'grid-cell-link-target'\n )?.value as ItemTarget;\n }\n\n const template = host.querySelector('template');\n if (!template) {\n setError(\n new Error(\n `The \"${tagName}\" component must contain a \"template\" element as a child.`\n )\n );\n return;\n }\n\n if (!allowEmpty && !template.innerHTML.trim()) {\n setError(\n new Error(`The \"template\" tag inside \"${tagName}\" cannot be empty.`)\n );\n return;\n }\n\n if (template.content.querySelector('script')) {\n console.warn(\n 'Any \"script\" tags defined inside of \"template\" elements are not supported and will not be executed when the products are rendered.',\n host\n );\n }\n\n const {section: sectionNodes, other: otherNodes} = groupNodesByType(\n template.content.childNodes\n );\n if (sectionNodes?.length && otherNodes?.length) {\n console.warn(\n 'Product templates should only contain section elements or non-section elements. Future updates could unpredictably affect this product template.',\n host,\n {sectionNodes, otherNodes}\n );\n }\n }\n\n getTemplate(\n conditions: ProductTemplateCondition[],\n error: Error\n ): ProductTemplate<TemplateContent> | null {\n if (error) {\n return null;\n }\n\n return {\n conditions: conditions.concat(this.matchConditions),\n content: getTemplateElement(this.host).content!,\n linkContent: this.getLinkTemplateElement(this.host).content!,\n priority: 1,\n };\n }\n\n renderIfError(error: Error) {\n if (error) {\n return (\n <atomic-component-error\n element={this.host}\n error={error}\n ></atomic-component-error>\n );\n }\n }\n getDefaultLinkTemplateElement() {\n const linkTemplate = document.createElement('template');\n linkTemplate.innerHTML = `<atomic-product-link>${this.gridCellLinkTarget ? `<a slot=\"attributes\" target=\"${this.gridCellLinkTarget}\"></a>` : ''}</atomic-product-link>`;\n return linkTemplate;\n }\n\n getLinkTemplateElement(host: HTMLElement) {\n return (\n host.querySelector<HTMLTemplateElement>('template[slot=\"link\"]') ??\n this.getDefaultLinkTemplateElement()\n );\n }\n}\n\nfunction getTemplateElement(host: HTMLElement) {\n return host.querySelector<HTMLTemplateElement>('template:not([slot])')!;\n}\n\nexport function makeDefinedConditions(\n ifDefined?: string,\n ifNotDefined?: string\n): ProductTemplateCondition[] {\n const conditions: ProductTemplateCondition[] = [];\n if (ifDefined) {\n const fieldNames = ifDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));\n }\n\n if (ifNotDefined) {\n const fieldNames = ifNotDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));\n }\n return conditions;\n}\n","import {Product, ProductTemplateCondition} from '@coveo/headless/commerce';\nimport {Component, Prop, h, Element} from '@stencil/core';\nimport {MapProp} from '../../../utils/props-utils';\nimport {\n makeDefinedConditions,\n makeMatchConditions,\n} from '../../common/product-template/stencil-product-template-common';\nimport {ProductContext} from '../product-template-component-utils/stencil-product-template-decorators';\n\n/**\n * The `atomic-product-field-condition` component takes a list of conditions that, if fulfilled, apply the template in which it's defined.\n * The condition properties can be based on any top-level product property of the `product` object, not restricted to fields (e.g., `ec_name`).\n * @alpha\n */\n@Component({\n tag: 'atomic-product-field-condition',\n shadow: false,\n})\nexport class AtomicProductFieldCondition {\n @Element() host!: HTMLElement;\n\n /**\n * Verifies whether the specified fields are defined.\n */\n @Prop({reflect: true}) ifDefined?: string;\n /**\n * Verifies whether the specified fields are not defined.\n */\n @Prop({reflect: true}) ifNotDefined?: string;\n\n /**\n * Verifies whether the specified fields match the specified values.\n * @type {Record<string, string[]>}\n */\n @Prop() @MapProp({splitValues: true}) mustMatch: Record<string, string[]> =\n {};\n\n /**\n * Verifies whether the specified fields do not match the specified values.\n * @type {Record<string, string[]>}\n */\n @Prop() @MapProp({splitValues: true}) mustNotMatch: Record<string, string[]> =\n {};\n\n private conditions: ProductTemplateCondition[] = [];\n private shouldBeRemoved = false;\n\n @ProductContext() private product!: Product;\n\n public componentWillLoad() {\n this.conditions = makeDefinedConditions(this.ifDefined, this.ifNotDefined);\n this.conditions.push(\n ...makeMatchConditions(this.mustMatch, this.mustNotMatch)\n );\n }\n\n public render() {\n if (!this.conditions.every((condition) => condition(this.product))) {\n this.shouldBeRemoved = true;\n return '';\n }\n\n return <slot />;\n }\n\n public componentDidLoad() {\n this.shouldBeRemoved && this.host.remove();\n }\n}\n"],"version":3}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { r as registerInstance, h, g as getElement } from './index-3f35faca.js';
|
|
2
|
-
import { M as MapProp } from './props-utils-e17fa18c.js';
|
|
3
|
-
import './purify-c7ebd240.js';
|
|
4
|
-
import { ProductTemplatesHelpers } from '@coveo/headless/commerce';
|
|
5
|
-
import { P as ProductContext } from './stencil-product-template-decorators-58cfc116.js';
|
|
6
|
-
import '@coveo/bueno';
|
|
7
|
-
import './utils-30b00491.js';
|
|
8
|
-
import './_commonjsHelpers-1789f0cf.js';
|
|
9
|
-
import './stencil-item-decorators-6c453c11.js';
|
|
10
|
-
import './dom-utils-f6086cd3.js';
|
|
11
|
-
import './event-utils-8de63ec3.js';
|
|
12
|
-
|
|
13
|
-
// TODO: Replace by Set.prototype.intersection in July 2025
|
|
14
|
-
function intersection(setA, setB) {
|
|
15
|
-
const result = new Set();
|
|
16
|
-
for (const elem of setA) {
|
|
17
|
-
if (setB.has(elem)) {
|
|
18
|
-
result.add(elem);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function makeMatchConditions(mustMatch, mustNotMatch) {
|
|
25
|
-
const conditions = [];
|
|
26
|
-
for (const field in mustMatch) {
|
|
27
|
-
if (mustNotMatch[field]) {
|
|
28
|
-
const mustNotMatchValues = new Set(mustNotMatch[field]);
|
|
29
|
-
const mustMatchValues = new Set(mustMatch[field]);
|
|
30
|
-
const commonValues = intersection(mustNotMatchValues, mustMatchValues);
|
|
31
|
-
if (commonValues.size > 0) {
|
|
32
|
-
console.error(`Conflicting match conditions for field ${field}, the template will be ignored.`, commonValues);
|
|
33
|
-
return [() => false];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
conditions.push(ProductTemplatesHelpers.fieldMustMatch(field, mustMatch[field]));
|
|
37
|
-
}
|
|
38
|
-
for (const field in mustNotMatch) {
|
|
39
|
-
conditions.push(ProductTemplatesHelpers.fieldMustNotMatch(field, mustNotMatch[field]));
|
|
40
|
-
}
|
|
41
|
-
return conditions;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function makeDefinedConditions(ifDefined, ifNotDefined) {
|
|
45
|
-
const conditions = [];
|
|
46
|
-
if (ifDefined) {
|
|
47
|
-
const fieldNames = ifDefined.split(',');
|
|
48
|
-
conditions.push(ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));
|
|
49
|
-
}
|
|
50
|
-
if (ifNotDefined) {
|
|
51
|
-
const fieldNames = ifNotDefined.split(',');
|
|
52
|
-
conditions.push(ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));
|
|
53
|
-
}
|
|
54
|
-
return conditions;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
58
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
59
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
60
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
61
|
-
else
|
|
62
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
63
|
-
if (d = decorators[i])
|
|
64
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
65
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
66
|
-
};
|
|
67
|
-
const AtomicProductFieldCondition = class {
|
|
68
|
-
constructor(hostRef) {
|
|
69
|
-
registerInstance(this, hostRef);
|
|
70
|
-
/**
|
|
71
|
-
* Verifies whether the specified fields match the specified values.
|
|
72
|
-
* @type {Record<string, string[]>}
|
|
73
|
-
*/
|
|
74
|
-
this.mustMatch = {};
|
|
75
|
-
/**
|
|
76
|
-
* Verifies whether the specified fields do not match the specified values.
|
|
77
|
-
* @type {Record<string, string[]>}
|
|
78
|
-
*/
|
|
79
|
-
this.mustNotMatch = {};
|
|
80
|
-
this.conditions = [];
|
|
81
|
-
this.shouldBeRemoved = false;
|
|
82
|
-
this.ifDefined = undefined;
|
|
83
|
-
this.ifNotDefined = undefined;
|
|
84
|
-
this.mustMatch = {};
|
|
85
|
-
this.mustNotMatch = {};
|
|
86
|
-
}
|
|
87
|
-
componentWillLoad() {
|
|
88
|
-
this.conditions = makeDefinedConditions(this.ifDefined, this.ifNotDefined);
|
|
89
|
-
this.conditions.push(...makeMatchConditions(this.mustMatch, this.mustNotMatch));
|
|
90
|
-
}
|
|
91
|
-
render() {
|
|
92
|
-
if (!this.conditions.every((condition) => condition(this.product))) {
|
|
93
|
-
this.shouldBeRemoved = true;
|
|
94
|
-
return '';
|
|
95
|
-
}
|
|
96
|
-
return h("slot", null);
|
|
97
|
-
}
|
|
98
|
-
componentDidLoad() {
|
|
99
|
-
this.shouldBeRemoved && this.host.remove();
|
|
100
|
-
}
|
|
101
|
-
get host() { return getElement(this); }
|
|
102
|
-
};
|
|
103
|
-
__decorate([
|
|
104
|
-
MapProp({ splitValues: true })
|
|
105
|
-
], AtomicProductFieldCondition.prototype, "mustMatch", void 0);
|
|
106
|
-
__decorate([
|
|
107
|
-
MapProp({ splitValues: true })
|
|
108
|
-
], AtomicProductFieldCondition.prototype, "mustNotMatch", void 0);
|
|
109
|
-
__decorate([
|
|
110
|
-
ProductContext()
|
|
111
|
-
], AtomicProductFieldCondition.prototype, "product", void 0);
|
|
112
|
-
|
|
113
|
-
export { AtomicProductFieldCondition as atomic_product_field_condition };
|
|
114
|
-
|
|
115
|
-
//# sourceMappingURL=atomic-product-field-condition.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"atomic-product-field-condition.entry.js","mappings":";;;;;;;;;;;;AAAA;SACgB,YAAY,CAAI,IAAY,EAAE,IAAY;IACxD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAK,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;QACvB,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAClB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SAClB;KACF;IACD,OAAO,MAAM,CAAC;AAChB;;SCsBgB,mBAAmB,CACjC,SAAmC,EACnC,YAAsC;IAEtC,MAAM,UAAU,GAA+B,EAAE,CAAC;IAClD,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE;QAC7B,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;YACvB,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YACxD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YAClD,MAAM,YAAY,GAAG,YAAY,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;YACvE,IAAI,YAAY,CAAC,IAAI,GAAG,CAAC,EAAE;gBACzB,OAAO,CAAC,KAAK,CACX,0CAA0C,KAAK,iCAAiC,EAChF,YAAY,CACb,CAAC;g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AAC,YAAY,CAAC,CAC1D,CAAC;KACH;IAEM,MAAM;QACX,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;YAClE,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAC5B,OAAO,EAAE,CAAC;SACX;QAED,OAAO,eAAQ,CAAC;KACjB;IAEM,gBAAgB;QACrB,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;KAC5C;;;AAjCqC;IAA7B,OAAO,CAAC,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;8DAChC;AAMiC;IAA7B,OAAO,CAAC,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;iEAChC;AAKqB;IAAzB,cAAc,EAAE;4DAA2B;;;;","names":[],"sources":["src/utils/set.ts","src/components/common/product-template/product-template-common.ts","src/components/common/product-template/stencil-product-template-common.tsx","src/components/commerce/atomic-product-field-condition/atomic-product-field-condition.tsx"],"sourcesContent":["// TODO: Replace by Set.prototype.intersection in July 2025\nexport function intersection<T>(setA: Set<T>, setB: Set<T>): Set<T> {\n const result = new Set<T>();\n for (const elem of setA) {\n if (setB.has(elem)) {\n result.add(elem);\n }\n }\n return result;\n}\n","import {\n type ProductTemplateCondition,\n ProductTemplatesHelpers,\n} from '@coveo/headless/commerce';\nimport {intersection} from '../../../utils/set';\nimport {isElementNode, isVisualNode} from '../../../utils/utils';\nimport {tableElementTagName} from '../../search/atomic-table-result/table-element-utils';\nimport {isResultSectionNode} from '../layout/sections';\n\ntype TemplateNodeType =\n | 'section'\n | 'metadata'\n | 'table-column-definition'\n | 'other';\n\nexport function getTemplateNodeType(node: Node): TemplateNodeType {\n if (isResultSectionNode(node)) {\n return 'section';\n }\n if (!isVisualNode(node)) {\n return 'metadata';\n }\n if (\n isElementNode(node) &&\n node.tagName.toLowerCase() === tableElementTagName\n ) {\n return 'table-column-definition';\n }\n return 'other';\n}\n\nexport function makeMatchConditions(\n mustMatch: Record<string, string[]>,\n mustNotMatch: Record<string, string[]>\n): ProductTemplateCondition[] {\n const conditions: ProductTemplateCondition[] = [];\n for (const field in mustMatch) {\n if (mustNotMatch[field]) {\n const mustNotMatchValues = new Set(mustNotMatch[field]);\n const mustMatchValues = new Set(mustMatch[field]);\n const commonValues = intersection(mustNotMatchValues, mustMatchValues);\n if (commonValues.size > 0) {\n console.error(\n `Conflicting match conditions for field ${field}, the template will be ignored.`,\n commonValues\n );\n return [() => false];\n }\n }\n conditions.push(\n ProductTemplatesHelpers.fieldMustMatch(field, mustMatch[field])\n );\n }\n\n for (const field in mustNotMatch) {\n conditions.push(\n ProductTemplatesHelpers.fieldMustNotMatch(field, mustNotMatch[field])\n );\n }\n return conditions;\n}\n\nexport function makeDefinedConditions(\n ifDefined?: string,\n ifNotDefined?: string\n): ProductTemplateCondition[] {\n const conditions: ProductTemplateCondition[] = [];\n if (ifDefined) {\n const fieldNames = ifDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));\n }\n\n if (ifNotDefined) {\n const fieldNames = ifNotDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));\n }\n return conditions;\n}\n","import {aggregate, isElementNode, isVisualNode} from '@/src/utils/utils';\nimport {\n ProductTemplate,\n ProductTemplateCondition,\n ProductTemplatesHelpers,\n} from '@coveo/headless/commerce';\nimport {h} from '@stencil/core';\nimport {tableElementTagName} from '../../search/atomic-table-result/table-element-utils';\nimport {ItemTarget} from '../layout/display-options';\nimport {isResultSectionNode} from '../layout/sections';\n\nexport {makeMatchConditions} from './product-template-common';\n\nexport type TemplateContent = DocumentFragment;\n\ninterface ProductTemplateCommonProps {\n allowEmpty?: boolean;\n host: HTMLDivElement;\n validParents: string[];\n setError: (error: Error) => void;\n}\n\ntype TemplateNodeType =\n | 'section'\n | 'metadata'\n | 'table-column-definition'\n | 'other';\n\nexport function getTemplateNodeType(node: Node): TemplateNodeType {\n if (isResultSectionNode(node)) {\n return 'section';\n }\n if (!isVisualNode(node)) {\n return 'metadata';\n }\n if (\n isElementNode(node) &&\n node.tagName.toLowerCase() === tableElementTagName\n ) {\n return 'table-column-definition';\n }\n return 'other';\n}\n\nfunction groupNodesByType(nodes: NodeList) {\n return aggregate(Array.from(nodes), (node) => getTemplateNodeType(node));\n}\n\n/**\n * @deprecated Use `ProductTemplateController` Reactive controller instead.\n */\nexport class ProductTemplateCommon {\n private host: HTMLDivElement;\n public matchConditions: ProductTemplateCondition[] = [];\n private gridCellLinkTarget?: ItemTarget;\n\n constructor({\n host,\n setError,\n validParents,\n allowEmpty = false,\n }: ProductTemplateCommonProps) {\n this.host = host;\n this.validateTemplate(host, setError, validParents, allowEmpty);\n }\n\n validateTemplate(\n host: HTMLDivElement,\n setError: (error: Error) => void,\n validParents: string[],\n allowEmpty = true\n ) {\n const hasValidParent = validParents\n .map((p) => p.toUpperCase())\n .includes(host.parentElement?.nodeName || '');\n const tagName = host.nodeName.toLowerCase();\n\n if (!hasValidParent) {\n setError(\n new Error(\n `The \"${tagName}\" component has to be the child of one of the following: ${validParents\n .map((p) => `\"${p.toLowerCase()}\"`)\n .join(', ')}.`\n )\n );\n return;\n }\n\n if (\n host.parentElement?.attributes.getNamedItem('display')?.value === 'grid'\n ) {\n this.gridCellLinkTarget = host.parentElement?.attributes.getNamedItem(\n 'grid-cell-link-target'\n )?.value as ItemTarget;\n }\n\n const template = host.querySelector('template');\n if (!template) {\n setError(\n new Error(\n `The \"${tagName}\" component must contain a \"template\" element as a child.`\n )\n );\n return;\n }\n\n if (!allowEmpty && !template.innerHTML.trim()) {\n setError(\n new Error(`The \"template\" tag inside \"${tagName}\" cannot be empty.`)\n );\n return;\n }\n\n if (template.content.querySelector('script')) {\n console.warn(\n 'Any \"script\" tags defined inside of \"template\" elements are not supported and will not be executed when the products are rendered.',\n host\n );\n }\n\n const {section: sectionNodes, other: otherNodes} = groupNodesByType(\n template.content.childNodes\n );\n if (sectionNodes?.length && otherNodes?.length) {\n console.warn(\n 'Product templates should only contain section elements or non-section elements. Future updates could unpredictably affect this product template.',\n host,\n {sectionNodes, otherNodes}\n );\n }\n }\n\n getTemplate(\n conditions: ProductTemplateCondition[],\n error: Error\n ): ProductTemplate<TemplateContent> | null {\n if (error) {\n return null;\n }\n\n return {\n conditions: conditions.concat(this.matchConditions),\n content: getTemplateElement(this.host).content!,\n linkContent: this.getLinkTemplateElement(this.host).content!,\n priority: 1,\n };\n }\n\n renderIfError(error: Error) {\n if (error) {\n return (\n <atomic-component-error\n element={this.host}\n error={error}\n ></atomic-component-error>\n );\n }\n }\n getDefaultLinkTemplateElement() {\n const linkTemplate = document.createElement('template');\n linkTemplate.innerHTML = `<atomic-product-link>${this.gridCellLinkTarget ? `<a slot=\"attributes\" target=\"${this.gridCellLinkTarget}\"></a>` : ''}</atomic-product-link>`;\n return linkTemplate;\n }\n\n getLinkTemplateElement(host: HTMLElement) {\n return (\n host.querySelector<HTMLTemplateElement>('template[slot=\"link\"]') ??\n this.getDefaultLinkTemplateElement()\n );\n }\n}\n\nfunction getTemplateElement(host: HTMLElement) {\n return host.querySelector<HTMLTemplateElement>('template:not([slot])')!;\n}\n\nexport function makeDefinedConditions(\n ifDefined?: string,\n ifNotDefined?: string\n): ProductTemplateCondition[] {\n const conditions: ProductTemplateCondition[] = [];\n if (ifDefined) {\n const fieldNames = ifDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));\n }\n\n if (ifNotDefined) {\n const fieldNames = ifNotDefined.split(',');\n conditions.push(ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));\n }\n return conditions;\n}\n","import {Product, ProductTemplateCondition} from '@coveo/headless/commerce';\nimport {Component, Prop, h, Element} from '@stencil/core';\nimport {MapProp} from '../../../utils/props-utils';\nimport {\n makeDefinedConditions,\n makeMatchConditions,\n} from '../../common/product-template/stencil-product-template-common';\nimport {ProductContext} from '../product-template-component-utils/stencil-product-template-decorators';\n\n/**\n * The `atomic-product-field-condition` component takes a list of conditions that, if fulfilled, apply the template in which it's defined.\n * The condition properties can be based on any top-level product property of the `product` object, not restricted to fields (e.g., `ec_name`).\n * @alpha\n */\n@Component({\n tag: 'atomic-product-field-condition',\n shadow: false,\n})\nexport class AtomicProductFieldCondition {\n @Element() host!: HTMLElement;\n\n /**\n * Verifies whether the specified fields are defined.\n */\n @Prop({reflect: true}) ifDefined?: string;\n /**\n * Verifies whether the specified fields are not defined.\n */\n @Prop({reflect: true}) ifNotDefined?: string;\n\n /**\n * Verifies whether the specified fields match the specified values.\n * @type {Record<string, string[]>}\n */\n @Prop() @MapProp({splitValues: true}) mustMatch: Record<string, string[]> =\n {};\n\n /**\n * Verifies whether the specified fields do not match the specified values.\n * @type {Record<string, string[]>}\n */\n @Prop() @MapProp({splitValues: true}) mustNotMatch: Record<string, string[]> =\n {};\n\n private conditions: ProductTemplateCondition[] = [];\n private shouldBeRemoved = false;\n\n @ProductContext() private product!: Product;\n\n public componentWillLoad() {\n this.conditions = makeDefinedConditions(this.ifDefined, this.ifNotDefined);\n this.conditions.push(\n ...makeMatchConditions(this.mustMatch, this.mustNotMatch)\n );\n }\n\n public render() {\n if (!this.conditions.every((condition) => condition(this.product))) {\n this.shouldBeRemoved = true;\n return '';\n }\n\n return <slot />;\n }\n\n public componentDidLoad() {\n this.shouldBeRemoved && this.host.remove();\n }\n}\n"],"version":3}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|