@coveo/atomic 3.34.0-pre.a9fe0810fa → 3.34.0-pre.af804ee661

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.
Files changed (122) hide show
  1. package/dist/atomic/_atomic.esm.js +1 -1
  2. package/dist/atomic/components/analytics-config.js +1 -1
  3. package/dist/atomic/components/atomic-field-condition.js +1 -1
  4. package/dist/atomic/components/atomic-field-condition.js.map +1 -1
  5. package/dist/atomic/components/atomic-insight-result-children-template.js +1 -1
  6. package/dist/atomic/components/atomic-insight-result-children-template.js.map +1 -1
  7. package/dist/atomic/components/atomic-insight-result-template.js +1 -1
  8. package/dist/atomic/components/atomic-insight-result-template.js.map +1 -1
  9. package/dist/atomic/components/atomic-recs-result-template.js +1 -1
  10. package/dist/atomic/components/atomic-recs-result-template.js.map +1 -1
  11. package/dist/atomic/components/atomic-result-children-template.js +1 -1
  12. package/dist/atomic/components/atomic-result-children-template.js.map +1 -1
  13. package/dist/atomic/components/atomic-result-list.js.map +1 -1
  14. package/dist/atomic/components/atomic-result-template.js +1 -1
  15. package/dist/atomic/components/atomic-result-template.js.map +1 -1
  16. package/dist/atomic/components/components/commerce/atomic-product-field-condition/atomic-product-field-condition.js +4 -3
  17. package/dist/atomic/components/components/commerce/atomic-product-template/atomic-product-template.js +4 -3
  18. package/dist/atomic/components/components/common/item-list/table-layout.js +1 -1
  19. package/dist/atomic/components/components/common/product-template/product-template-controller.js +16 -81
  20. package/dist/atomic/components/components/common/template-controller/base-template-controller.js +89 -0
  21. package/dist/atomic/components/components/common/{product-template/product-template-common.js → template-controller/template-utils.js} +11 -12
  22. package/dist/atomic/components/global/environment.js +1 -1
  23. package/dist/atomic/components/{result-template-common.js → stencil-result-template-common.js} +1 -1
  24. package/dist/atomic/components/stencil-result-template-common.js.map +1 -0
  25. package/dist/atomic/components/table-element-utils.js.map +1 -1
  26. package/dist/atomic/{p-07e869dc.entry.js → p-13d55b17.entry.js} +2 -2
  27. package/dist/atomic/{p-7fd5b6ac.entry.js → p-2213060b.entry.js} +2 -2
  28. package/dist/atomic/p-2213060b.entry.js.map +1 -0
  29. package/dist/atomic/{p-e7a25b00.entry.js → p-2895c42c.entry.js} +2 -2
  30. package/dist/atomic/p-2895c42c.entry.js.map +1 -0
  31. package/dist/atomic/{p-2250f505.js → p-4da8f827.js} +2 -2
  32. package/dist/atomic/p-4da8f827.js.map +1 -0
  33. package/dist/atomic/{p-41c35d48.js → p-56609107.js} +2 -2
  34. package/dist/atomic/{p-62e85c20.entry.js → p-6694e114.entry.js} +2 -2
  35. package/dist/atomic/p-6694e114.entry.js.map +1 -0
  36. package/dist/atomic/{p-a1e5f767.entry.js → p-86f950a5.entry.js} +2 -2
  37. package/dist/atomic/p-86f950a5.entry.js.map +1 -0
  38. package/dist/atomic/{p-373448df.entry.js → p-a46d36dd.entry.js} +2 -2
  39. package/dist/atomic/p-a46d36dd.entry.js.map +1 -0
  40. package/dist/atomic/{p-acd1a1d3.js → p-be0518ae.js} +1 -1
  41. package/dist/atomic/p-be0518ae.js.map +1 -0
  42. package/dist/atomic/{p-3a830dfe.entry.js → p-dba59af6.entry.js} +2 -2
  43. package/dist/atomic/{p-9260dd7d.entry.js → p-ebd00891.entry.js} +2 -2
  44. package/dist/atomic/p-ebd00891.entry.js.map +1 -0
  45. package/dist/atomic/{p-af1b4924.entry.js → p-f676b5ba.entry.js} +2 -2
  46. package/dist/atomic/p-f676b5ba.entry.js.map +1 -0
  47. package/dist/cjs/{analytics-config-1c5ebc92.js → analytics-config-90eba384.js} +2 -2
  48. package/dist/cjs/{analytics-config-1c5ebc92.js.map → analytics-config-90eba384.js.map} +1 -1
  49. package/dist/cjs/atomic-field-condition.cjs.entry.js +3 -3
  50. package/dist/cjs/atomic-field-condition.cjs.entry.js.map +1 -1
  51. package/dist/cjs/atomic-insight-interface.cjs.entry.js +1 -1
  52. package/dist/cjs/atomic-insight-result-children-template.cjs.entry.js +5 -5
  53. package/dist/cjs/atomic-insight-result-children-template.cjs.entry.js.map +1 -1
  54. package/dist/cjs/atomic-insight-result-template.cjs.entry.js +5 -5
  55. package/dist/cjs/atomic-insight-result-template.cjs.entry.js.map +1 -1
  56. package/dist/cjs/atomic-recs-interface.cjs.entry.js +1 -1
  57. package/dist/cjs/atomic-recs-result-template.cjs.entry.js +5 -5
  58. package/dist/cjs/atomic-recs-result-template.cjs.entry.js.map +1 -1
  59. package/dist/cjs/atomic-result-children-template.cjs.entry.js +4 -4
  60. package/dist/cjs/atomic-result-children-template.cjs.entry.js.map +1 -1
  61. package/dist/cjs/atomic-result-list.cjs.entry.js +1 -1
  62. package/dist/cjs/atomic-result-list.cjs.entry.js.map +1 -1
  63. package/dist/cjs/atomic-result-template.cjs.entry.js +4 -4
  64. package/dist/cjs/atomic-result-template.cjs.entry.js.map +1 -1
  65. package/dist/cjs/{result-template-common-84bd4057.js → stencil-result-template-common-bb38948f.js} +2 -2
  66. package/dist/cjs/stencil-result-template-common-bb38948f.js.map +1 -0
  67. package/dist/cjs/{table-element-utils-4865b735.js → table-element-utils-2cc6dc82.js} +1 -1
  68. package/dist/cjs/table-element-utils-2cc6dc82.js.map +1 -0
  69. package/dist/cjs/version.cjs.js +1 -1
  70. package/dist/esm/{analytics-config-291aa687.js → analytics-config-f1c30920.js} +2 -2
  71. package/dist/esm/{analytics-config-291aa687.js.map → analytics-config-f1c30920.js.map} +1 -1
  72. package/dist/esm/atomic-field-condition.entry.js +2 -2
  73. package/dist/esm/atomic-field-condition.entry.js.map +1 -1
  74. package/dist/esm/atomic-insight-interface.entry.js +1 -1
  75. package/dist/esm/atomic-insight-result-children-template.entry.js +2 -2
  76. package/dist/esm/atomic-insight-result-children-template.entry.js.map +1 -1
  77. package/dist/esm/atomic-insight-result-template.entry.js +2 -2
  78. package/dist/esm/atomic-insight-result-template.entry.js.map +1 -1
  79. package/dist/esm/atomic-recs-interface.entry.js +1 -1
  80. package/dist/esm/atomic-recs-result-template.entry.js +2 -2
  81. package/dist/esm/atomic-recs-result-template.entry.js.map +1 -1
  82. package/dist/esm/atomic-result-children-template.entry.js +2 -2
  83. package/dist/esm/atomic-result-children-template.entry.js.map +1 -1
  84. package/dist/esm/atomic-result-list.entry.js +1 -1
  85. package/dist/esm/atomic-result-list.entry.js.map +1 -1
  86. package/dist/esm/atomic-result-template.entry.js +2 -2
  87. package/dist/esm/atomic-result-template.entry.js.map +1 -1
  88. package/dist/esm/{result-template-common-995b94f8.js → stencil-result-template-common-19af5cfb.js} +2 -2
  89. package/dist/esm/stencil-result-template-common-19af5cfb.js.map +1 -0
  90. package/dist/esm/{table-element-utils-49d22ec6.js → table-element-utils-1dbc5ef6.js} +1 -1
  91. package/dist/esm/table-element-utils-1dbc5ef6.js.map +1 -0
  92. package/dist/esm/version.js +1 -1
  93. package/dist/types/components/common/product-template/product-template-controller.d.ts +9 -19
  94. package/dist/types/components/common/product-template/stencil-product-template-common.d.ts +1 -1
  95. package/dist/types/components/common/result-templates/result-template-controller.d.ts +16 -0
  96. package/dist/types/components/common/template-controller/base-template-controller.d.ts +36 -0
  97. package/dist/types/components/common/template-controller/template-utils.d.ts +11 -0
  98. package/dist/types/components/insight/result-templates/atomic-insight-result-children-template/atomic-insight-result-children-template.d.ts +1 -1
  99. package/dist/types/components/search/result-templates/atomic-result-children-template/atomic-result-children-template.d.ts +1 -1
  100. package/docs/atomic-docs.json +1 -1
  101. package/package.json +1 -1
  102. package/dist/atomic/components/result-template-common.js.map +0 -1
  103. package/dist/atomic/p-2250f505.js.map +0 -1
  104. package/dist/atomic/p-373448df.entry.js.map +0 -1
  105. package/dist/atomic/p-62e85c20.entry.js.map +0 -1
  106. package/dist/atomic/p-7fd5b6ac.entry.js.map +0 -1
  107. package/dist/atomic/p-9260dd7d.entry.js.map +0 -1
  108. package/dist/atomic/p-a1e5f767.entry.js.map +0 -1
  109. package/dist/atomic/p-acd1a1d3.js.map +0 -1
  110. package/dist/atomic/p-af1b4924.entry.js.map +0 -1
  111. package/dist/atomic/p-e7a25b00.entry.js.map +0 -1
  112. package/dist/cjs/result-template-common-84bd4057.js.map +0 -1
  113. package/dist/cjs/table-element-utils-4865b735.js.map +0 -1
  114. package/dist/esm/result-template-common-995b94f8.js.map +0 -1
  115. package/dist/esm/table-element-utils-49d22ec6.js.map +0 -1
  116. package/dist/types/components/common/product-template/product-template-common.d.ts +0 -6
  117. /package/dist/atomic/components/components/{search/atomic-table-result → common}/table-element-utils.js +0 -0
  118. /package/dist/atomic/{p-07e869dc.entry.js.map → p-13d55b17.entry.js.map} +0 -0
  119. /package/dist/atomic/{p-41c35d48.js.map → p-56609107.js.map} +0 -0
  120. /package/dist/atomic/{p-3a830dfe.entry.js.map → p-dba59af6.entry.js.map} +0 -0
  121. /package/dist/types/components/common/result-templates/{result-template-common.d.ts → stencil-result-template-common.d.ts} +0 -0
  122. /package/dist/types/components/{search/atomic-table-result → common}/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/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}
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/stencil-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,14 +4,15 @@ 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';
7
8
  import { html, LitElement } from 'lit';
