@coveo/atomic 3.34.0-pre.b429ebe8aa → 3.34.0-pre.b893a97055
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atomic/_atomic.esm.js +1 -1
- package/dist/atomic/components/analytics-config.js +1 -1
- package/dist/atomic/components/atomic-field-condition.js +1 -1
- package/dist/atomic/components/atomic-field-condition.js.map +1 -1
- package/dist/atomic/components/atomic-insight-result-children-template.js +1 -1
- package/dist/atomic/components/atomic-insight-result-children-template.js.map +1 -1
- package/dist/atomic/components/atomic-insight-result-template.js +1 -1
- package/dist/atomic/components/atomic-insight-result-template.js.map +1 -1
- package/dist/atomic/components/atomic-recs-result-template.js +1 -1
- package/dist/atomic/components/atomic-recs-result-template.js.map +1 -1
- package/dist/atomic/components/atomic-result-children-template.js +1 -1
- package/dist/atomic/components/atomic-result-children-template.js.map +1 -1
- package/dist/atomic/components/atomic-result-list.js.map +1 -1
- package/dist/atomic/components/atomic-result-template.js +1 -1
- package/dist/atomic/components/atomic-result-template.js.map +1 -1
- package/dist/atomic/components/components/commerce/atomic-product-field-condition/atomic-product-field-condition.js +3 -4
- package/dist/atomic/components/components/commerce/atomic-product-template/atomic-product-template.js +2 -3
- package/dist/atomic/components/components/common/item-list/table-layout.js +1 -1
- package/dist/atomic/components/components/common/{template-controller/template-utils.js → product-template/product-template-common.js} +12 -11
- package/dist/atomic/components/components/common/product-template/product-template-controller.js +81 -16
- package/dist/atomic/components/global/environment.js +1 -1
- package/dist/atomic/components/{stencil-result-template-common.js → result-template-common.js} +1 -1
- package/dist/atomic/components/result-template-common.js.map +1 -0
- package/dist/atomic/components/table-element-utils.js.map +1 -1
- package/dist/atomic/{p-4da8f827.js → p-2250f505.js} +2 -2
- package/dist/atomic/p-2250f505.js.map +1 -0
- package/dist/atomic/{p-60be00ad.js → p-2a457f26.js} +2 -2
- package/dist/atomic/{p-a46d36dd.entry.js → p-373448df.entry.js} +2 -2
- package/dist/atomic/p-373448df.entry.js.map +1 -0
- package/dist/atomic/{p-6694e114.entry.js → p-62e85c20.entry.js} +2 -2
- package/dist/atomic/p-62e85c20.entry.js.map +1 -0
- package/dist/atomic/{p-4f34763d.entry.js → p-663c1246.entry.js} +2 -2
- package/dist/atomic/{p-2213060b.entry.js → p-7fd5b6ac.entry.js} +2 -2
- package/dist/atomic/p-7fd5b6ac.entry.js.map +1 -0
- package/dist/atomic/{p-ebd00891.entry.js → p-9260dd7d.entry.js} +2 -2
- package/dist/atomic/p-9260dd7d.entry.js.map +1 -0
- package/dist/atomic/{p-86f950a5.entry.js → p-a1e5f767.entry.js} +2 -2
- package/dist/atomic/p-a1e5f767.entry.js.map +1 -0
- package/dist/atomic/{p-be0518ae.js → p-acd1a1d3.js} +1 -1
- package/dist/atomic/p-acd1a1d3.js.map +1 -0
- package/dist/atomic/{p-f676b5ba.entry.js → p-af1b4924.entry.js} +2 -2
- package/dist/atomic/p-af1b4924.entry.js.map +1 -0
- package/dist/atomic/{p-a3fac2ec.entry.js → p-e461f0cc.entry.js} +2 -2
- package/dist/atomic/{p-2895c42c.entry.js → p-e7a25b00.entry.js} +2 -2
- package/dist/atomic/p-e7a25b00.entry.js.map +1 -0
- package/dist/cjs/{analytics-config-7fafe2ee.js → analytics-config-f9b37a30.js} +2 -2
- package/dist/cjs/{analytics-config-7fafe2ee.js.map → analytics-config-f9b37a30.js.map} +1 -1
- package/dist/cjs/atomic-field-condition.cjs.entry.js +3 -3
- package/dist/cjs/atomic-field-condition.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-insight-interface.cjs.entry.js +1 -1
- package/dist/cjs/atomic-insight-result-children-template.cjs.entry.js +5 -5
- package/dist/cjs/atomic-insight-result-children-template.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-insight-result-template.cjs.entry.js +5 -5
- package/dist/cjs/atomic-insight-result-template.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-recs-interface.cjs.entry.js +1 -1
- package/dist/cjs/atomic-recs-result-template.cjs.entry.js +5 -5
- package/dist/cjs/atomic-recs-result-template.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-result-children-template.cjs.entry.js +4 -4
- package/dist/cjs/atomic-result-children-template.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-result-list.cjs.entry.js +1 -1
- package/dist/cjs/atomic-result-list.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-result-template.cjs.entry.js +4 -4
- package/dist/cjs/atomic-result-template.cjs.entry.js.map +1 -1
- package/dist/cjs/{stencil-result-template-common-bb38948f.js → result-template-common-84bd4057.js} +2 -2
- package/dist/cjs/result-template-common-84bd4057.js.map +1 -0
- package/dist/cjs/{table-element-utils-2cc6dc82.js → table-element-utils-4865b735.js} +1 -1
- package/dist/cjs/table-element-utils-4865b735.js.map +1 -0
- package/dist/cjs/version.cjs.js +1 -1
- package/dist/esm/{analytics-config-a8c239d1.js → analytics-config-b57631c1.js} +2 -2
- package/dist/esm/{analytics-config-a8c239d1.js.map → analytics-config-b57631c1.js.map} +1 -1
- package/dist/esm/atomic-field-condition.entry.js +2 -2
- package/dist/esm/atomic-field-condition.entry.js.map +1 -1
- package/dist/esm/atomic-insight-interface.entry.js +1 -1
- package/dist/esm/atomic-insight-result-children-template.entry.js +2 -2
- package/dist/esm/atomic-insight-result-children-template.entry.js.map +1 -1
- package/dist/esm/atomic-insight-result-template.entry.js +2 -2
- package/dist/esm/atomic-insight-result-template.entry.js.map +1 -1
- package/dist/esm/atomic-recs-interface.entry.js +1 -1
- package/dist/esm/atomic-recs-result-template.entry.js +2 -2
- package/dist/esm/atomic-recs-result-template.entry.js.map +1 -1
- package/dist/esm/atomic-result-children-template.entry.js +2 -2
- package/dist/esm/atomic-result-children-template.entry.js.map +1 -1
- package/dist/esm/atomic-result-list.entry.js +1 -1
- package/dist/esm/atomic-result-list.entry.js.map +1 -1
- package/dist/esm/atomic-result-template.entry.js +2 -2
- package/dist/esm/atomic-result-template.entry.js.map +1 -1
- package/dist/esm/{stencil-result-template-common-19af5cfb.js → result-template-common-995b94f8.js} +2 -2
- package/dist/esm/result-template-common-995b94f8.js.map +1 -0
- package/dist/esm/{table-element-utils-1dbc5ef6.js → table-element-utils-49d22ec6.js} +1 -1
- package/dist/esm/table-element-utils-49d22ec6.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/components/common/product-template/product-template-common.d.ts +6 -0
- package/dist/types/components/common/product-template/product-template-controller.d.ts +19 -9
- package/dist/types/components/common/product-template/stencil-product-template-common.d.ts +1 -1
- package/dist/types/components/insight/result-templates/atomic-insight-result-children-template/atomic-insight-result-children-template.d.ts +1 -1
- package/dist/types/components/search/result-templates/atomic-result-children-template/atomic-result-children-template.d.ts +1 -1
- package/docs/atomic-docs.json +1 -1
- package/package.json +1 -1
- package/dist/atomic/components/components/common/template-controller/base-template-controller.js +0 -89
- package/dist/atomic/components/stencil-result-template-common.js.map +0 -1
- package/dist/atomic/p-2213060b.entry.js.map +0 -1
- package/dist/atomic/p-2895c42c.entry.js.map +0 -1
- package/dist/atomic/p-4da8f827.js.map +0 -1
- package/dist/atomic/p-6694e114.entry.js.map +0 -1
- package/dist/atomic/p-86f950a5.entry.js.map +0 -1
- package/dist/atomic/p-a46d36dd.entry.js.map +0 -1
- package/dist/atomic/p-be0518ae.js.map +0 -1
- package/dist/atomic/p-ebd00891.entry.js.map +0 -1
- package/dist/atomic/p-f676b5ba.entry.js.map +0 -1
- package/dist/cjs/stencil-result-template-common-bb38948f.js.map +0 -1
- package/dist/cjs/table-element-utils-2cc6dc82.js.map +0 -1
- package/dist/esm/stencil-result-template-common-19af5cfb.js.map +0 -1
- package/dist/esm/table-element-utils-1dbc5ef6.js.map +0 -1
- package/dist/types/components/common/result-templates/result-template-controller.d.ts +0 -16
- package/dist/types/components/common/template-controller/base-template-controller.d.ts +0 -36
- package/dist/types/components/common/template-controller/template-utils.d.ts +0 -11
- /package/dist/atomic/components/components/{common → search/atomic-table-result}/table-element-utils.js +0 -0
- /package/dist/atomic/{p-60be00ad.js.map → p-2a457f26.js.map} +0 -0
- /package/dist/atomic/{p-4f34763d.entry.js.map → p-663c1246.entry.js.map} +0 -0
- /package/dist/atomic/{p-a3fac2ec.entry.js.map → p-e461f0cc.entry.js.map} +0 -0
- /package/dist/types/components/common/result-templates/{stencil-result-template-common.d.ts → result-template-common.d.ts} +0 -0
- /package/dist/types/components/{common → search/atomic-table-result}/table-element-utils.d.ts +0 -0
@@ -1 +1 @@
|
|
1
|
-
{"file":"atomic-result-template.js","mappings":";;;;;;;;;;;;;;MAsBaA,sBAAoB;IAkC/B;;;;;;;;;;;QApBe,eAAU,GAA8B,EAAE,CAAC;;;;;QAMb,cAAS,GAGlD,EAAE,CAAC;;;;;QAMsC,iBAAY,GAGrD,EAAE,CAAC;;0BAlBgD,EAAE;yBASrD,EAAE;4BASF,EAAE;KAEU;IAEhB,iBAAiB;QACf,IAAI,CAAC,oBAAoB,GAAG,IAAI,oBAAoB,CAAC;YACnD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,CAAC,GAAG;gBACZ,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;aAClB;YACD,YAAY,EAAE;gBACZ,oBAAoB;gBACpB,2BAA2B;gBAC3B,mCAAmC;aACpC;YACD,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;KACJ;IAEM,iBAAiB;QACtB,IAAI,CAAC,oBAAoB,CAAC,eAAe,GAAG,mBAAmB,CAC7D,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,YAAY,CAClB,CAAC;KACH;;;;IAMM,MAAM,WAAW;QACtB,OAAO,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;KAC3E;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAC5D;;;;;;;;;AAhD4C;IAApC,OAAO,CAAC,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;yDAG9B;AAMsC;IAApC,OAAO,CAAC,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;4DAG9B;;;;;;;;;;;;;;;;;;;;","names":["AtomicResultTemplate"],"sources":["src/components/search/result-templates/atomic-result-template/atomic-result-template.tsx"],"sourcesContent":["import {ResultTemplate, ResultTemplateCondition} from '@coveo/headless';\nimport {Component, Element, Prop, Method, State} from '@stencil/core';\nimport {MapProp} from '../../../../utils/props-utils';\nimport {\n makeMatchConditions,\n ResultTemplateCommon,\n} from '../../../common/result-templates/
|
1
|
+
{"file":"atomic-result-template.js","mappings":";;;;;;;;;;;;;;MAsBaA,sBAAoB;IAkC/B;;;;;;;;;;;QApBe,eAAU,GAA8B,EAAE,CAAC;;;;;QAMb,cAAS,GAGlD,EAAE,CAAC;;;;;QAMsC,iBAAY,GAGrD,EAAE,CAAC;;0BAlBgD,EAAE;yBASrD,EAAE;4BASF,EAAE;KAEU;IAEhB,iBAAiB;QACf,IAAI,CAAC,oBAAoB,GAAG,IAAI,oBAAoB,CAAC;YACnD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,CAAC,GAAG;gBACZ,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;aAClB;YACD,YAAY,EAAE;gBACZ,oBAAoB;gBACpB,2BAA2B;gBAC3B,mCAAmC;aACpC;YACD,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;KACJ;IAEM,iBAAiB;QACtB,IAAI,CAAC,oBAAoB,CAAC,eAAe,GAAG,mBAAmB,CAC7D,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,YAAY,CAClB,CAAC;KACH;;;;IAMM,MAAM,WAAW;QACtB,OAAO,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;KAC3E;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAC5D;;;;;;;;;AAhD4C;IAApC,OAAO,CAAC,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;yDAG9B;AAMsC;IAApC,OAAO,CAAC,EAAC,WAAW,EAAE,IAAI,EAAC,CAAC;4DAG9B;;;;;;;;;;;;;;;;;;;;","names":["AtomicResultTemplate"],"sources":["src/components/search/result-templates/atomic-result-template/atomic-result-template.tsx"],"sourcesContent":["import {ResultTemplate, ResultTemplateCondition} from '@coveo/headless';\nimport {Component, Element, Prop, Method, State} from '@stencil/core';\nimport {MapProp} from '../../../../utils/props-utils';\nimport {\n makeMatchConditions,\n ResultTemplateCommon,\n} from '../../../common/result-templates/result-template-common';\n\n/**\n * A [result template](https://docs.coveo.com/en/atomic/latest/usage/displaying-results#defining-a-result-template) determines the format of the query results, depending on the conditions that are defined for each template.\n *\n * @slot default - Mandatory. A `template` element that defines the structure of the result item.\n * @slot link - A `template` element that contains a single `atomic-result-link` component.\n *\n * **Note:** Any `<script>` tags that are defined inside a `<template>` element will not be executed when the results are being rendered.\n * @MapProp name: mustMatch;attr: must-match;docs: The field and values that define which result items the condition must be applied to. For example, a template with the following attribute only applies to result items whose `filetype` is `lithiummessage` or `YouTubePlaylist`: `must-match-filetype=\"lithiummessage,YouTubePlaylist\"`;type: Record<string, string[]> ;default: {}\n * @MapProp name: mustNotMatch;attr: must-not-match;docs: The field and values that define which result items the condition must not be applied to. For example, a template with the following attribute only applies to result items whose `filetype` is not `lithiummessage`: `must-not-match-filetype=\"lithiummessage\";type: Record<string, string[]> ;default: {}\n */\n@Component({\n tag: 'atomic-result-template',\n shadow: true,\n})\nexport class AtomicResultTemplate {\n private resultTemplateCommon!: ResultTemplateCommon;\n\n @State() public error!: Error;\n\n @Element() public host!: HTMLDivElement;\n\n /**\n * A function that must return true on results for the result template to apply.\n * Set programmatically before initialization, not via attribute.\n *\n * For example, the following targets a template and sets a condition to make it apply only to results whose `title` contains `singapore`:\n * `document.querySelector('#target-template').conditions = [(result) => /singapore/i.test(result.title)];`\n */\n @Prop() public conditions: ResultTemplateCondition[] = [];\n\n /**\n * Verifies whether the specified fields match the specified values.\n * @type {Record<string, string[]>}\n */\n @Prop() @MapProp({splitValues: true}) public mustMatch: Record<\n string,\n 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}) public mustNotMatch: Record<\n string,\n string[]\n > = {};\n\n constructor() {}\n\n connectedCallback() {\n this.resultTemplateCommon = new ResultTemplateCommon({\n host: this.host,\n setError: (err) => {\n this.error = err;\n },\n validParents: [\n 'atomic-result-list',\n 'atomic-folded-result-list',\n 'atomic-search-box-instant-results',\n ],\n allowEmpty: true,\n });\n }\n\n public componentWillLoad() {\n this.resultTemplateCommon.matchConditions = makeMatchConditions(\n this.mustMatch,\n this.mustNotMatch\n );\n }\n\n /**\n * Gets the appropriate result template based on conditions applied.\n */\n @Method()\n public async getTemplate(): Promise<ResultTemplate<DocumentFragment> | null> {\n return this.resultTemplateCommon.getTemplate(this.conditions, this.error);\n }\n\n public render() {\n return this.resultTemplateCommon.renderIfError(this.error);\n }\n}\n"],"version":3}
|
@@ -4,7 +4,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
6
|
};
|
7
|
-
import { ProductTemplatesHelpers } from '@coveo/headless/commerce';
|
8
7
|
import { html, LitElement } from 'lit';
|
9
8
|
import { customElement, property, state } from 'lit/decorators.js';
|
10
9
|
import { bindings } from "../../../decorators/bindings";
|
@@ -12,7 +11,7 @@ import { createProductContextController } from "../../../decorators/commerce/pro
|
|
12
11
|
import { errorGuard } from "../../../decorators/error-guard";
|
13
12
|
import { LightDomMixin } from "../../../mixins/light-dom";
|
14
13
|
import { mapProperty } from "../../../utils/props-utils";
|
15
|
-
import { makeDefinedConditions, makeMatchConditions, } from '../../common/template-
|
14
|
+
import { makeDefinedConditions, makeMatchConditions, } from '../../common/product-template/product-template-common';
|
16
15
|
/**
|
17
16
|
* The `atomic-product-field-condition` component renders its children only when all of the conditions specified through its props are satisfied.
|
18
17
|
* The condition properties can be based on any top-level product property of the `product` object, not restricted to fields (e.g., `ec_name`).
|
@@ -27,8 +26,8 @@ let AtomicProductFieldCondition = class AtomicProductFieldCondition extends Ligh
|
|
27
26
|
initialize() { }
|
28
27
|
get conditions() {
|
29
28
|
return [
|
30
|
-
...makeDefinedConditions(this.ifDefined, this.ifNotDefined
|
31
|
-
...makeMatchConditions(this.mustMatch, this.mustNotMatch
|
29
|
+
...makeDefinedConditions(this.ifDefined, this.ifNotDefined),
|
30
|
+
...makeMatchConditions(this.mustMatch, this.mustNotMatch),
|
32
31
|
];
|
33
32
|
}
|
34
33
|
render() {
|
@@ -4,13 +4,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
6
|
};
|
7
|
-
import { ProductTemplatesHelpers } from '@coveo/headless/commerce';
|
8
7
|
import { html, LitElement, nothing } from 'lit';
|
9
8
|
import { customElement, property, state } from 'lit/decorators.js';
|
10
9
|
import { errorGuard } from "../../../decorators/error-guard";
|
11
10
|
import { mapProperty } from "../../../utils/props-utils";
|
11
|
+
import { makeMatchConditions } from '../../common/product-template/product-template-common';
|
12
12
|
import { ProductTemplateController } from '../../common/product-template/product-template-controller';
|
13
|
-
import { makeMatchConditions } from '../../common/template-controller/template-utils';
|
14
13
|
import '../atomic-product/atomic-product';
|
15
14
|
/**
|
16
15
|
* * A product template determines the format of the products, depending on the conditions that are defined for each template.
|
@@ -44,7 +43,7 @@ let AtomicProductTemplate = class AtomicProductTemplate extends LitElement {
|
|
44
43
|
}
|
45
44
|
connectedCallback() {
|
46
45
|
super.connectedCallback();
|
47
|
-
this.productTemplateController.matchConditions = makeMatchConditions(this.mustMatch, this.mustNotMatch
|
46
|
+
this.productTemplateController.matchConditions = makeMatchConditions(this.mustMatch, this.mustNotMatch);
|
48
47
|
}
|
49
48
|
/**
|
50
49
|
* Gets the product template to apply based on the evaluated conditions.
|
@@ -2,7 +2,7 @@ import { html } from 'lit';
|
|
2
2
|
import { keyed } from 'lit/directives/keyed.js';
|
3
3
|
import { map } from 'lit/directives/map.js';
|
4
4
|
import { ref } from 'lit/directives/ref.js';
|
5
|
-
import { tableElementTagName } from '
|
5
|
+
import { tableElementTagName } from '../../search/atomic-table-result/table-element-utils';
|
6
6
|
export const renderTableLayout = ({ props }) => {
|
7
7
|
const { host, listClasses, logger } = props;
|
8
8
|
const fieldColumns = getFieldTableColumns(props);
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
1
|
+
import { ProductTemplatesHelpers, } from '@coveo/headless/commerce';
|
2
|
+
import { intersection } from '../../../utils/set';
|
3
|
+
import { isElementNode, isVisualNode } from '../../../utils/utils';
|
4
|
+
import { tableElementTagName } from '../../search/atomic-table-result/table-element-utils';
|
5
|
+
import { isResultSectionNode } from '../layout/item-layout-sections';
|
5
6
|
export function getTemplateNodeType(node) {
|
6
7
|
if (isResultSectionNode(node)) {
|
7
8
|
return 'section';
|
@@ -15,7 +16,7 @@ export function getTemplateNodeType(node) {
|
|
15
16
|
}
|
16
17
|
return 'other';
|
17
18
|
}
|
18
|
-
export function makeMatchConditions(mustMatch, mustNotMatch
|
19
|
+
export function makeMatchConditions(mustMatch, mustNotMatch) {
|
19
20
|
const conditions = [];
|
20
21
|
for (const field in mustMatch) {
|
21
22
|
if (mustNotMatch[field]) {
|
@@ -24,25 +25,25 @@ export function makeMatchConditions(mustMatch, mustNotMatch, helpers) {
|
|
24
25
|
const commonValues = intersection(mustNotMatchValues, mustMatchValues);
|
25
26
|
if (commonValues.size > 0) {
|
26
27
|
console.error(`Conflicting match conditions for field ${field}, the template will be ignored.`, commonValues);
|
27
|
-
return [(
|
28
|
+
return [() => false];
|
28
29
|
}
|
29
30
|
}
|
30
|
-
conditions.push(
|
31
|
+
conditions.push(ProductTemplatesHelpers.fieldMustMatch(field, mustMatch[field]));
|
31
32
|
}
|
32
33
|
for (const field in mustNotMatch) {
|
33
|
-
conditions.push(
|
34
|
+
conditions.push(ProductTemplatesHelpers.fieldMustNotMatch(field, mustNotMatch[field]));
|
34
35
|
}
|
35
36
|
return conditions;
|
36
37
|
}
|
37
|
-
export function makeDefinedConditions(ifDefined, ifNotDefined
|
38
|
+
export function makeDefinedConditions(ifDefined, ifNotDefined) {
|
38
39
|
const conditions = [];
|
39
40
|
if (ifDefined) {
|
40
41
|
const fieldNames = ifDefined.split(',');
|
41
|
-
conditions.push(
|
42
|
+
conditions.push(ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));
|
42
43
|
}
|
43
44
|
if (ifNotDefined) {
|
44
45
|
const fieldNames = ifNotDefined.split(',');
|
45
|
-
conditions.push(
|
46
|
+
conditions.push(ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));
|
46
47
|
}
|
47
48
|
return conditions;
|
48
49
|
}
|
package/dist/atomic/components/components/common/product-template/product-template-controller.js
CHANGED
@@ -1,29 +1,94 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import { aggregate } from '../../../utils/utils';
|
2
|
+
import { getTemplateNodeType } from './product-template-common';
|
3
|
+
export class ProductTemplateController {
|
3
4
|
constructor(host, validParents, allowEmpty = false) {
|
4
|
-
|
5
|
+
this.host = host;
|
6
|
+
this.validParents = validParents;
|
7
|
+
this.allowEmpty = allowEmpty;
|
8
|
+
this.matchConditions = [];
|
9
|
+
this.host.addController(this);
|
10
|
+
}
|
11
|
+
hostConnected() {
|
12
|
+
this.validateTemplate();
|
13
|
+
}
|
14
|
+
setError(error) {
|
15
|
+
this.host.error = error;
|
16
|
+
}
|
17
|
+
validateTemplate() {
|
18
|
+
const hasValidParent = this.validParents
|
19
|
+
.map((p) => p.toUpperCase())
|
20
|
+
.includes(this.parentElement?.nodeName || '');
|
21
|
+
const tagName = this.host.nodeName.toLowerCase();
|
22
|
+
if (!hasValidParent) {
|
23
|
+
this.setError(new Error(ProductTemplateController.ERRORS.invalidParent(tagName, this.validParents)));
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
if (this.parentAttr('display') === 'grid') {
|
27
|
+
this.gridCellLinkTarget = this.parentAttr('grid-cell-link-target');
|
28
|
+
}
|
29
|
+
if (!this.template) {
|
30
|
+
this.setError(new Error(ProductTemplateController.ERRORS.missingTemplate(tagName)));
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
if (!this.allowEmpty && !this.template.innerHTML.trim()) {
|
34
|
+
this.setError(new Error(ProductTemplateController.ERRORS.emptyTemplate(tagName)));
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
if (this.template.content.querySelector('script')) {
|
38
|
+
console.warn(ProductTemplateController.WARNINGS.scriptTag, this.host);
|
39
|
+
}
|
40
|
+
const { section, other } = groupNodesByType(this.template.content.childNodes);
|
41
|
+
if (section?.length && other?.length) {
|
42
|
+
console.warn(ProductTemplateController.WARNINGS.sectionMix, this.host, {
|
43
|
+
section,
|
44
|
+
other,
|
45
|
+
});
|
46
|
+
}
|
5
47
|
}
|
6
48
|
getTemplate(conditions) {
|
7
|
-
|
8
|
-
if (!baseTemplate) {
|
49
|
+
if (this.host.error) {
|
9
50
|
return null;
|
10
51
|
}
|
11
52
|
return {
|
12
|
-
conditions:
|
13
|
-
content:
|
14
|
-
linkContent:
|
15
|
-
priority:
|
16
|
-
};
|
17
|
-
}
|
18
|
-
getWarnings() {
|
19
|
-
return {
|
20
|
-
scriptTag: 'Any "script" tags defined inside of "template" elements are not supported and will not be executed when the products are rendered.',
|
21
|
-
sectionMix: 'Product templates should only contain section elements or non-section elements, not both. Future updates could unpredictably affect this product template.',
|
53
|
+
conditions: conditions.concat(this.matchConditions),
|
54
|
+
content: getTemplateElement(this.host).content,
|
55
|
+
linkContent: this.getLinkTemplateElement(this.host).content,
|
56
|
+
priority: 1,
|
22
57
|
};
|
23
58
|
}
|
24
59
|
getDefaultLinkTemplateElement() {
|
25
60
|
const linkTemplate = document.createElement('template');
|
26
|
-
linkTemplate.innerHTML = `<atomic-product-link>${this.
|
61
|
+
linkTemplate.innerHTML = `<atomic-product-link>${this.gridCellLinkTarget ? `<a slot="attributes" target="${this.gridCellLinkTarget}"></a>` : ''}</atomic-product-link>`;
|
27
62
|
return linkTemplate;
|
28
63
|
}
|
64
|
+
getLinkTemplateElement(host) {
|
65
|
+
return (host.querySelector('template[slot="link"]') ??
|
66
|
+
this.getDefaultLinkTemplateElement());
|
67
|
+
}
|
68
|
+
get parentElement() {
|
69
|
+
return this.host.parentElement;
|
70
|
+
}
|
71
|
+
get template() {
|
72
|
+
return this.host.querySelector('template');
|
73
|
+
}
|
74
|
+
parentAttr(attribute) {
|
75
|
+
return this.parentElement?.attributes.getNamedItem(attribute)?.value;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
ProductTemplateController.ERRORS = {
|
79
|
+
invalidParent: (tagName, validParents) => `The "${tagName}" component has to be the child of one of the following: ${validParents
|
80
|
+
.map((p) => `"${p.toLowerCase()}"`)
|
81
|
+
.join(', ')}.`,
|
82
|
+
missingTemplate: (tagName) => `The "${tagName}" component must contain a "template" element as a child.`,
|
83
|
+
emptyTemplate: (tagName) => `The "template" tag inside "${tagName}" cannot be empty.`,
|
84
|
+
};
|
85
|
+
ProductTemplateController.WARNINGS = {
|
86
|
+
scriptTag: 'Any "script" tags defined inside of "template" elements are not supported and will not be executed when the products are rendered.',
|
87
|
+
sectionMix: 'Product templates should only contain section elements or non-section elements. Future updates could unpredictably affect this product template.',
|
88
|
+
};
|
89
|
+
function getTemplateElement(host) {
|
90
|
+
return host.querySelector('template:not([slot])');
|
91
|
+
}
|
92
|
+
function groupNodesByType(nodes) {
|
93
|
+
return aggregate(Array.from(nodes), (node) => getTemplateNodeType(node));
|
29
94
|
}
|
package/dist/atomic/components/{stencil-result-template-common.js → result-template-common.js}
RENAMED
@@ -112,4 +112,4 @@ function makeDefinedConditions(ifDefined, ifNotDefined) {
|
|
112
112
|
|
113
113
|
export { ResultTemplateCommon as R, makeDefinedConditions as a, makeMatchConditions as m };
|
114
114
|
|
115
|
-
//# sourceMappingURL=
|
115
|
+
//# sourceMappingURL=result-template-common.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"file":"result-template-common.js","mappings":";;;;;;SA0BgB,mBAAmB,CAAC,IAAU;IAC5C,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE;QAC7B,OAAO,SAAS,CAAC;KAClB;IACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO,UAAU,CAAC;KACnB;IACD,IACE,aAAa,CAAC,IAAI,CAAC;QACnB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,mBAAmB,EAClD;QACA,OAAO,yBAAyB,CAAC;KAClC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAe;IACvC,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,KAAK,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3E,CAAC;MAEY,oBAAoB;IAK/B,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,UAAU,GAAG,KAAK,GACQ;QARrB,oBAAe,GAA8B,EAAE,CAAC;QAC/C,uBAAkB,GAAe,OAAO,CAAC;QAQ/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;K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,IAAiB;IAC3C,OAAO,IAAI,CAAC,aAAa,CAAsB,sBAAsB,CAAE,CAAC;AAC1E,CAAC;SAEe,mBAAmB,CACjC,SAAmC,EACnC,YAAsC;IAEtC,MAAM,UAAU,GAA8B,EAAE,CAAC;IACjD,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE;QAC7B,UAAU,CAAC,IAAI,CACb,sBAAsB,CAAC,cAAc,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAC/D,CAAC;KACH;IAED,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;QAChC,UAAU,CAAC,IAAI,CACb,sBAAsB,CAAC,iBAAiB,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CACrE,CAAC;KACH;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;SAEe,qBAAqB,CACnC,SAAkB,EAClB,YAAqB;IAErB,MAAM,UAAU,GAA8B,EAAE,CAAC;IACjD,IAAI,SAAS,EAAE;QACb,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACxC,UAAU,CAAC,IAAI,CAAC,sBAAsB,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC;KACzE;IAED,IAAI,YAAY,EAAE;QAChB,MAAM,UAAU,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3C,UAAU,CAAC,IAAI,CAAC,sBAAsB,CAAC,sBAAsB,CAAC,UAAU,CAAC,CAAC,CAAC;KAC5E;IACD,OAAO,UAAU,CAAC;AACpB;;;;","names":[],"sources":["src/components/common/result-templates/result-template-common.tsx"],"sourcesContent":["import {\n ResultTemplate,\n ResultTemplateCondition,\n ResultTemplatesHelpers,\n} from '@coveo/headless';\nimport {h} from '@stencil/core';\nimport {aggregate, isElementNode, isVisualNode} from '../../../utils/utils';\nimport {tableElementTagName} from '../../search/atomic-table-result/table-element-utils';\nimport {ItemTarget} from '../layout/display-options';\nimport {isResultSectionNode} from '../layout/item-layout-sections';\n\nexport type TemplateContent = DocumentFragment;\n\ninterface ResultTemplateCommonProps {\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\nexport class ResultTemplateCommon {\n private host: HTMLDivElement;\n public matchConditions: ResultTemplateCondition[] = [];\n private gridCellLinkTarget: ItemTarget = '_self';\n\n constructor({\n host,\n setError,\n validParents,\n allowEmpty = false,\n }: ResultTemplateCommonProps) {\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<HTMLTemplateElement>(\n 'template:not([slot])'\n );\n if (!template) {\n setError(\n new Error(\n `The \"${tagName}\" component has to 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 results 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 'Result templates should only contain section elements or non-section elements. Future updates could unpredictably affect this result template.',\n host,\n {sectionNodes, otherNodes}\n );\n }\n }\n\n getTemplate(\n conditions: ResultTemplateCondition[],\n error: Error\n ): ResultTemplate<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\n getDefaultLinkTemplateElement() {\n const linkTemplate = document.createElement('template');\n linkTemplate.innerHTML = `<atomic-result-link>${this.gridCellLinkTarget ? `<a slot=\"attributes\" target=\"${this.gridCellLinkTarget}\"></a>` : ''}</atomic-result-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 makeMatchConditions(\n mustMatch: Record<string, string[]>,\n mustNotMatch: Record<string, string[]>\n): ResultTemplateCondition[] {\n const conditions: ResultTemplateCondition[] = [];\n for (const field in mustMatch) {\n conditions.push(\n ResultTemplatesHelpers.fieldMustMatch(field, mustMatch[field])\n );\n }\n\n for (const field in mustNotMatch) {\n conditions.push(\n ResultTemplatesHelpers.fieldMustNotMatch(field, mustNotMatch[field])\n );\n }\n return conditions;\n}\n\nexport function makeDefinedConditions(\n ifDefined?: string,\n ifNotDefined?: string\n): ResultTemplateCondition[] {\n const conditions: ResultTemplateCondition[] = [];\n if (ifDefined) {\n const fieldNames = ifDefined.split(',');\n conditions.push(ResultTemplatesHelpers.fieldsMustBeDefined(fieldNames));\n }\n\n if (ifNotDefined) {\n const fieldNames = ifNotDefined.split(',');\n conditions.push(ResultTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));\n }\n return conditions;\n}\n"],"version":3}
|
@@ -1 +1 @@
|
|
1
|
-
{"file":"table-element-utils.js","mappings":"MAAa,mBAAmB,GAAG;;;;","names":[],"sources":["src/components/
|
1
|
+
{"file":"table-element-utils.js","mappings":"MAAa,mBAAmB,GAAG;;;;","names":[],"sources":["src/components/search/atomic-table-result/table-element-utils.ts"],"sourcesContent":["export const tableElementTagName = 'atomic-table-element';\n"],"version":3}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{ResultTemplatesHelpers as t}from"@coveo/headless";import{h as e}from"./p-dc3df5ce.js";import{a as n,i as o,b as r}from"./p-a12e1c59.js";import{t as s}from"./p-
|
2
|
-
//# sourceMappingURL=p-
|
1
|
+
import{ResultTemplatesHelpers as t}from"@coveo/headless";import{h as e}from"./p-dc3df5ce.js";import{a as n,i as o,b as r}from"./p-a12e1c59.js";import{t as s}from"./p-acd1a1d3.js";import{i}from"./p-dc28ee14.js";function a(t){if(i(t)){return"section"}if(!o(t)){return"metadata"}if(r(t)&&t.tagName.toLowerCase()===s){return"table-column-definition"}return"other"}function l(t){return n(Array.from(t),(t=>a(t)))}class c{constructor({host:t,setError:e,validParents:n,allowEmpty:o=false}){this.matchConditions=[];this.gridCellLinkTarget="_self";this.host=t;this.validateTemplate(t,e,n,o)}validateTemplate(t,e,n,o=true){const r=n.map((t=>t.toUpperCase())).includes(t.parentElement?.nodeName||"");const s=t.nodeName.toLowerCase();if(!r){e(new Error(`The "${s}" component has to be the child of one of the following: ${n.map((t=>`"${t.toLowerCase()}"`)).join(", ")}.`));return}if(t.parentElement?.attributes.getNamedItem("display")?.value==="grid"){this.gridCellLinkTarget=t.parentElement?.attributes.getNamedItem("grid-cell-link-target")?.value}const i=t.querySelector("template:not([slot])");if(!i){e(new Error(`The "${s}" component has to contain a "template" element as a child.`));return}if(!o&&!i.innerHTML.trim()){e(new Error(`The "template" tag inside "${s}" cannot be empty.`));return}if(i.content.querySelector("script")){console.warn('Any "script" tags defined inside of "template" elements are not supported and will not be executed when the results are rendered.',t)}const{section:a,other:c}=l(i.content.childNodes);if(a?.length&&c?.length){console.warn("Result templates should only contain section elements or non-section elements. Future updates could unpredictably affect this result template.",t,{sectionNodes:a,otherNodes:c})}}getTemplate(t,e){if(e){return null}return{conditions:t.concat(this.matchConditions),content:m(this.host).content,linkContent:this.getLinkTemplateElement(this.host).content,priority:1}}renderIfError(t){if(t){return e("atomic-component-error",{element:this.host,error:t})}}getDefaultLinkTemplateElement(){const t=document.createElement("template");t.innerHTML=`<atomic-result-link>${this.gridCellLinkTarget?`<a slot="attributes" target="${this.gridCellLinkTarget}"></a>`:""}</atomic-result-link>`;return t}getLinkTemplateElement(t){return t.querySelector('template[slot="link"]')??this.getDefaultLinkTemplateElement()}}function m(t){return t.querySelector("template:not([slot])")}function u(e,n){const o=[];for(const n in e){o.push(t.fieldMustMatch(n,e[n]))}for(const e in n){o.push(t.fieldMustNotMatch(e,n[e]))}return o}function f(e,n){const o=[];if(e){const n=e.split(",");o.push(t.fieldsMustBeDefined(n))}if(n){const e=n.split(",");o.push(t.fieldsMustNotBeDefined(e))}return o}export{c as R,f as a,u as m};
|
2
|
+
//# sourceMappingURL=p-2250f505.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["getTemplateNodeType","node","isResultSectionNode","isVisualNode","isElementNode","tagName","toLowerCase","tableElementTagName","groupNodesByType","nodes","aggregate","Array","from","ResultTemplateCommon","constructor","host","setError","validParents","allowEmpty","this","matchConditions","gridCellLinkTarget","validateTemplate","hasValidParent","map","p","toUpperCase","includes","parentElement","nodeName","Error","join","attributes","getNamedItem","value","template","querySelector","innerHTML","trim","content","console","warn","section","sectionNodes","other","otherNodes","childNodes","length","getTemplate","conditions","error","concat","getTemplateElement","linkContent","getLinkTemplateElement","priority","renderIfError","h","element","getDefaultLinkTemplateElement","linkTemplate","document","createElement","makeMatchConditions","mustMatch","mustNotMatch","field","push","ResultTemplatesHelpers","fieldMustMatch","fieldMustNotMatch","makeDefinedConditions","ifDefined","ifNotDefined","fieldNames","split","fieldsMustBeDefined","fieldsMustNotBeDefined"],"sources":["src/components/common/result-templates/result-template-common.tsx"],"sourcesContent":["import {\n ResultTemplate,\n ResultTemplateCondition,\n ResultTemplatesHelpers,\n} from '@coveo/headless';\nimport {h} from '@stencil/core';\nimport {aggregate, isElementNode, isVisualNode} from '../../../utils/utils';\nimport {tableElementTagName} from '../../search/atomic-table-result/table-element-utils';\nimport {ItemTarget} from '../layout/display-options';\nimport {isResultSectionNode} from '../layout/item-layout-sections';\n\nexport type TemplateContent = DocumentFragment;\n\ninterface ResultTemplateCommonProps {\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\nexport class ResultTemplateCommon {\n private host: HTMLDivElement;\n public matchConditions: ResultTemplateCondition[] = [];\n private gridCellLinkTarget: ItemTarget = '_self';\n\n constructor({\n host,\n setError,\n validParents,\n allowEmpty = false,\n }: ResultTemplateCommonProps) {\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<HTMLTemplateElement>(\n 'template:not([slot])'\n );\n if (!template) {\n setError(\n new Error(\n `The \"${tagName}\" component has to 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 results 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 'Result templates should only contain section elements or non-section elements. Future updates could unpredictably affect this result template.',\n host,\n {sectionNodes, otherNodes}\n );\n }\n }\n\n getTemplate(\n conditions: ResultTemplateCondition[],\n error: Error\n ): ResultTemplate<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\n getDefaultLinkTemplateElement() {\n const linkTemplate = document.createElement('template');\n linkTemplate.innerHTML = `<atomic-result-link>${this.gridCellLinkTarget ? `<a slot=\"attributes\" target=\"${this.gridCellLinkTarget}\"></a>` : ''}</atomic-result-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 makeMatchConditions(\n mustMatch: Record<string, string[]>,\n mustNotMatch: Record<string, string[]>\n): ResultTemplateCondition[] {\n const conditions: ResultTemplateCondition[] = [];\n for (const field in mustMatch) {\n conditions.push(\n ResultTemplatesHelpers.fieldMustMatch(field, mustMatch[field])\n );\n }\n\n for (const field in mustNotMatch) {\n conditions.push(\n ResultTemplatesHelpers.fieldMustNotMatch(field, mustNotMatch[field])\n );\n }\n return conditions;\n}\n\nexport function makeDefinedConditions(\n ifDefined?: string,\n ifNotDefined?: string\n): ResultTemplateCondition[] {\n const conditions: ResultTemplateCondition[] = [];\n if (ifDefined) {\n const fieldNames = ifDefined.split(',');\n conditions.push(ResultTemplatesHelpers.fieldsMustBeDefined(fieldNames));\n }\n\n if (ifNotDefined) {\n const fieldNames = ifNotDefined.split(',');\n conditions.push(ResultTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));\n }\n return conditions;\n}\n"],"mappings":"2NA0BgBA,EAAoBC,GAClC,GAAIC,EAAoBD,GAAO,CAC7B,MAAO,S,CAET,IAAKE,EAAaF,GAAO,CACvB,MAAO,U,CAET,GACEG,EAAcH,IACdA,EAAKI,QAAQC,gBAAkBC,EAC/B,CACA,MAAO,yB,CAET,MAAO,OACT,CAEA,SAASC,EAAiBC,GACxB,OAAOC,EAAUC,MAAMC,KAAKH,IAASR,GAASD,EAAoBC,IACpE,C,MAEaY,EAKX,WAAAC,EAAYC,KACVA,EAAIC,SACJA,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