@coveo/atomic 3.49.0 → 3.51.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.
- package/custom-elements.json +2257 -369
- package/dist/atomic/_atomic.esm.js +1 -1
- package/dist/atomic/atomic.esm.js.map +1 -1
- package/dist/atomic/components/_index.d.ts +0 -10
- package/dist/atomic/components/_index.js +2 -8
- package/dist/atomic/components/atomic-insight-result-action.js +123 -6
- package/dist/atomic/components/atomic-insight-result-action.js.map +1 -1
- package/dist/atomic/components/atomic-insight-result-children-template.js +1 -2
- package/dist/atomic/components/atomic-insight-result-children-template.js.map +1 -1
- package/dist/atomic/components/atomic-insight-timeframe-facet.js +97 -7
- package/dist/atomic/components/atomic-insight-timeframe-facet.js.map +1 -1
- package/dist/atomic/components/atomic-stencil-facet-date-input.js +3 -3
- package/dist/atomic/components/components/commerce/atomic-commerce-search-box/atomic-commerce-search-box.js +4 -4
- package/dist/atomic/components/components/common/generated-answer/render-feedback-and-copy-buttons.js +4 -3
- package/dist/atomic/components/components/insight/atomic-insight-generated-answer/atomic-insight-generated-answer.js +444 -0
- package/dist/atomic/components/components/insight/atomic-insight-generated-answer/atomic-insight-generated-answer.tw.css.js +2 -0
- package/dist/atomic/components/components/insight/atomic-insight-result-attach-to-case-action/atomic-insight-result-attach-to-case-action.js +122 -0
- package/dist/atomic/components/components/insight/atomic-insight-result-children/atomic-insight-result-children.js +4 -4
- package/dist/atomic/components/components/insight/index.js +2 -0
- package/dist/atomic/components/components/insight/lazy-index.js +2 -0
- package/dist/atomic/components/components/ipx/atomic-ipx-button/atomic-ipx-button.js +1 -1
- package/dist/atomic/components/components/ipx/atomic-ipx-recs-list/atomic-ipx-recs-list.js +483 -0
- package/dist/atomic/components/components/ipx/atomic-ipx-refine-modal/atomic-ipx-refine-modal.js +202 -0
- package/dist/atomic/components/components/ipx/atomic-ipx-refine-toggle/atomic-ipx-refine-toggle.js +123 -0
- package/dist/atomic/components/components/ipx/index.js +3 -0
- package/dist/atomic/components/components/ipx/lazy-index.js +3 -0
- package/dist/atomic/components/components/recommendations/atomic-recs-result/atomic-recs-result.js +1 -0
- package/dist/atomic/components/components/search/atomic-generated-answer/atomic-generated-answer.js +7 -1
- package/dist/atomic/components/components/search/atomic-refine-modal/atomic-refine-modal.js +2 -1
- package/dist/atomic/components/components/search/atomic-search-box/atomic-search-box.js +4 -4
- package/dist/atomic/components/global/environment.js +1 -1
- package/dist/atomic/components/index.js.map +1 -1
- package/dist/atomic/components/props-utils.js +1402 -2
- package/dist/atomic/components/props-utils.js.map +1 -1
- package/dist/atomic/components/utils/custom-element-tags.js +7 -0
- package/dist/atomic/components/utils/tailwind.global.tw.css.js +4 -4
- package/dist/atomic/index.esm.js +1 -1
- package/dist/atomic/p-1df0744f.entry.js +9 -0
- package/dist/atomic/p-1df0744f.entry.js.map +1 -0
- package/dist/atomic/{p-4a32511f.js → p-2045a1b1.js} +2 -2
- package/dist/atomic/p-500bf5c4.entry.js +2 -0
- package/dist/atomic/{p-4117289b.entry.js.map → p-500bf5c4.entry.js.map} +1 -1
- package/dist/atomic/p-5226a938.js +3 -0
- package/dist/atomic/p-5226a938.js.map +1 -0
- package/dist/atomic/{p-b4cfedf1.js → p-720863c3.js} +2 -2
- package/dist/atomic/p-81336626.entry.js +2 -0
- package/dist/atomic/p-81336626.entry.js.map +1 -0
- package/dist/atomic/p-aad3b4ec.js +3 -0
- package/dist/atomic/p-aad3b4ec.js.map +1 -0
- package/dist/atomic/{p-0698ccf1.entry.js → p-b5af331b.entry.js} +2 -2
- package/dist/atomic/{p-677f9c40.js → p-b7209471.js} +2 -2
- package/dist/cjs/_index.cjs.js +2 -2
- package/dist/cjs/_loader.cjs.js +2 -2
- package/dist/cjs/atomic-insight-result-action.cjs.entry.js +22 -9
- package/dist/cjs/atomic-insight-result-action.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-insight-result-children-template.cjs.entry.js +6 -7
- package/dist/cjs/atomic-insight-result-children-template.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-insight-timeframe-facet.cjs.entry.js +106 -16
- package/dist/cjs/atomic-insight-timeframe-facet.cjs.entry.js.map +1 -1
- package/dist/cjs/atomic-stencil-facet-date-input.cjs.entry.js +5 -5
- package/dist/cjs/atomic.cjs.js +2 -2
- package/dist/cjs/{index-3532822e.js → index-122375df.js} +4 -58
- package/dist/cjs/index-122375df.js.map +1 -0
- package/dist/cjs/{initialization-utils-51a423fe.js → initialization-utils-c2821271.js} +2 -2
- package/dist/cjs/{initialization-utils-51a423fe.js.map → initialization-utils-c2821271.js.map} +1 -1
- package/dist/cjs/{utils-e845f262.js → props-utils-e4f29f1e.js} +54 -21
- package/dist/cjs/props-utils-e4f29f1e.js.map +1 -0
- package/dist/cjs/{stencil-button-f39da03e.js → stencil-button-bf22eea4.js} +2 -2
- package/dist/cjs/{stencil-button-f39da03e.js.map → stencil-button-bf22eea4.js.map} +1 -1
- package/dist/cjs/{stencil-result-template-decorators-1f099c15.js → stencil-result-template-decorators-96954751.js} +2 -2
- package/dist/cjs/{stencil-result-template-decorators-1f099c15.js.map → stencil-result-template-decorators-96954751.js.map} +1 -1
- package/dist/cjs/version.cjs.js +2 -2
- package/dist/esm/_index.js +3 -3
- package/dist/esm/_loader.js +3 -3
- package/dist/esm/atomic-insight-result-action.entry.js +20 -7
- package/dist/esm/atomic-insight-result-action.entry.js.map +1 -1
- package/dist/esm/atomic-insight-result-children-template.entry.js +2 -3
- package/dist/esm/atomic-insight-result-children-template.entry.js.map +1 -1
- package/dist/esm/atomic-insight-timeframe-facet.entry.js +100 -10
- package/dist/esm/atomic-insight-timeframe-facet.entry.js.map +1 -1
- package/dist/esm/atomic-stencil-facet-date-input.entry.js +5 -5
- package/dist/esm/atomic.js +3 -3
- package/dist/esm/{index-3eb0b28e.js → index-4d679e44.js} +5 -58
- package/dist/{cjs/index-3532822e.js.map → esm/index-4d679e44.js.map} +1 -1
- package/dist/esm/{initialization-utils-82d28c63.js → initialization-utils-9ff399ff.js} +2 -2
- package/dist/esm/{initialization-utils-82d28c63.js.map → initialization-utils-9ff399ff.js.map} +1 -1
- package/dist/esm/{utils-b5bab369.js → props-utils-76043c82.js} +54 -18
- package/dist/esm/props-utils-76043c82.js.map +1 -0
- package/dist/esm/{stencil-button-c25899df.js → stencil-button-28de709c.js} +2 -2
- package/dist/esm/{stencil-button-c25899df.js.map → stencil-button-28de709c.js.map} +1 -1
- package/dist/esm/{stencil-result-template-decorators-9cbe1e1c.js → stencil-result-template-decorators-4c2e5132.js} +2 -2
- package/dist/esm/{stencil-result-template-decorators-9cbe1e1c.js.map → stencil-result-template-decorators-4c2e5132.js.map} +1 -1
- package/dist/esm/version.js +2 -2
- package/dist/types/components/common/generated-answer/answerContent/answer-content.d.ts +49 -0
- package/dist/types/components/common/generated-answer/generated-answer-thread-item/generated-answer-thread-item.d.ts +49 -0
- package/dist/types/components/common/generated-answer/render-feedback-and-copy-buttons.d.ts +8 -2
- package/dist/types/components/common/item-list/table-layout.d.ts +1 -1
- package/dist/types/components/insight/atomic-insight-generated-answer/atomic-insight-generated-answer.d.ts +54 -35
- package/dist/types/components/insight/atomic-insight-generated-answer/atomic-insight-generated-answer.tw.css.d.ts +2 -0
- package/dist/types/components/insight/atomic-insight-result-attach-to-case-action/atomic-insight-result-attach-to-case-action.d.ts +25 -20
- package/dist/types/components/insight/index.d.ts +2 -0
- package/dist/types/components/ipx/atomic-ipx-button/atomic-ipx-button.d.ts +1 -1
- package/dist/types/components/ipx/atomic-ipx-recs-list/{atomic-recs-list/atomic-ipx-recs-list.d.ts → atomic-ipx-recs-list.d.ts} +43 -21
- package/dist/types/components/ipx/atomic-ipx-refine-modal/atomic-ipx-refine-modal.d.ts +62 -15
- package/dist/types/components/ipx/atomic-ipx-refine-toggle/atomic-ipx-refine-toggle.d.ts +26 -11
- package/dist/types/components/ipx/index.d.ts +3 -0
- package/dist/types/components/recommendations/atomic-recs-result/atomic-recs-result.d.ts +1 -0
- package/dist/types/components/search/atomic-refine-modal/atomic-refine-modal.d.ts +4 -3
- package/dist/types/components.d.ts +0 -249
- package/docs/atomic-docs.json +1 -26
- package/package.json +4 -4
- package/dist/atomic/components/arrow-top-rounded.js +0 -7
- package/dist/atomic/components/arrow-top-rounded.js.map +0 -1
- package/dist/atomic/components/atomic-insight-generated-answer.d.ts +0 -11
- package/dist/atomic/components/atomic-insight-generated-answer.js +0 -3264
- package/dist/atomic/components/atomic-insight-generated-answer.js.map +0 -1
- package/dist/atomic/components/atomic-insight-result-attach-to-case-action.d.ts +0 -11
- package/dist/atomic/components/atomic-insight-result-attach-to-case-action.js +0 -102
- package/dist/atomic/components/atomic-insight-result-attach-to-case-action.js.map +0 -1
- package/dist/atomic/components/atomic-ipx-recs-list.d.ts +0 -11
- package/dist/atomic/components/atomic-ipx-recs-list.js +0 -631
- package/dist/atomic/components/atomic-ipx-recs-list.js.map +0 -1
- package/dist/atomic/components/atomic-ipx-refine-modal.d.ts +0 -11
- package/dist/atomic/components/atomic-ipx-refine-modal.js +0 -8
- package/dist/atomic/components/atomic-ipx-refine-modal.js.map +0 -1
- package/dist/atomic/components/atomic-ipx-refine-modal2.js +0 -162
- package/dist/atomic/components/atomic-ipx-refine-modal2.js.map +0 -1
- package/dist/atomic/components/atomic-ipx-refine-toggle.d.ts +0 -11
- package/dist/atomic/components/atomic-ipx-refine-toggle.js +0 -121
- package/dist/atomic/components/atomic-ipx-refine-toggle.js.map +0 -1
- package/dist/atomic/components/attach.js +0 -115
- package/dist/atomic/components/attach.js.map +0 -1
- package/dist/atomic/components/components/common/layout/display-options.js +0 -28
- package/dist/atomic/components/popover-type.js +0 -12
- package/dist/atomic/components/popover-type.js.map +0 -1
- package/dist/atomic/components/stencil-heading.js +0 -169
- package/dist/atomic/components/stencil-heading.js.map +0 -1
- package/dist/atomic/components/stencil-iconButton.js +0 -16
- package/dist/atomic/components/stencil-iconButton.js.map +0 -1
- package/dist/atomic/components/store.js +0 -13
- package/dist/atomic/components/store.js.map +0 -1
- package/dist/atomic/components/utils.js +0 -1421
- package/dist/atomic/components/utils.js.map +0 -1
- package/dist/atomic/p-2c08a419.entry.js +0 -2
- package/dist/atomic/p-2c08a419.entry.js.map +0 -1
- package/dist/atomic/p-4117289b.entry.js +0 -2
- package/dist/atomic/p-52d14165.entry.js +0 -2
- package/dist/atomic/p-52d14165.entry.js.map +0 -1
- package/dist/atomic/p-578d761c.js +0 -2
- package/dist/atomic/p-578d761c.js.map +0 -1
- package/dist/atomic/p-64f83898.entry.js +0 -2
- package/dist/atomic/p-64f83898.entry.js.map +0 -1
- package/dist/atomic/p-70cc18a1.js +0 -2
- package/dist/atomic/p-70cc18a1.js.map +0 -1
- package/dist/atomic/p-9c5ec170.js +0 -2
- package/dist/atomic/p-9c5ec170.js.map +0 -1
- package/dist/atomic/p-9dfe5ab1.js +0 -2
- package/dist/atomic/p-9dfe5ab1.js.map +0 -1
- package/dist/atomic/p-a33748a9.js +0 -2
- package/dist/atomic/p-a33748a9.js.map +0 -1
- package/dist/atomic/p-b09433bb.js +0 -3
- package/dist/atomic/p-b09433bb.js.map +0 -1
- package/dist/atomic/p-c8452548.entry.js +0 -2
- package/dist/atomic/p-c8452548.entry.js.map +0 -1
- package/dist/atomic/p-c95ac794.entry.js +0 -2
- package/dist/atomic/p-c95ac794.entry.js.map +0 -1
- package/dist/atomic/p-d75a4630.js +0 -2
- package/dist/atomic/p-d75a4630.js.map +0 -1
- package/dist/atomic/p-d8230482.entry.js +0 -9
- package/dist/atomic/p-d8230482.entry.js.map +0 -1
- package/dist/atomic/p-e94ba0e1.entry.js +0 -2
- package/dist/atomic/p-e94ba0e1.entry.js.map +0 -1
- package/dist/atomic/p-ec1c5f46.js +0 -3
- package/dist/atomic/p-ec1c5f46.js.map +0 -1
- package/dist/atomic/p-f321aab0.js +0 -2
- package/dist/atomic/p-f321aab0.js.map +0 -1
- package/dist/cjs/arrow-top-rounded-885250ea.js +0 -10
- package/dist/cjs/arrow-top-rounded-885250ea.js.map +0 -1
- package/dist/cjs/atomic-insight-generated-answer.cjs.entry.js +0 -3238
- package/dist/cjs/atomic-insight-generated-answer.cjs.entry.js.map +0 -1
- package/dist/cjs/atomic-insight-result-attach-to-case-action.cjs.entry.js +0 -90
- package/dist/cjs/atomic-insight-result-attach-to-case-action.cjs.entry.js.map +0 -1
- package/dist/cjs/atomic-ipx-recs-list.cjs.entry.js +0 -600
- package/dist/cjs/atomic-ipx-recs-list.cjs.entry.js.map +0 -1
- package/dist/cjs/atomic-ipx-refine-modal.cjs.entry.js +0 -143
- package/dist/cjs/atomic-ipx-refine-modal.cjs.entry.js.map +0 -1
- package/dist/cjs/atomic-ipx-refine-toggle.cjs.entry.js +0 -99
- package/dist/cjs/atomic-ipx-refine-toggle.cjs.entry.js.map +0 -1
- package/dist/cjs/attach-19283bec.js +0 -10
- package/dist/cjs/attach-19283bec.js.map +0 -1
- package/dist/cjs/popover-type-22f285e1.js +0 -16
- package/dist/cjs/popover-type-22f285e1.js.map +0 -1
- package/dist/cjs/props-utils-bc5feb04.js +0 -59
- package/dist/cjs/props-utils-bc5feb04.js.map +0 -1
- package/dist/cjs/stencil-heading-ecec9ab3.js +0 -174
- package/dist/cjs/stencil-heading-ecec9ab3.js.map +0 -1
- package/dist/cjs/stencil-iconButton-f8b9fda0.js +0 -18
- package/dist/cjs/stencil-iconButton-f8b9fda0.js.map +0 -1
- package/dist/cjs/store-70fff5e6.js +0 -16
- package/dist/cjs/store-70fff5e6.js.map +0 -1
- package/dist/cjs/utils-e845f262.js.map +0 -1
- package/dist/esm/arrow-top-rounded-745b84a6.js +0 -7
- package/dist/esm/arrow-top-rounded-745b84a6.js.map +0 -1
- package/dist/esm/atomic-insight-generated-answer.entry.js +0 -3234
- package/dist/esm/atomic-insight-generated-answer.entry.js.map +0 -1
- package/dist/esm/atomic-insight-result-attach-to-case-action.entry.js +0 -86
- package/dist/esm/atomic-insight-result-attach-to-case-action.entry.js.map +0 -1
- package/dist/esm/atomic-ipx-recs-list.entry.js +0 -596
- package/dist/esm/atomic-ipx-recs-list.entry.js.map +0 -1
- package/dist/esm/atomic-ipx-refine-modal.entry.js +0 -139
- package/dist/esm/atomic-ipx-refine-modal.entry.js.map +0 -1
- package/dist/esm/atomic-ipx-refine-toggle.entry.js +0 -95
- package/dist/esm/atomic-ipx-refine-toggle.entry.js.map +0 -1
- package/dist/esm/attach-81bb8872.js +0 -8
- package/dist/esm/attach-81bb8872.js.map +0 -1
- package/dist/esm/index-3eb0b28e.js.map +0 -1
- package/dist/esm/popover-type-c85677ef.js +0 -12
- package/dist/esm/popover-type-c85677ef.js.map +0 -1
- package/dist/esm/props-utils-d343133b.js +0 -57
- package/dist/esm/props-utils-d343133b.js.map +0 -1
- package/dist/esm/stencil-heading-98a5f23f.js +0 -169
- package/dist/esm/stencil-heading-98a5f23f.js.map +0 -1
- package/dist/esm/stencil-iconButton-ed5804d3.js +0 -16
- package/dist/esm/stencil-iconButton-ed5804d3.js.map +0 -1
- package/dist/esm/store-50d170c8.js +0 -13
- package/dist/esm/store-50d170c8.js.map +0 -1
- package/dist/esm/utils-b5bab369.js.map +0 -1
- /package/dist/atomic/{p-4a32511f.js.map → p-2045a1b1.js.map} +0 -0
- /package/dist/atomic/{p-b4cfedf1.js.map → p-720863c3.js.map} +0 -0
- /package/dist/atomic/{p-0698ccf1.entry.js.map → p-b5af331b.entry.js.map} +0 -0
- /package/dist/atomic/{p-677f9c40.js.map → p-b7209471.js.map} +0 -0
|
@@ -8,9 +8,10 @@ import { hasClipboardSupport } from './generated-answer-utils';
|
|
|
8
8
|
* Renders the feedback (like/dislike) and copy-to-clipboard buttons.
|
|
9
9
|
*/
|
|
10
10
|
export const renderFeedbackAndCopyButtons = ({ props }) => {
|
|
11
|
-
const { i18n,
|
|
12
|
-
const { liked, disliked, answer, isStreaming } =
|
|
13
|
-
|
|
11
|
+
const { i18n, generatedAnswerActionsState, copied, copyError, getCopyToClipboardTooltip, onClickLike, onClickDislike, onCopyToClipboard, } = props;
|
|
12
|
+
const { liked, disliked, answer, isStreaming, isLoading } = generatedAnswerActionsState ?? {};
|
|
13
|
+
const shouldShowButtons = !!answer && !isStreaming && !isLoading;
|
|
14
|
+
return html `${when(shouldShowButtons, () => html `
|
|
14
15
|
<div
|
|
15
16
|
class="${classMap({
|
|
16
17
|
'feedback-buttons flex h-9 items-center shrink-0 gap-2': true,
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var AtomicInsightGeneratedAnswer_1;
|
|
8
|
+
import { NumberValue, Schema } from '@coveo/bueno';
|
|
9
|
+
import { buildGeneratedAnswer as buildInsightGeneratedAnswer, buildInteractiveCitation as buildInsightInteractiveCitation, buildSearchStatus as buildInsightSearchStatus, } from '@coveo/headless/insight';
|
|
10
|
+
import { html, LitElement, nothing } from 'lit';
|
|
11
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
12
|
+
import { when } from 'lit/directives/when.js';
|
|
13
|
+
import { GeneratedAnswerController } from "../../common/generated-answer/generated-answer-controller";
|
|
14
|
+
import { renderAnswerContent } from "../../common/generated-answer/render-answer-content";
|
|
15
|
+
import { renderCardHeader } from "../../common/generated-answer/render-card-header";
|
|
16
|
+
import { renderCitations } from "../../common/generated-answer/render-citations";
|
|
17
|
+
import { renderCustomNoAnswerMessage } from "../../common/generated-answer/render-custom-no-answer-message";
|
|
18
|
+
import { renderDisclaimer } from "../../common/generated-answer/render-disclaimer";
|
|
19
|
+
import { renderFeedbackAndCopyButtons } from "../../common/generated-answer/render-feedback-and-copy-buttons";
|
|
20
|
+
import { ValidatePropsController } from "../../common/validate-props-controller/validate-props-controller";
|
|
21
|
+
import { booleanConverter } from "../../../converters/boolean-converter";
|
|
22
|
+
import { createLegacyArrayStringConverter } from "../../../converters/legacy-array-string-converter";
|
|
23
|
+
import { bindStateToController } from "../../../decorators/bind-state";
|
|
24
|
+
import { bindingGuard } from "../../../decorators/binding-guard";
|
|
25
|
+
import { bindings } from "../../../decorators/bindings";
|
|
26
|
+
import { errorGuard } from "../../../decorators/error-guard";
|
|
27
|
+
import { withTailwindStyles } from "../../../decorators/with-tailwind-styles";
|
|
28
|
+
import { AriaLiveRegionController } from "../../../utils/accessibility-utils";
|
|
29
|
+
import { debounce } from "../../../utils/debounce-utils";
|
|
30
|
+
import { getNamedSlotContent } from "../../../utils/slot-utils";
|
|
31
|
+
import atomicInsightGeneratedAnswerStyles from './atomic-insight-generated-answer.tw.css.js';
|
|
32
|
+
/**
|
|
33
|
+
* The `atomic-insight-generated-answer` component uses Coveo Machine Learning (Coveo ML) models to automatically generate an answer to a query executed by the user.
|
|
34
|
+
* For more information, see [About Relevance Generative Answering (RGA)](https://docs.coveo.com/en/n9de0370/)
|
|
35
|
+
*
|
|
36
|
+
* @slot no-answer-message - Lets you pass a custom sorry message when no answer is generated.
|
|
37
|
+
*
|
|
38
|
+
* @part container - The container displaying the generated answer.
|
|
39
|
+
* @part header-label - The header of the generated answer container.
|
|
40
|
+
* @part feedback-button - The "like" and "dislike" buttons.
|
|
41
|
+
* @part toggle - The switch to toggle the visibility of the generated answer.
|
|
42
|
+
* @part copy-button - The "Copy answer" button.
|
|
43
|
+
* @part retry-container - The container for the "retry" section.
|
|
44
|
+
* @part generated-text - The text of the generated answer.
|
|
45
|
+
* @part citations-label - The header of the citations list.
|
|
46
|
+
*
|
|
47
|
+
* @part answer-code-block - The generated answer multi-line code blocks.
|
|
48
|
+
* @part answer-emphasis - The generated answer emphasized text elements.
|
|
49
|
+
* @part answer-inline-code - The generated answer inline code elements.
|
|
50
|
+
* @part answer-heading-1 - The generated answer level 1 heading elements.
|
|
51
|
+
* @part answer-heading-2 - The generated answer level 2 heading elements.
|
|
52
|
+
* @part answer-heading-3 - The generated answer level 3 heading elements.
|
|
53
|
+
* @part answer-heading-4 - The generated answer level 4 heading elements.
|
|
54
|
+
* @part answer-heading-5 - The generated answer level 5 heading elements.
|
|
55
|
+
* @part answer-heading-6 - The generated answer level 6 heading elements.
|
|
56
|
+
* @part answer-list-item - The generated answer list item elements for both ordered and unordered lists.
|
|
57
|
+
* @part answer-ordered-list - The generated answer ordered list elements.
|
|
58
|
+
* @part answer-paragraph - The generated answer paragraph elements.
|
|
59
|
+
* @part answer-quote-block - The generated answer quote block elements.
|
|
60
|
+
* @part answer-unordered-list - The generated answer unordered list elements.
|
|
61
|
+
* @part answer-strong - The generated answer strong text elements.
|
|
62
|
+
* @part answer-table - The generated answer table elements.
|
|
63
|
+
* @part answer-table-container - The generated answer table container elements.
|
|
64
|
+
* @part answer-table-content - The generated answer table content cell elements.
|
|
65
|
+
* @part answer-table-header - The generated answer table header cell elements.
|
|
66
|
+
*
|
|
67
|
+
* @part citation - The link that allows the user to navigate to the item.
|
|
68
|
+
* @part citation-popover - The pop-up that shows an item preview when the user hovers over the citation.
|
|
69
|
+
*/
|
|
70
|
+
let AtomicInsightGeneratedAnswer = AtomicInsightGeneratedAnswer_1 = class AtomicInsightGeneratedAnswer extends LitElement {
|
|
71
|
+
constructor() {
|
|
72
|
+
super();
|
|
73
|
+
this.DEFAULT_COLLAPSED_HEIGHT = 16;
|
|
74
|
+
this.MAX_COLLAPSED_HEIGHT = 32;
|
|
75
|
+
this.MIN_COLLAPSED_HEIGHT = 9;
|
|
76
|
+
this.REQUIRED_FIELDS_TO_INCLUDE_IN_CITATIONS = ['filetype'];
|
|
77
|
+
/**
|
|
78
|
+
* Whether to render a toggle button that lets the user hide or show the answer.
|
|
79
|
+
*/
|
|
80
|
+
this.withToggle = false;
|
|
81
|
+
/**
|
|
82
|
+
* Whether to allow the answer to be collapsed when the text is taller than the specified `--atomic-crga-collapsed-height` value (16rem by default).
|
|
83
|
+
*/
|
|
84
|
+
this.collapsible = false;
|
|
85
|
+
/**
|
|
86
|
+
* The maximum height (in rem units) of the answer when collapsed.
|
|
87
|
+
*/
|
|
88
|
+
this.maxCollapsedHeight = this.DEFAULT_COLLAPSED_HEIGHT;
|
|
89
|
+
/**
|
|
90
|
+
* Whether to disable citation anchoring.
|
|
91
|
+
*/
|
|
92
|
+
this.disableCitationAnchoring = false;
|
|
93
|
+
this.copied = false;
|
|
94
|
+
this.copyError = false;
|
|
95
|
+
this.ariaMessage = new AriaLiveRegionController(this, 'generated-answer');
|
|
96
|
+
// Used by bindStateToController decorator via onUpdateCallbackMethod option
|
|
97
|
+
this.onGeneratedAnswerStateUpdate = () => {
|
|
98
|
+
if (this.generatedAnswerState.isVisible !== this.controller.data.isVisible) {
|
|
99
|
+
this.controller.data = {
|
|
100
|
+
...this.controller.data,
|
|
101
|
+
isVisible: this.generatedAnswerState.isVisible,
|
|
102
|
+
};
|
|
103
|
+
this.controller.writeStoredData(this.controller.data);
|
|
104
|
+
}
|
|
105
|
+
this.ariaMessage.message = this.controller.getGeneratedAnswerStatus();
|
|
106
|
+
};
|
|
107
|
+
new ValidatePropsController(this, () => ({ maxCollapsedHeight: this.maxCollapsedHeight }), AtomicInsightGeneratedAnswer_1.propsSchema,
|
|
108
|
+
// TODO: V4: KIT-5197 - Remove skipValidation flag
|
|
109
|
+
false);
|
|
110
|
+
}
|
|
111
|
+
initialize() {
|
|
112
|
+
this.controller = new GeneratedAnswerController(this, {
|
|
113
|
+
withToggle: this.withToggle,
|
|
114
|
+
getGeneratedAnswer: () => this.generatedAnswer,
|
|
115
|
+
getGeneratedAnswerState: () => this.generatedAnswerState,
|
|
116
|
+
getSearchStatusState: () => this.searchStatusState,
|
|
117
|
+
getBindings: () => this.bindings,
|
|
118
|
+
});
|
|
119
|
+
this.generatedAnswer = buildInsightGeneratedAnswer(this.bindings.engine, {
|
|
120
|
+
initialState: {
|
|
121
|
+
isVisible: this.controller.data.isVisible,
|
|
122
|
+
responseFormat: {
|
|
123
|
+
contentFormat: ['text/markdown', 'text/plain'],
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
...(this.answerConfigurationId && {
|
|
127
|
+
answerConfigurationId: this.answerConfigurationId,
|
|
128
|
+
}),
|
|
129
|
+
fieldsToIncludeInCitations: this.getCitationFields(),
|
|
130
|
+
});
|
|
131
|
+
this.searchStatus = buildInsightSearchStatus(this.bindings.engine);
|
|
132
|
+
this.controller.insertFeedbackModal();
|
|
133
|
+
if (window.ResizeObserver && this.collapsible) {
|
|
134
|
+
const debouncedAdaptAnswerHeight = debounce(() => this.adaptAnswerHeight(), 100);
|
|
135
|
+
this.resizeObserver = new ResizeObserver(debouncedAdaptAnswerHeight);
|
|
136
|
+
this.resizeObserver.observe(this);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
disconnectedCallback() {
|
|
140
|
+
super.disconnectedCallback();
|
|
141
|
+
this.resizeObserver?.disconnect();
|
|
142
|
+
}
|
|
143
|
+
willUpdate(changedProperties) {
|
|
144
|
+
if (changedProperties.has('generatedAnswerState')) {
|
|
145
|
+
const oldState = changedProperties.get('generatedAnswerState');
|
|
146
|
+
if (oldState &&
|
|
147
|
+
this.generatedAnswerState?.expanded !== oldState?.expanded) {
|
|
148
|
+
const container = this.getAnswerContainer();
|
|
149
|
+
if (container) {
|
|
150
|
+
this.toggleClass(container, 'answer-collapsed', !this.generatedAnswerState.expanded);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
render() {
|
|
156
|
+
const contentClasses = 'mx-auto mt-0 mb-4 border border-neutral shadow-lg bg-background rounded-lg text-on-background';
|
|
157
|
+
if (this.hasNoAnswerGenerated) {
|
|
158
|
+
if (this.generatedAnswerState?.cannotAnswer &&
|
|
159
|
+
this.hasCustomNoAnswerMessage) {
|
|
160
|
+
return html `
|
|
161
|
+
<div>
|
|
162
|
+
<aside
|
|
163
|
+
class=${contentClasses}
|
|
164
|
+
part="container"
|
|
165
|
+
aria-label=${this.bindings.i18n.t('generated-answer-title')}
|
|
166
|
+
>
|
|
167
|
+
<div part="generated-content">
|
|
168
|
+
${this.renderCardHeaderWrapper()}
|
|
169
|
+
${when(this.isAnswerVisible, () => html `<article>${renderCustomNoAnswerMessage()}</article>`)}
|
|
170
|
+
</div>
|
|
171
|
+
</aside>
|
|
172
|
+
</div>
|
|
173
|
+
`;
|
|
174
|
+
}
|
|
175
|
+
return nothing;
|
|
176
|
+
}
|
|
177
|
+
return html `
|
|
178
|
+
<div>
|
|
179
|
+
<aside
|
|
180
|
+
class=${contentClasses}
|
|
181
|
+
part="container"
|
|
182
|
+
aria-label=${this.bindings.i18n.t('generated-answer-title')}
|
|
183
|
+
>
|
|
184
|
+
<div part="generated-content">
|
|
185
|
+
${this.renderCardHeaderWrapper()}
|
|
186
|
+
${when(this.isAnswerVisible, () => html ` <div part="generated-content-container" class="px-6 pb-6">
|
|
187
|
+
<article>${this.renderContent()}</article>
|
|
188
|
+
${renderDisclaimer({
|
|
189
|
+
props: {
|
|
190
|
+
i18n: this.bindings.i18n,
|
|
191
|
+
isStreaming: !!this.generatedAnswerState.isStreaming,
|
|
192
|
+
},
|
|
193
|
+
})}
|
|
194
|
+
</div>`)}
|
|
195
|
+
</div>
|
|
196
|
+
</aside>
|
|
197
|
+
</div>
|
|
198
|
+
`;
|
|
199
|
+
}
|
|
200
|
+
get hasNoAnswerGenerated() {
|
|
201
|
+
return this.controller.hasNoAnswerGenerated;
|
|
202
|
+
}
|
|
203
|
+
get isAnswerVisible() {
|
|
204
|
+
return this.controller.isAnswerVisible;
|
|
205
|
+
}
|
|
206
|
+
get toggleTooltip() {
|
|
207
|
+
return this.controller.getToggleTooltip();
|
|
208
|
+
}
|
|
209
|
+
get copyToClipboardTooltip() {
|
|
210
|
+
return this.controller.getCopyToClipboardTooltip(this.copied, this.copyError);
|
|
211
|
+
}
|
|
212
|
+
get hasCustomNoAnswerMessage() {
|
|
213
|
+
return getNamedSlotContent(this, 'no-answer-message').length > 0;
|
|
214
|
+
}
|
|
215
|
+
async copyToClipboard(answer) {
|
|
216
|
+
await this.controller.copyToClipboard(answer, () => {
|
|
217
|
+
this.copied = true;
|
|
218
|
+
setTimeout(() => {
|
|
219
|
+
this.copied = false;
|
|
220
|
+
}, 2000);
|
|
221
|
+
}, () => {
|
|
222
|
+
this.copyError = true;
|
|
223
|
+
setTimeout(() => {
|
|
224
|
+
this.copyError = false;
|
|
225
|
+
}, 2000);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
clickOnShowButton() {
|
|
229
|
+
this.controller.clickOnShowButton();
|
|
230
|
+
}
|
|
231
|
+
getCitationFields() {
|
|
232
|
+
// Defensive: handle both string and array for backward compatibility
|
|
233
|
+
// TODO V4 (KIT-5306): remove string handling
|
|
234
|
+
let fields = [];
|
|
235
|
+
if (Array.isArray(this.fieldsToIncludeInCitations)) {
|
|
236
|
+
fields = this.fieldsToIncludeInCitations;
|
|
237
|
+
}
|
|
238
|
+
else if (typeof this.fieldsToIncludeInCitations === 'string') {
|
|
239
|
+
fields = this.fieldsToIncludeInCitations
|
|
240
|
+
.split(',')
|
|
241
|
+
.map((f) => f.trim())
|
|
242
|
+
.filter((f) => f.length > 0);
|
|
243
|
+
}
|
|
244
|
+
return fields.concat(this.REQUIRED_FIELDS_TO_INCLUDE_IN_CITATIONS);
|
|
245
|
+
}
|
|
246
|
+
validateMaxCollapsedHeight() {
|
|
247
|
+
const isValid = this.maxCollapsedHeight >= this.MIN_COLLAPSED_HEIGHT &&
|
|
248
|
+
this.maxCollapsedHeight <= this.MAX_COLLAPSED_HEIGHT;
|
|
249
|
+
if (!isValid) {
|
|
250
|
+
console.warn(`max-collapsed-height (${this.maxCollapsedHeight}rem) is out of the valid range (${this.MIN_COLLAPSED_HEIGHT}rem - ${this.MAX_COLLAPSED_HEIGHT}rem). Falling back to default value (${this.DEFAULT_COLLAPSED_HEIGHT}rem).`);
|
|
251
|
+
}
|
|
252
|
+
return isValid ? this.maxCollapsedHeight : this.DEFAULT_COLLAPSED_HEIGHT;
|
|
253
|
+
}
|
|
254
|
+
toggleClass(element, className, condition) {
|
|
255
|
+
element.classList.toggle(className, condition);
|
|
256
|
+
}
|
|
257
|
+
adaptAnswerHeight() {
|
|
258
|
+
const answerHeight = this.shadowRoot
|
|
259
|
+
?.querySelector('[part="generated-text"]')
|
|
260
|
+
?.getBoundingClientRect().height;
|
|
261
|
+
if (answerHeight) {
|
|
262
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
263
|
+
this.fullAnswerHeight = answerHeight / rootFontSize;
|
|
264
|
+
this.updateAnswerHeight();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
getAnswerContainer() {
|
|
268
|
+
return this.shadowRoot?.querySelector('[part="generated-container"]');
|
|
269
|
+
}
|
|
270
|
+
getAnswerFooter() {
|
|
271
|
+
return this.shadowRoot?.querySelector('[part="generated-answer-footer"]');
|
|
272
|
+
}
|
|
273
|
+
setCSSVariable(variableName, value) {
|
|
274
|
+
const container = this.getAnswerContainer();
|
|
275
|
+
if (container) {
|
|
276
|
+
container.style.setProperty(variableName, value);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
updateAnswerHeight() {
|
|
280
|
+
const container = this.getAnswerContainer();
|
|
281
|
+
const footer = this.getAnswerFooter();
|
|
282
|
+
const maxHeight = this.validateMaxCollapsedHeight();
|
|
283
|
+
if (!container || !footer) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (this.fullAnswerHeight > maxHeight) {
|
|
287
|
+
this.setCSSVariable('--atomic-crga-collapsed-height', `${maxHeight}rem`);
|
|
288
|
+
this.toggleClass(container, 'answer-collapsed', !this.generatedAnswerState.expanded);
|
|
289
|
+
this.toggleClass(footer, 'is-collapsible', true);
|
|
290
|
+
this.toggleClass(footer, 'generating-label-visible', this.generatedAnswerState.isStreaming);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
this.toggleClass(container, 'answer-collapsed', false);
|
|
294
|
+
this.toggleClass(footer, 'is-collapsible', false);
|
|
295
|
+
this.toggleClass(footer, 'generating-label-visible', false);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
clickDislike() {
|
|
299
|
+
this.controller.clickDislike();
|
|
300
|
+
}
|
|
301
|
+
clickLike() {
|
|
302
|
+
this.controller.clickLike();
|
|
303
|
+
}
|
|
304
|
+
renderCitationsList() {
|
|
305
|
+
const { citations } = this.generatedAnswerState ?? {};
|
|
306
|
+
return renderCitations({
|
|
307
|
+
props: {
|
|
308
|
+
citations,
|
|
309
|
+
i18n: this.bindings.i18n,
|
|
310
|
+
buildInteractiveCitation: (citation) => buildInsightInteractiveCitation(this.bindings.engine, {
|
|
311
|
+
options: { citation },
|
|
312
|
+
}),
|
|
313
|
+
logCitationHover: (citationId, citationHoverTimeMs) => {
|
|
314
|
+
this.generatedAnswer?.logCitationHover(citationId, citationHoverTimeMs);
|
|
315
|
+
},
|
|
316
|
+
disableCitationAnchoring: this.disableCitationAnchoring,
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
renderFeedbackAndCopyButtonsWrapper() {
|
|
321
|
+
return renderFeedbackAndCopyButtons({
|
|
322
|
+
props: {
|
|
323
|
+
i18n: this.bindings.i18n,
|
|
324
|
+
generatedAnswerActionsState: {
|
|
325
|
+
liked: this.generatedAnswerState.liked,
|
|
326
|
+
disliked: this.generatedAnswerState.disliked,
|
|
327
|
+
isStreaming: this.generatedAnswerState.isStreaming,
|
|
328
|
+
isLoading: this.generatedAnswerState.isLoading,
|
|
329
|
+
answer: this.generatedAnswerState.answer,
|
|
330
|
+
},
|
|
331
|
+
copied: this.copied,
|
|
332
|
+
copyError: this.copyError,
|
|
333
|
+
getCopyToClipboardTooltip: () => this.copyToClipboardTooltip,
|
|
334
|
+
onClickLike: () => this.clickLike(),
|
|
335
|
+
onClickDislike: () => this.clickDislike(),
|
|
336
|
+
onCopyToClipboard: (answer) => this.copyToClipboard(answer),
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
renderContent() {
|
|
341
|
+
const generatedAnswer = {
|
|
342
|
+
...this.generatedAnswerState,
|
|
343
|
+
question: this.bindings.engine.state.query?.q ?? '',
|
|
344
|
+
};
|
|
345
|
+
return renderAnswerContent({
|
|
346
|
+
props: {
|
|
347
|
+
i18n: this.bindings.i18n,
|
|
348
|
+
generatedAnswer: generatedAnswer,
|
|
349
|
+
collapsible: this.collapsible,
|
|
350
|
+
renderFeedbackAndCopyButtonsSlot: () => this.renderFeedbackAndCopyButtonsWrapper(),
|
|
351
|
+
renderCitationsSlot: () => html `${this.renderCitationsList()}`,
|
|
352
|
+
onRetry: () => this.generatedAnswer?.retry(),
|
|
353
|
+
onClickShowButton: () => this.clickOnShowButton(),
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
renderCardHeaderWrapper() {
|
|
358
|
+
return renderCardHeader({
|
|
359
|
+
props: {
|
|
360
|
+
i18n: this.bindings.i18n,
|
|
361
|
+
isAnswerVisible: this.isAnswerVisible,
|
|
362
|
+
toggleTooltip: this.toggleTooltip,
|
|
363
|
+
withToggle: this.withToggle,
|
|
364
|
+
onToggle: (checked) => {
|
|
365
|
+
checked ? this.generatedAnswer?.show() : this.generatedAnswer?.hide();
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
AtomicInsightGeneratedAnswer.styles = [atomicInsightGeneratedAnswerStyles];
|
|
372
|
+
AtomicInsightGeneratedAnswer.propsSchema = new Schema({
|
|
373
|
+
maxCollapsedHeight: new NumberValue({
|
|
374
|
+
min: 9,
|
|
375
|
+
max: 32,
|
|
376
|
+
required: false,
|
|
377
|
+
}),
|
|
378
|
+
});
|
|
379
|
+
// TODO V4 (KIT-5306): Remove converter and use arrayConverter directly.
|
|
380
|
+
AtomicInsightGeneratedAnswer.fieldsToIncludeInCitationsConverter = createLegacyArrayStringConverter((value) => {
|
|
381
|
+
console.warn(`Starting from Atomic v4, the "fields-to-include-in-citations" property will only accept an array of strings. Using a comma-separated string value ("${value}") is now deprecated. Please update the value to be a JSON array. For example: fields-to-include-in-citations='["fieldA","fieldB"]'`);
|
|
382
|
+
});
|
|
383
|
+
__decorate([
|
|
384
|
+
property({
|
|
385
|
+
type: Boolean,
|
|
386
|
+
attribute: 'with-toggle',
|
|
387
|
+
converter: booleanConverter,
|
|
388
|
+
})
|
|
389
|
+
], AtomicInsightGeneratedAnswer.prototype, "withToggle", void 0);
|
|
390
|
+
__decorate([
|
|
391
|
+
property({ type: Boolean, converter: booleanConverter })
|
|
392
|
+
], AtomicInsightGeneratedAnswer.prototype, "collapsible", void 0);
|
|
393
|
+
__decorate([
|
|
394
|
+
property({ type: Number, attribute: 'max-collapsed-height' })
|
|
395
|
+
], AtomicInsightGeneratedAnswer.prototype, "maxCollapsedHeight", void 0);
|
|
396
|
+
__decorate([
|
|
397
|
+
property({ type: String, attribute: 'answer-configuration-id' })
|
|
398
|
+
], AtomicInsightGeneratedAnswer.prototype, "answerConfigurationId", void 0);
|
|
399
|
+
__decorate([
|
|
400
|
+
property({
|
|
401
|
+
type: String,
|
|
402
|
+
attribute: 'fields-to-include-in-citations',
|
|
403
|
+
converter: AtomicInsightGeneratedAnswer.fieldsToIncludeInCitationsConverter,
|
|
404
|
+
})
|
|
405
|
+
], AtomicInsightGeneratedAnswer.prototype, "fieldsToIncludeInCitations", void 0);
|
|
406
|
+
__decorate([
|
|
407
|
+
property({
|
|
408
|
+
type: Boolean,
|
|
409
|
+
attribute: 'disable-citation-anchoring',
|
|
410
|
+
converter: booleanConverter,
|
|
411
|
+
})
|
|
412
|
+
], AtomicInsightGeneratedAnswer.prototype, "disableCitationAnchoring", void 0);
|
|
413
|
+
__decorate([
|
|
414
|
+
state()
|
|
415
|
+
], AtomicInsightGeneratedAnswer.prototype, "bindings", void 0);
|
|
416
|
+
__decorate([
|
|
417
|
+
state()
|
|
418
|
+
], AtomicInsightGeneratedAnswer.prototype, "error", void 0);
|
|
419
|
+
__decorate([
|
|
420
|
+
bindStateToController('generatedAnswer', {
|
|
421
|
+
onUpdateCallbackMethod: 'onGeneratedAnswerStateUpdate',
|
|
422
|
+
}),
|
|
423
|
+
state()
|
|
424
|
+
], AtomicInsightGeneratedAnswer.prototype, "generatedAnswerState", void 0);
|
|
425
|
+
__decorate([
|
|
426
|
+
bindStateToController('searchStatus'),
|
|
427
|
+
state()
|
|
428
|
+
], AtomicInsightGeneratedAnswer.prototype, "searchStatusState", void 0);
|
|
429
|
+
__decorate([
|
|
430
|
+
state()
|
|
431
|
+
], AtomicInsightGeneratedAnswer.prototype, "copied", void 0);
|
|
432
|
+
__decorate([
|
|
433
|
+
state()
|
|
434
|
+
], AtomicInsightGeneratedAnswer.prototype, "copyError", void 0);
|
|
435
|
+
__decorate([
|
|
436
|
+
bindingGuard(),
|
|
437
|
+
errorGuard()
|
|
438
|
+
], AtomicInsightGeneratedAnswer.prototype, "render", null);
|
|
439
|
+
AtomicInsightGeneratedAnswer = AtomicInsightGeneratedAnswer_1 = __decorate([
|
|
440
|
+
customElement('atomic-insight-generated-answer'),
|
|
441
|
+
bindings(),
|
|
442
|
+
withTailwindStyles
|
|
443
|
+
], AtomicInsightGeneratedAnswer);
|
|
444
|
+
export { AtomicInsightGeneratedAnswer };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { buildAttachedResults, } from '@coveo/headless/insight';
|
|
8
|
+
import { html, LitElement } from 'lit';
|
|
9
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
10
|
+
import { renderIconButton } from "../../common/icon-button";
|
|
11
|
+
import { ItemContextController } from "../../common/item-list/context/item-context-controller";
|
|
12
|
+
import { bindStateToController } from "../../../decorators/bind-state";
|
|
13
|
+
import { bindingGuard } from "../../../decorators/binding-guard";
|
|
14
|
+
import { bindings } from "../../../decorators/bindings";
|
|
15
|
+
import { errorGuard } from "../../../decorators/error-guard";
|
|
16
|
+
import { LightDomMixin } from "../../../mixins/light-dom";
|
|
17
|
+
const AttachIcon = "<svg width=\"26\" height=\"26\" viewBox=\"0 0 26 26\" xmlns=\"http://www.w3.org/2000/svg\">\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M8.8125 18.3125C9.1125 18.6125 9.5625 18.5625 9.8625 18.3125L14.8625 13.3125C15.2125 12.9625 15.8125 12.9125 16.2625 13.3125C16.7125 13.7125 16.6625 14.4125 16.2625 14.8125L10.1125 20.8625C8.7625 22.2125 6.5125 22.2125 5.1625 20.8625L5.1125 20.8125C3.7625 19.4625 3.7625 17.2125 5.1125 15.8625L15.9625 5.0125C17.3125 3.6625 19.5625 3.6625 20.9125 5.0125L20.9625 5.0625C22.3125 6.4125 22.3125 8.6625 20.9625 10.0125L20.9125 10.0625C20.6625 10.3125 20.6125 10.6625 20.8125 10.9625C21.1125 11.5125 21.3625 12.1125 21.5125 12.7125C21.6125 13.1125 22.0625 13.2125 22.3625 12.9625C22.7625 12.5625 23.1125 12.1625 23.1125 12.1625C25.6625 9.6125 25.6625 5.4625 23.1125 2.9125H23.0125C20.4625 0.3625 16.3125 0.3625 13.7625 2.9125L2.9125 13.7125C0.3625 16.2625 0.3625 20.4125 2.9125 22.9625L3.0125 23.0625C5.5625 25.6125 9.6625 25.6125 12.2125 23.0625L18.4125 16.9125C20.0125 15.3125 19.9625 12.7125 18.3125 11.1125C16.7125 9.5625 14.1125 9.6625 12.5625 11.2625L7.6625 16.1625C7.3625 16.4625 7.3625 16.9625 7.6625 17.2625L8.8125 18.3125Z\"/>\n</svg>\n";
|
|
18
|
+
const DetachIcon = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"26px\" height=\"26px\" viewBox=\"0 0 26 26\" version=\"1.1\">\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M 8.300781 16.898438 C 8.566406 17.148438 8.980469 17.148438 9.25 16.898438 L 13.851562 12.300781 C 14.214844 11.957031 14.785156 11.957031 15.148438 12.300781 C 15.53125 12.6875 15.53125 13.3125 15.148438 13.699219 L 9.449219 19.25 C 8.191406 20.457031 6.207031 20.457031 4.949219 19.25 L 4.898438 19.25 C 4.289062 18.640625 3.945312 17.8125 3.945312 16.949219 C 3.945312 16.085938 4.289062 15.257812 4.898438 14.648438 L 14.898438 4.648438 C 16.15625 3.445312 18.140625 3.445312 19.398438 4.648438 L 19.5 4.75 C 20.707031 6.007812 20.707031 7.992188 19.5 9.25 L 19.449219 9.351562 C 19.234375 9.5625 19.195312 9.890625 19.351562 10.148438 C 19.632812 10.65625 19.847656 11.191406 20 11.75 C 20.050781 11.894531 20.167969 12.011719 20.3125 12.058594 C 20.460938 12.109375 20.621094 12.085938 20.75 12 C 21.148438 11.648438 21.449219 11.25 21.449219 11.25 C 22.578125 10.125 23.214844 8.59375 23.214844 7 C 23.214844 5.40625 22.578125 3.875 21.449219 2.75 L 21.351562 2.75 C 20.222656 1.621094 18.695312 0.984375 17.101562 0.984375 C 15.503906 0.984375 13.976562 1.621094 12.851562 2.75 L 2.851562 12.699219 C 1.71875 13.824219 1.085938 15.355469 1.085938 16.949219 C 1.085938 18.542969 1.71875 20.074219 2.851562 21.199219 L 2.949219 21.300781 C 5.289062 23.621094 9.0625 23.621094 11.398438 21.300781 L 17.101562 15.648438 C 18.078125 14.695312 18.457031 13.285156 18.089844 11.964844 C 17.726562 10.648438 16.671875 9.636719 15.34375 9.320312 C 14.015625 9.003906 12.617188 9.4375 11.699219 10.449219 L 7.199219 14.949219 C 7.066406 15.082031 6.988281 15.261719 6.988281 15.449219 C 6.988281 15.636719 7.066406 15.816406 7.199219 15.949219 Z M 22.648438 20.800781 L 24.75 18.699219 C 24.839844 18.613281 24.890625 18.496094 24.890625 18.375 C 24.890625 18.253906 24.839844 18.136719 24.75 18.050781 L 23.5 16.75 C 23.414062 16.660156 23.296875 16.609375 23.175781 16.609375 C 23.050781 16.609375 22.933594 16.660156 22.851562 16.75 L 20.800781 19 L 18.800781 17 C 18.714844 16.910156 18.597656 16.859375 18.476562 16.859375 C 18.351562 16.859375 18.234375 16.910156 18.148438 17 L 16.898438 18.25 C 16.738281 18.4375 16.738281 18.710938 16.898438 18.898438 L 18.898438 20.898438 L 16.898438 22.800781 C 16.8125 22.886719 16.761719 23.003906 16.761719 23.125 C 16.761719 23.246094 16.8125 23.363281 16.898438 23.449219 L 18.25 24.75 C 18.335938 24.839844 18.453125 24.890625 18.574219 24.890625 C 18.699219 24.890625 18.816406 24.839844 18.898438 24.75 L 20.800781 22.800781 L 22.851562 24.898438 C 22.933594 24.988281 23.050781 25.039062 23.175781 25.039062 C 23.296875 25.039062 23.414062 24.988281 23.5 24.898438 L 24.800781 23.601562 C 24.886719 23.515625 24.9375 23.398438 24.9375 23.273438 C 24.9375 23.152344 24.886719 23.035156 24.800781 22.949219 Z M 22.648438 20.800781 \"/>\n</svg>\n";
|
|
19
|
+
/**
|
|
20
|
+
* The `atomic-insight-result-attach-to-case-action` component can be nested
|
|
21
|
+
* inside a `atomic-insight-result-actions` to render an interactive button
|
|
22
|
+
* that will emit an `atomic/insight/attachToCase/attach` or
|
|
23
|
+
* `atomic/insight/attachToCase/detach` JavaScript event, based on its current
|
|
24
|
+
* state, when clicked.
|
|
25
|
+
*
|
|
26
|
+
* @part result-action-container - The result action container
|
|
27
|
+
* @part result-action-button - The result action button
|
|
28
|
+
* @part result-action-icon - The result action icon
|
|
29
|
+
*/
|
|
30
|
+
let AtomicInsightResultAttachToCaseAction = class AtomicInsightResultAttachToCaseAction extends LightDomMixin(LitElement) {
|
|
31
|
+
constructor() {
|
|
32
|
+
super();
|
|
33
|
+
this.itemContextController = new ItemContextController(this, {
|
|
34
|
+
parentName: 'atomic-insight-result',
|
|
35
|
+
folded: false,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
get result() {
|
|
39
|
+
return this.itemContextController.item;
|
|
40
|
+
}
|
|
41
|
+
initialize() {
|
|
42
|
+
const caseId = this.bindings.engine.state.insightCaseContext?.caseId || '';
|
|
43
|
+
this.attachedResults = buildAttachedResults(this.bindings.engine, {
|
|
44
|
+
options: {
|
|
45
|
+
caseId: caseId,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
onClick() {
|
|
50
|
+
if (!this.result) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (this.attachedResults.isAttached(this.result)) {
|
|
54
|
+
this.dispatchEvent(new CustomEvent('atomic/insight/attachToCase/detach', {
|
|
55
|
+
bubbles: true,
|
|
56
|
+
composed: true,
|
|
57
|
+
cancelable: true,
|
|
58
|
+
detail: {
|
|
59
|
+
callback: () => this.attachedResults.detach(this.result),
|
|
60
|
+
result: this.result,
|
|
61
|
+
},
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.dispatchEvent(new CustomEvent('atomic/insight/attachToCase/attach', {
|
|
66
|
+
bubbles: true,
|
|
67
|
+
composed: true,
|
|
68
|
+
cancelable: true,
|
|
69
|
+
detail: {
|
|
70
|
+
callback: () => this.attachedResults.attach(this.result),
|
|
71
|
+
result: this.result,
|
|
72
|
+
},
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
getIcon() {
|
|
77
|
+
return this.result && this.attachedResults?.isAttached(this.result)
|
|
78
|
+
? DetachIcon
|
|
79
|
+
: AttachIcon;
|
|
80
|
+
}
|
|
81
|
+
getTooltip() {
|
|
82
|
+
return this.result && this.attachedResults?.isAttached(this.result)
|
|
83
|
+
? this.bindings.i18n.t('detach-from-case')
|
|
84
|
+
: this.bindings.i18n.t('attach-to-case');
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
if (!this.result || !this.attachedResults) {
|
|
88
|
+
return html ``;
|
|
89
|
+
}
|
|
90
|
+
return renderIconButton({
|
|
91
|
+
props: {
|
|
92
|
+
partPrefix: 'result-action',
|
|
93
|
+
style: 'outline-neutral',
|
|
94
|
+
icon: this.getIcon(),
|
|
95
|
+
ariaLabel: this.getTooltip(),
|
|
96
|
+
title: this.getTooltip(),
|
|
97
|
+
onClick: () => this.onClick(),
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
__decorate([
|
|
103
|
+
state()
|
|
104
|
+
], AtomicInsightResultAttachToCaseAction.prototype, "bindings", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
state()
|
|
107
|
+
], AtomicInsightResultAttachToCaseAction.prototype, "error", void 0);
|
|
108
|
+
__decorate([
|
|
109
|
+
bindStateToController('attachedResults'),
|
|
110
|
+
state()
|
|
111
|
+
// @ts-ignore - Binds headless state to trigger Lit re-renders.
|
|
112
|
+
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: Binds headless state to trigger Lit re-renders.
|
|
113
|
+
], AtomicInsightResultAttachToCaseAction.prototype, "attachedResultsState", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
errorGuard(),
|
|
116
|
+
bindingGuard()
|
|
117
|
+
], AtomicInsightResultAttachToCaseAction.prototype, "render", null);
|
|
118
|
+
AtomicInsightResultAttachToCaseAction = __decorate([
|
|
119
|
+
customElement('atomic-insight-result-attach-to-case-action'),
|
|
120
|
+
bindings()
|
|
121
|
+
], AtomicInsightResultAttachToCaseAction);
|
|
122
|
+
export { AtomicInsightResultAttachToCaseAction };
|