8
9
  import { customElement, property, state } from 'lit/decorators.js';
10
+ import { makeDefinedConditions, makeMatchConditions, } from "../../common/template-controller/template-utils";
9
11
  import { bindings } from "../../../decorators/bindings";
10
12
  import { createProductContextController } from "../../../decorators/commerce/product-template-decorators";
11
13
  import { errorGuard } from "../../../decorators/error-guard";
12
14
  import { LightDomMixin } from "../../../mixins/light-dom";
13
15
  import { mapProperty } from "../../../utils/props-utils";
14
- import { makeDefinedConditions, makeMatchConditions, } from '../../common/product-template/product-template-common';
15
16
  /**
16
17
  * The `atomic-product-field-condition` component renders its children only when all of the conditions specified through its props are satisfied.
17
18
  * The condition properties can be based on any top-level product property of the `product` object, not restricted to fields (e.g., `ec_name`).
@@ -26,8 +27,8 @@ let AtomicProductFieldCondition = class AtomicProductFieldCondition extends Ligh
26
27
  initialize() { }
27
28
  get conditions() {
28
29
  return [
29
- ...makeDefinedConditions(this.ifDefined, this.ifNotDefined),
30
- ...makeMatchConditions(this.mustMatch, this.mustNotMatch),
30
+ ...makeDefinedConditions(this.ifDefined, this.ifNotDefined, ProductTemplatesHelpers),
31
+ ...makeMatchConditions(this.mustMatch, this.mustNotMatch, ProductTemplatesHelpers),
31
32
  ];
32
33
  }
33
34
  render() {
@@ -4,12 +4,13 @@ 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';
7
8
  import { html, LitElement, nothing } from 'lit';
8
9
  import { customElement, property, state } from 'lit/decorators.js';
10
+ import { ProductTemplateController } from "../../common/product-template/product-template-controller";
11
+ import { makeMatchConditions } from "../../common/template-controller/template-utils";
9
12
  import { errorGuard } from "../../../decorators/error-guard";
10
13
  import { mapProperty } from "../../../utils/props-utils";
11
- import { makeMatchConditions } from '../../common/product-template/product-template-common';
12
- import { ProductTemplateController } from '../../common/product-template/product-template-controller';
13
14
  import '../atomic-product/atomic-product';
14
15
  /**
15
16
  * * A product template determines the format of the products, depending on the conditions that are defined for each template.
@@ -43,7 +44,7 @@ let AtomicProductTemplate = class AtomicProductTemplate extends LitElement {
43
44
  }
44
45
  connectedCallback() {
45
46
  super.connectedCallback();
46
- this.productTemplateController.matchConditions = makeMatchConditions(this.mustMatch, this.mustNotMatch);
47
+ this.productTemplateController.matchConditions = makeMatchConditions(this.mustMatch, this.mustNotMatch, ProductTemplatesHelpers);
47
48
  }
48
49
  /**
49
50
  * 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 '../../search/atomic-table-result/table-element-utils';
5
+ import { tableElementTagName } from '../table-element-utils';
6
6
  export const renderTableLayout = ({ props }) => {
7
7
  const { host, listClasses, logger } = props;
8
8
  const fieldColumns = getFieldTableColumns(props);
@@ -1,94 +1,29 @@
1
- import { aggregate } from '../../../utils/utils';
2
- import { getTemplateNodeType } from './product-template-common';
3
- export class ProductTemplateController {
1
+ import { BaseTemplateController, } from "../template-controller/base-template-controller";
2
+ export class ProductTemplateController extends BaseTemplateController {
4
3
  constructor(host, validParents, allowEmpty = false) {
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
- }
4
+ super(host, validParents, allowEmpty);
47
5
  }
48
6
  getTemplate(conditions) {
49
- if (this.host.error) {
7
+ const baseTemplate = this.getBaseTemplate(conditions);
8
+ if (!baseTemplate) {
50
9
  return null;
51
10
  }
52
11
  return {
53
- conditions: conditions.concat(this.matchConditions),
54
- content: getTemplateElement(this.host).content,
55
- linkContent: this.getLinkTemplateElement(this.host).content,
56
- priority: 1,
12
+ conditions: baseTemplate.conditions,
13
+ content: baseTemplate.content,
14
+ linkContent: baseTemplate.linkContent,
15
+ priority: baseTemplate.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.',
57
22
  };
58
23
  }
59
24
  getDefaultLinkTemplateElement() {
60
25
  const linkTemplate = document.createElement('template');
61
- linkTemplate.innerHTML = `<atomic-product-link>${this.gridCellLinkTarget ? `<a slot="attributes" target="${this.gridCellLinkTarget}"></a>` : ''}</atomic-product-link>`;
26
+ linkTemplate.innerHTML = `<atomic-product-link>${this.currentGridCellLinkTarget ? `<a slot="attributes" target="${this.currentGridCellLinkTarget}"></a>` : ''}</atomic-product-link>`;
62
27
  return linkTemplate;
63
28
  }
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));
94
29
  }
@@ -0,0 +1,89 @@
1
+ import { aggregate } from "../../../utils/utils";
2
+ import { getTemplateNodeType } from './template-utils';
3
+ export class BaseTemplateController {
4
+ constructor(host, validParents, allowEmpty = false) {
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
+ getLinkTemplateElement(host) {
15
+ return (host.querySelector('template[slot="link"]') ??
16
+ this.getDefaultLinkTemplateElement());
17
+ }
18
+ setError(error) {
19
+ this.host.error = error;
20
+ }
21
+ getBaseTemplate(conditions) {
22
+ if (this.host.error) {
23
+ return null;
24
+ }
25
+ return {
26
+ conditions: conditions.concat(this.matchConditions),
27
+ content: getTemplateElement(this.host).content,
28
+ linkContent: this.getLinkTemplateElement(this.host).content,
29
+ priority: 1,
30
+ };
31
+ }
32
+ get parentElement() {
33
+ return this.host.parentElement;
34
+ }
35
+ get template() {
36
+ return this.host.querySelector('template');
37
+ }
38
+ parentAttr(attribute) {
39
+ return this.parentElement?.attributes.getNamedItem(attribute)?.value;
40
+ }
41
+ get currentGridCellLinkTarget() {
42
+ return this.gridCellLinkTarget;
43
+ }
44
+ validateTemplate() {
45
+ const hasValidParent = this.validParents
46
+ .map((p) => p.toUpperCase())
47
+ .includes(this.parentElement?.nodeName || '');
48
+ const tagName = this.host.nodeName.toLowerCase();
49
+ if (!hasValidParent) {
50
+ this.setError(new Error(BaseTemplateController.ERRORS.invalidParent(tagName, this.validParents)));
51
+ return;
52
+ }
53
+ if (this.parentAttr('display') === 'grid') {
54
+ this.gridCellLinkTarget = this.parentAttr('grid-cell-link-target');
55
+ }
56
+ if (!this.template) {
57
+ this.setError(new Error(BaseTemplateController.ERRORS.missingTemplate(tagName)));
58
+ return;
59
+ }
60
+ if (!this.allowEmpty && !this.template.innerHTML.trim()) {
61
+ this.setError(new Error(BaseTemplateController.ERRORS.emptyTemplate(tagName)));
62
+ return;
63
+ }
64
+ const warnings = this.getWarnings();
65
+ if (this.template.content.querySelector('script')) {
66
+ console.warn(warnings.scriptTag, this.host);
67
+ }
68
+ const { section, other } = groupNodesByType(this.template.content.childNodes);
69
+ if (section?.length && other?.length) {
70
+ console.warn(warnings.sectionMix, this.host, {
71
+ section,
72
+ other,
73
+ });
74
+ }
75
+ }
76
+ }
77
+ BaseTemplateController.ERRORS = {
78
+ invalidParent: (tagName, validParents) => `The "${tagName}" component has to be the child of one of the following: ${validParents
79
+ .map((p) => `"${p.toLowerCase()}"`)
80
+ .join(', ')}.`,
81
+ missingTemplate: (tagName) => `The "${tagName}" component must contain a "template" element as a child.`,
82
+ emptyTemplate: (tagName) => `The "template" tag inside "${tagName}" cannot be empty.`,
83
+ };
84
+ function getTemplateElement(host) {
85
+ return host.querySelector('template:not([slot])');
86
+ }
87
+ function groupNodesByType(nodes) {
88
+ return aggregate(Array.from(nodes), (node) => getTemplateNodeType(node));
89
+ }
@@ -1,8 +1,7 @@
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';
1
+ import { isResultSectionNode } from "../layout/item-layout-sections";
2
+ import { tableElementTagName } from "../table-element-utils";
3
+ import { intersection } from "../../../utils/set";
4
+ import { isElementNode, isVisualNode } from "../../../utils/utils";
6
5
  export function getTemplateNodeType(node) {
7
6
  if (isResultSectionNode(node)) {
8
7
  return 'section';
@@ -16,7 +15,7 @@ export function getTemplateNodeType(node) {
16
15
  }
17
16
  return 'other';
18
17
  }
19
- export function makeMatchConditions(mustMatch, mustNotMatch) {
18
+ export function makeMatchConditions(mustMatch, mustNotMatch, helpers) {
20
19
  const conditions = [];
21
20
  for (const field in mustMatch) {
22
21
  if (mustNotMatch[field]) {
@@ -25,25 +24,25 @@ export function makeMatchConditions(mustMatch, mustNotMatch) {
25
24
  const commonValues = intersection(mustNotMatchValues, mustMatchValues);
26
25
  if (commonValues.size > 0) {
27
26
  console.error(`Conflicting match conditions for field ${field}, the template will be ignored.`, commonValues);
28
- return [() => false];
27
+ return [(() => false)];
29
28
  }
30
29
  }
31
- conditions.push(ProductTemplatesHelpers.fieldMustMatch(field, mustMatch[field]));
30
+ conditions.push(helpers.fieldMustMatch(field, mustMatch[field]));
32
31
  }
33
32
  for (const field in mustNotMatch) {
34
- conditions.push(ProductTemplatesHelpers.fieldMustNotMatch(field, mustNotMatch[field]));
33
+ conditions.push(helpers.fieldMustNotMatch(field, mustNotMatch[field]));
35
34
  }
36
35
  return conditions;
37
36
  }
38
- export function makeDefinedConditions(ifDefined, ifNotDefined) {
37
+ export function makeDefinedConditions(ifDefined, ifNotDefined, helpers) {
39
38
  const conditions = [];
40
39
  if (ifDefined) {
41
40
  const fieldNames = ifDefined.split(',');
42
- conditions.push(ProductTemplatesHelpers.fieldsMustBeDefined(fieldNames));
41
+ conditions.push(helpers.fieldsMustBeDefined(fieldNames));
43
42
  }
44
43
  if (ifNotDefined) {
45
44
  const fieldNames = ifNotDefined.split(',');
46
- conditions.push(ProductTemplatesHelpers.fieldsMustNotBeDefined(fieldNames));
45
+ conditions.push(helpers.fieldsMustNotBeDefined(fieldNames));
47
46
  }
48
47
  return conditions;
49
48
  }
@@ -3,7 +3,7 @@ function getWindow() {
3
3
  }
4
4
  export function getAtomicEnvironment(headlessVersion) {
5
5
  return {
6
- version: "3.34.0-pre.a9fe0810fa",
6
+ version: "3.34.0-pre.af804ee661",
7
7
  headlessVersion,
8
8
  };
9
9
  }
@@ -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=result-template-common.js.map
115
+ //# sourceMappingURL=stencil-result-template-common.js.map
@@ -0,0 +1 @@
1
+ {"file":"stencil-result-template-common.js","mappings":";;;;;;SA0BgB,mBAAmB,CAAC,IAAU;IAC5C,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE;QAC7B,OAAO,SAAS,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AqB,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/stencil-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 '../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/search/atomic-table-result/table-element-utils.ts"],"sourcesContent":["export const tableElementTagName = 'atomic-table-element';\n"],"version":3}
1
+ {"file":"table-element-utils.js","mappings":"MAAa,mBAAmB,GAAG;;;;","names":[],"sources":["src/components/common/table-element-utils.ts"],"sourcesContent":["export const tableElementTagName = 'atomic-table-element';\n"],"version":3}