@coveo/atomic 3.31.2-pre.250e2f6259 → 3.31.2-pre.25fd3f0b2d
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 +1 -3
- package/dist/atomic/components/analytics-config.js +1 -1
- package/dist/atomic/components/atomic-product-rating.js +34 -2
- package/dist/atomic/components/atomic-product-rating.js.map +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-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/global/environment.js +1 -1
- package/dist/atomic/components/index.js.map +1 -1
- package/dist/atomic/{p-9d58dc80.entry.js → p-48c24b74.entry.js} +2 -2
- package/dist/atomic/{p-940a79a5.js → p-96b96395.js} +2 -2
- package/dist/atomic/{p-e6f4dfb3.entry.js → p-af06280e.entry.js} +2 -2
- package/dist/atomic/{p-7b928196.entry.js → p-f876f7f7.entry.js} +2 -2
- package/dist/cjs/_loader.cjs.js +1 -1
- package/dist/cjs/{analytics-config-05d4b837.js → analytics-config-df2581de.js} +2 -2
- package/dist/cjs/{analytics-config-05d4b837.js.map → analytics-config-df2581de.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-b8a89287.js → analytics-config-482fd000.js} +2 -2
- package/dist/esm/{analytics-config-b8a89287.js.map → analytics-config-482fd000.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-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.d.ts +0 -69
- package/docs/atomic-docs.json +1 -134
- 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/stencil-product-template-decorators.js +0 -37
- package/dist/atomic/components/stencil-product-template-decorators.js.map +0 -1
- 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-9d58dc80.entry.js.map → p-48c24b74.entry.js.map} +0 -0
- /package/dist/atomic/{p-940a79a5.js.map → p-96b96395.js.map} +0 -0
- /package/dist/atomic/{p-e6f4dfb3.entry.js.map → p-af06280e.entry.js.map} +0 -0
- /package/dist/atomic/{p-7b928196.entry.js.map → p-f876f7f7.entry.js.map} +0 -0
|
@@ -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":"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","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
|