@coveops/abi 0.1.0

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 (90) hide show
  1. package/.env.example +24 -0
  2. package/README.md +34 -0
  3. package/coveo.deploy.json +30 -0
  4. package/deployment.esbuild.mjs +54 -0
  5. package/dist/abi/abi.css +1 -0
  6. package/dist/abi/abi.esm.js +1 -0
  7. package/dist/abi/index.esm.js +1 -0
  8. package/dist/abi/p-0ae1e588.js +2 -0
  9. package/dist/abi/p-38555fec.js +1 -0
  10. package/dist/abi/p-424e40eb.entry.js +1 -0
  11. package/dist/abi/p-4da5a336.js +18 -0
  12. package/dist/abi/p-941f664c.entry.js +1 -0
  13. package/dist/abi/p-e5564016.entry.js +50 -0
  14. package/dist/bundle/index.css +1 -0
  15. package/dist/bundle/index.html +61 -0
  16. package/dist/bundle/index.js +673 -0
  17. package/dist/cjs/abi.cjs.js +19 -0
  18. package/dist/cjs/atomic-7321a250.js +7 -0
  19. package/dist/cjs/faq-popup-component.cjs.entry.js +106 -0
  20. package/dist/cjs/index-39c8295a.js +1753 -0
  21. package/dist/cjs/index-bea59ea1.js +1093 -0
  22. package/dist/cjs/index.cjs.js +18 -0
  23. package/dist/cjs/loader.cjs.js +21 -0
  24. package/dist/cjs/results-manager.cjs.entry.js +40 -0
  25. package/dist/cjs/sample-component.cjs.entry.js +146 -0
  26. package/dist/collection/collection-manifest.json +19 -0
  27. package/dist/collection/components/faq-popup-component/faq-popup-component.css +15 -0
  28. package/dist/collection/components/faq-popup-component/faq-popup-component.js +78 -0
  29. package/dist/collection/components/results-manager/results-manager.js +45 -0
  30. package/dist/collection/components/sample-component/sample-component.css +10 -0
  31. package/dist/collection/components/sample-component/sample-component.js +102 -0
  32. package/dist/collection/index.js +15 -0
  33. package/dist/collection/utils/atomic.js +3 -0
  34. package/dist/components/index.d.ts +57 -0
  35. package/dist/components/index.js +2999 -0
  36. package/dist/esm/abi.js +17 -0
  37. package/dist/esm/atomic-0e957d02.js +5 -0
  38. package/dist/esm/faq-popup-component.entry.js +102 -0
  39. package/dist/esm/index-51334f26.js +1065 -0
  40. package/dist/esm/index-9483cecb.js +1749 -0
  41. package/dist/esm/index.js +16 -0
  42. package/dist/esm/loader.js +17 -0
  43. package/dist/esm/polyfills/core-js.js +11 -0
  44. package/dist/esm/polyfills/css-shim.js +1 -0
  45. package/dist/esm/polyfills/dom.js +79 -0
  46. package/dist/esm/polyfills/es5-html-element.js +1 -0
  47. package/dist/esm/polyfills/index.js +34 -0
  48. package/dist/esm/polyfills/system.js +6 -0
  49. package/dist/esm/results-manager.entry.js +36 -0
  50. package/dist/esm/sample-component.entry.js +142 -0
  51. package/dist/index.cjs.js +1 -0
  52. package/dist/index.js +1 -0
  53. package/dist/loader/cdn.js +3 -0
  54. package/dist/loader/index.cjs.js +3 -0
  55. package/dist/loader/index.d.ts +12 -0
  56. package/dist/loader/index.es2017.js +3 -0
  57. package/dist/loader/index.js +4 -0
  58. package/dist/loader/package.json +10 -0
  59. package/dist/types/components/faq-popup-component/faq-popup-component.d.ts +10 -0
  60. package/dist/types/components/results-manager/results-manager.d.ts +8 -0
  61. package/dist/types/components/sample-component/sample-component.d.ts +25 -0
  62. package/dist/types/components.d.ts +63 -0
  63. package/dist/types/html.d.ts +4 -0
  64. package/dist/types/index.d.ts +1 -0
  65. package/dist/types/stencil-public-runtime.d.ts +1565 -0
  66. package/dist/types/utils/atomic.d.ts +1 -0
  67. package/package.json +31 -0
  68. package/src/components/faq-popup-component/faq-popup-component.css +15 -0
  69. package/src/components/faq-popup-component/faq-popup-component.tsx +102 -0
  70. package/src/components/results-manager/AppTemplate.html +44 -0
  71. package/src/components/results-manager/DocumentsTemplate.html +37 -0
  72. package/src/components/results-manager/ELearningTemplate.html +81 -0
  73. package/src/components/results-manager/FAQTemplate.html +73 -0
  74. package/src/components/results-manager/KATemplate.html +84 -0
  75. package/src/components/results-manager/MediaTemplate.html +40 -0
  76. package/src/components/results-manager/PeopleTemplate.html +74 -0
  77. package/src/components/results-manager/QuickLinksTemplate.html +51 -0
  78. package/src/components/results-manager/SitePagesTemplate.html +69 -0
  79. package/src/components/results-manager/results-manager.tsx +64 -0
  80. package/src/components/results-manager/template-1.html +67 -0
  81. package/src/components/sample-component/sample-component.css +10 -0
  82. package/src/components/sample-component/sample-component.tsx +157 -0
  83. package/src/components.d.ts +63 -0
  84. package/src/html.d.ts +4 -0
  85. package/src/index.ts +20 -0
  86. package/src/pages/index.html +137 -0
  87. package/src/style/index.css +12 -0
  88. package/src/utils/atomic.ts +3 -0
  89. package/stencil.config.ts +63 -0
  90. package/tsconfig.json +19 -0
@@ -0,0 +1,19 @@
1
+ {
2
+ "entries": [
3
+ "./components/faq-popup-component/faq-popup-component.js",
4
+ "./components/results-manager/results-manager.js",
5
+ "./components/sample-component/sample-component.js"
6
+ ],
7
+ "compiler": {
8
+ "name": "@stencil/core",
9
+ "version": "2.17.3",
10
+ "typescriptVersion": "4.5.4"
11
+ },
12
+ "collections": [
13
+ {
14
+ "name": "@coveo/atomic",
15
+ "tags": []
16
+ }
17
+ ],
18
+ "bundles": []
19
+ }
@@ -0,0 +1,15 @@
1
+ b {
2
+ color: var(--atomic-primary);
3
+ }
4
+ /* :host {
5
+ display: block;
6
+ }
7
+
8
+ .clickable-host {
9
+ cursor: pointer;
10
+ }
11
+
12
+ .clickable-host:hover {
13
+ cursor: pointer;
14
+ text-decoration: underline; /* Optional: adds underline on hover */
15
+ } */
@@ -0,0 +1,78 @@
1
+ import { Component, h, Element, State, Host } from "@stencil/core";
2
+ import { resultContext, initializeBindings } from "@coveo/atomic";
3
+ export class FaqPopupComponent {
4
+ constructor() {
5
+ this.closeFAQModal = () => {
6
+ this.modalElement.setAttribute('is-open', 'false');
7
+ this.modalElement.querySelector('#btn-done').removeEventListener('click', this.closeFAQModal);
8
+ };
9
+ }
10
+ // We recommended fetching the result context using the `connectedCallback` lifecycle method
11
+ // with async/await. Using `componentWillLoad` will hang the parent `atomic-search-interface` initialization.
12
+ async connectedCallback() {
13
+ var _a;
14
+ try {
15
+ this.bindings = await initializeBindings(this.host);
16
+ this.result = await resultContext(this.host);
17
+ this.modalElement = (_a = this.bindings) === null || _a === void 0 ? void 0 : _a.interfaceElement.querySelector('#faq-modal');
18
+ console.log("this.result", this.result, this.modalElement, this.bindings);
19
+ }
20
+ catch (error) {
21
+ console.error(error);
22
+ this.host.remove();
23
+ }
24
+ }
25
+ openFAQModal() {
26
+ var _a, _b, _c, _d;
27
+ this.modalElement.source = this.host;
28
+ this.modalElement.querySelector('[slot=header]').children[0].innerHTML = 'Question: ' + (((_a = this.result) === null || _a === void 0 ? void 0 : _a.title) || '');
29
+ // Get the body slot
30
+ const bodySlot = this.modalElement.querySelector('[slot=body]');
31
+ // Clear any existing content
32
+ bodySlot.innerHTML = '';
33
+ const answerElement = document.createElement('div');
34
+ answerElement.style.display = 'flex';
35
+ answerElement.style.gap = '16px';
36
+ // Create the answer title element and set its text
37
+ const answerTitleElement = document.createElement('div');
38
+ answerTitleElement.innerText = 'Answer:';
39
+ answerElement.appendChild(answerTitleElement);
40
+ // Get the answer from the result object
41
+ const answerContent = ((_b = this.result) === null || _b === void 0 ? void 0 : _b.raw.answer) || '';
42
+ // Create a new element to contain the answer content
43
+ const answerContentElement = document.createElement('div');
44
+ answerContentElement.innerHTML = answerContent;
45
+ // Append the answer content element to the answer element
46
+ answerElement.appendChild(answerContentElement);
47
+ // Now, the answer element has the title and the content properly appended
48
+ bodySlot.appendChild(answerElement);
49
+ // Create and append the category element
50
+ const categoryElement = document.createElement('div');
51
+ categoryElement.innerHTML = 'Category: ' + (((_c = this.result) === null || _c === void 0 ? void 0 : _c.raw.category) || '');
52
+ bodySlot.appendChild(categoryElement);
53
+ const linkElement = document.createElement('div');
54
+ const linkUrl = ((_d = this.result) === null || _d === void 0 ? void 0 : _d.raw.newmoreinfo) || '';
55
+ linkElement.innerHTML = `Link: <a href="${linkUrl}" target="_blank">${linkUrl}</a>`;
56
+ bodySlot.appendChild(linkElement);
57
+ this.modalElement.querySelector('#faq-modal-close').addEventListener('click', this.closeFAQModal);
58
+ this.modalElement.setAttribute('is-open', 'true');
59
+ }
60
+ render() {
61
+ if (!this.result) {
62
+ return;
63
+ }
64
+ return (h(Host, { className: "clickable-host", onClick: () => this.openFAQModal() }, this.result.title));
65
+ }
66
+ static get is() { return "faq-popup-component"; }
67
+ static get encapsulation() { return "shadow"; }
68
+ static get originalStyleUrls() { return {
69
+ "$": ["faq-popup-component.css"]
70
+ }; }
71
+ static get styleUrls() { return {
72
+ "$": ["faq-popup-component.css"]
73
+ }; }
74
+ static get states() { return {
75
+ "result": {}
76
+ }; }
77
+ static get elementRef() { return "host"; }
78
+ }
@@ -0,0 +1,45 @@
1
+ import { Component, h } from "@stencil/core";
2
+ import { waitForAtomic } from "../../utils/atomic";
3
+ import template1 from "./template-1.html";
4
+ import SitePagesTemplate from "./SitePagesTemplate.html";
5
+ import KATemplate from "./KATemplate.html";
6
+ import FAQTemplate from "./FAQTemplate.html";
7
+ import QuickLinksTemplate from "./QuickLinksTemplate.html";
8
+ import AppTemplate from "./AppTemplate.html";
9
+ import ELearningTemplate from "./ELearningTemplate.html";
10
+ import PeopleTemplate from "./PeopleTemplate.html";
11
+ import DocumentsTemplate from "./DocumentsTemplate.html";
12
+ import MediaTemplate from "./MediaTemplate.html";
13
+ /**
14
+ * Component used to manage results & result templates.
15
+ * See https://docs.coveo.com/en/atomic/latest/usage/create-a-result-list/
16
+ */
17
+ export class ResultsManager {
18
+ async componentWillLoad() {
19
+ return waitForAtomic();
20
+ }
21
+ render() {
22
+ return (h("atomic-result-list", null,
23
+ h("atomic-result-template", { "must-match-abicontenttype": "Site Pages" },
24
+ h("template", { innerHTML: SitePagesTemplate })),
25
+ h("atomic-result-template", { "must-match-abicontenttype": "Knowledge Article" },
26
+ h("template", { innerHTML: KATemplate })),
27
+ h("atomic-result-template", { "must-match-abicontenttype": 'FAQ' },
28
+ h("template", { innerHTML: FAQTemplate })),
29
+ h("atomic-result-template", { "must-match-abicontenttype": 'Quick Links' },
30
+ h("template", { innerHTML: QuickLinksTemplate })),
31
+ h("atomic-result-template", { "must-match-abicontenttype": 'Application' },
32
+ h("template", { innerHTML: AppTemplate })),
33
+ h("atomic-result-template", { "must-match-abicontenttype": 'eLearning' },
34
+ h("template", { innerHTML: ELearningTemplate })),
35
+ h("atomic-result-template", { "must-match-abicontenttype": 'People' },
36
+ h("template", { innerHTML: PeopleTemplate })),
37
+ h("atomic-result-template", { "must-match-abicontenttype": 'Documents' },
38
+ h("template", { innerHTML: DocumentsTemplate })),
39
+ h("atomic-result-template", { "must-match-abicontenttype": 'Media' },
40
+ h("template", { innerHTML: MediaTemplate })),
41
+ h("atomic-result-template", null,
42
+ h("template", { innerHTML: template1 }))));
43
+ }
44
+ static get is() { return "results-manager"; }
45
+ }
@@ -0,0 +1,10 @@
1
+ nav {
2
+ width: 300px;
3
+ display: flex;
4
+ justify-content: space-around;
5
+ }
6
+
7
+ button {
8
+ color: var(--atomic-on-primary);
9
+ background-color: var(--atomic-primary);
10
+ }
@@ -0,0 +1,102 @@
1
+ import { initializeBindings } from "@coveo/atomic";
2
+ import { Component, Element, h, State, forceUpdate } from "@stencil/core";
3
+ import { buildSearchStatus, buildPager, } from "@coveo/headless";
4
+ import { waitForAtomic } from "../../utils/atomic";
5
+ /**
6
+ * Sample custom Atomic component, initializing itself against a parent search interface in order to retrieve the bindings.
7
+ *
8
+ * This component showcases a custom-made pagination component, for educational purposes.
9
+ *
10
+ * In a real life scenario, we recommend using either [atomic-pager](https://docs.coveo.com/en/atomic/latest/reference/components/atomic-pager/) or [atomic-load-more-results](https://docs.coveo.com/en/atomic/latest/reference/components/atomic-load-more-results/) instead.
11
+ */
12
+ export class SampleComponent {
13
+ constructor() {
14
+ // When disconnecting components from the page, we recommend removing
15
+ // state change listeners as well by calling the unsubscribe methods.
16
+ this.pagerUnsubscribe = () => { };
17
+ this.statusUnsubscribe = () => { };
18
+ this.i18nUnsubscribe = () => { };
19
+ }
20
+ // We recommend initializing the bindings and the Headless controllers
21
+ // using the `connectedCallback` lifecycle method with async/await.
22
+ // Using `componentWillLoad` will hang the parent atomic-search-interface initialization.
23
+ async connectedCallback() {
24
+ try {
25
+ // Wait for the Atomic to load and bindings to be resolved.
26
+ await waitForAtomic();
27
+ this.bindings = await initializeBindings(this.host);
28
+ // Initialize controllers.
29
+ const statusController = buildSearchStatus(this.bindings.engine);
30
+ this.pagerController = buildPager(this.bindings.engine);
31
+ // Subscribe to controller state changes.
32
+ this.statusUnsubscribe = statusController.subscribe(() => (this.statusState = statusController.state));
33
+ this.pagerUnsubscribe = this.pagerController.subscribe(() => (this.pagerState = this.pagerController.state));
34
+ // (Optional) To use if component needs to rerender when the Atomic i18n language changes.
35
+ // If your component does not use any strings or does not support multiple languages,
36
+ // you can ignore everything related to i18n.
37
+ const updateLanguage = () => forceUpdate(this);
38
+ this.bindings.i18n.on("languageChanged", updateLanguage);
39
+ this.i18nUnsubscribe = () => this.bindings.i18n.off("languageChanged", updateLanguage);
40
+ }
41
+ catch (error) {
42
+ console.error(error);
43
+ this.error = error;
44
+ }
45
+ }
46
+ // The `disconnectedCallback` lifecycle method should be used to unsubcribe controllers and
47
+ // possibly the i18n language change listener.
48
+ disconnectedCallback() {
49
+ this.pagerUnsubscribe();
50
+ this.statusUnsubscribe();
51
+ this.i18nUnsubscribe();
52
+ }
53
+ get pages() {
54
+ const pages = this.pagerState.currentPages;
55
+ return pages.map((page) => this.buildPage(page));
56
+ }
57
+ buildPage(page) {
58
+ const isSelected = this.pagerController.isCurrentPage(page);
59
+ return (h("button", { onClick: () => {
60
+ this.pagerController.selectPage(page);
61
+ } },
62
+ isSelected ? "✓ " : "",
63
+ page.toLocaleString(this.bindings.i18n.language)));
64
+ }
65
+ get previous() {
66
+ return (h("button", { onClick: () => {
67
+ this.pagerController.previousPage();
68
+ } },
69
+ h("atomic-text", { value: "previous" })));
70
+ }
71
+ get next() {
72
+ return (h("button", { onClick: () => {
73
+ this.pagerController.nextPage();
74
+ } },
75
+ h("atomic-text", { value: "next" })));
76
+ }
77
+ render() {
78
+ if (this.error) {
79
+ return (h("p", null, "Error when initializing the component, please view the console for more information."));
80
+ }
81
+ if (!this.bindings || !this.statusState.hasResults) {
82
+ return;
83
+ }
84
+ return (h("nav", null,
85
+ this.pagerState.hasPreviousPage && this.previous,
86
+ this.pages,
87
+ this.pagerState.hasNextPage && this.next));
88
+ }
89
+ static get is() { return "sample-component"; }
90
+ static get encapsulation() { return "shadow"; }
91
+ static get originalStyleUrls() { return {
92
+ "$": ["sample-component.css"]
93
+ }; }
94
+ static get styleUrls() { return {
95
+ "$": ["sample-component.css"]
96
+ }; }
97
+ static get states() { return {
98
+ "pagerState": {},
99
+ "statusState": {}
100
+ }; }
101
+ static get elementRef() { return "host"; }
102
+ }
@@ -0,0 +1,15 @@
1
+ import { waitForAtomic } from "./utils/atomic";
2
+ async function main() {
3
+ await waitForAtomic();
4
+ const searchInterface = document.querySelector("atomic-search-interface");
5
+ const platformUrl = process.env.PLATFORM_URL;
6
+ const organizationId = process.env.ORGANIZATION_ID;
7
+ const accessToken = process.env.API_KEY;
8
+ await searchInterface.initialize({
9
+ accessToken,
10
+ organizationId,
11
+ platformUrl,
12
+ });
13
+ searchInterface.executeFirstSearch();
14
+ }
15
+ main();
@@ -0,0 +1,3 @@
1
+ export function waitForAtomic() {
2
+ return customElements.whenDefined("atomic-search-interface");
3
+ }
@@ -0,0 +1,57 @@
1
+ /* abi custom elements bundle */
2
+
3
+ import type { Components, JSX } from "../types/html";
4
+
5
+ interface FaqPopupComponent extends Components.FaqPopupComponent, HTMLElement {}
6
+ export const FaqPopupComponent: {
7
+ prototype: FaqPopupComponent;
8
+ new (): FaqPopupComponent;
9
+ };
10
+
11
+ interface ResultsManager extends Components.ResultsManager, HTMLElement {}
12
+ export const ResultsManager: {
13
+ prototype: ResultsManager;
14
+ new (): ResultsManager;
15
+ };
16
+
17
+ interface SampleComponent extends Components.SampleComponent, HTMLElement {}
18
+ export const SampleComponent: {
19
+ prototype: SampleComponent;
20
+ new (): SampleComponent;
21
+ };
22
+
23
+ /**
24
+ * Utility to define all custom elements within this package using the tag name provided in the component's source.
25
+ * When defining each custom element, it will also check it's safe to define by:
26
+ *
27
+ * 1. Ensuring the "customElements" registry is available in the global context (window).
28
+ * 2. The component tag name is not already defined.
29
+ *
30
+ * Use the standard [customElements.define()](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define)
31
+ * method instead to define custom elements individually, or to provide a different tag name.
32
+ */
33
+ export declare const defineCustomElements: (opts?: any) => void;
34
+
35
+ /**
36
+ * Used to manually set the base path where assets can be found.
37
+ * If the script is used as "module", it's recommended to use "import.meta.url",
38
+ * such as "setAssetPath(import.meta.url)". Other options include
39
+ * "setAssetPath(document.currentScript.src)", or using a bundler's replace plugin to
40
+ * dynamically set the path at build time, such as "setAssetPath(process.env.ASSET_PATH)".
41
+ * But do note that this configuration depends on how your script is bundled, or lack of
42
+ * bunding, and where your assets can be loaded from. Additionally custom bundling
43
+ * will have to ensure the static assets are copied to its build directory.
44
+ */
45
+ export declare const setAssetPath: (path: string) => void;
46
+
47
+ export interface SetPlatformOptions {
48
+ raf?: (c: FrameRequestCallback) => number;
49
+ ael?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
50
+ rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
51
+ ce?: (eventName: string, opts?: any) => CustomEvent;
52
+ }
53
+ export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;
54
+
55
+ export type { Components, JSX };
56
+
57
+ export * from '../types';