From 116e3e5c99e59d6dcb89a39b7a9b80437202cbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Jos=C3=A9=20Borba=20Fernandes?= Date: Wed, 27 Nov 2024 18:19:19 -0300 Subject: [PATCH] Fix events types --- packages/ui-stencil/src/components.d.ts | 8 ++++---- .../orama-sources/orama-sources.tsx | 7 ++++--- .../orama-chat-assistent-message/orama-sources/readme.md | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/ui-stencil/src/components.d.ts b/packages/ui-stencil/src/components.d.ts index bde17f55..73c90266 100644 --- a/packages/ui-stencil/src/components.d.ts +++ b/packages/ui-stencil/src/components.d.ts @@ -6,7 +6,7 @@ */ import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; import { ButtonProps } from "./components/internal/orama-button/orama-button"; -import { ChatMarkdownLinkHref, ChatMarkdownLinkTarget, ChatMarkdownLinkTitle, CloudIndexConfig, ColorScheme, Facet, OnAnswerGeneratedCallbackProps, OnAnswerSourceClickCallbackProps, OnChatMarkdownLinkClickedCallbackProps, OnSearchCompletedCallbackProps, OnSearchResultClickCallbackProps, ResultMap, SearchResult, SearchResultBySection, SourcesMap } from "./types/index"; +import { ChatMarkdownLinkHref, ChatMarkdownLinkTarget, ChatMarkdownLinkTitle, CloudIndexConfig, ColorScheme, Facet, OnAnswerGeneratedCallbackProps, OnAnswerSourceClickCallbackProps, OnChatMarkdownLinkClickedCallbackProps, OnSearchCompletedCallbackProps, OnSearchResultClickCallbackProps, ResultMap, SearchResultBySection, SourcesMap } from "./types/index"; import { TChatInteraction } from "./context/chatContext"; import { OramaClient } from "@oramacloud/client"; import { AnyOrama, Orama, SearchParams } from "@orama/orama"; @@ -18,7 +18,7 @@ import { TThemeOverrides as TThemeOverrides1 } from "./components.d"; import { SearchResultsProps } from "./components/internal/orama-search-results/orama-search-results"; import { TextProps } from "./components/internal/orama-text/orama-text"; export { ButtonProps } from "./components/internal/orama-button/orama-button"; -export { ChatMarkdownLinkHref, ChatMarkdownLinkTarget, ChatMarkdownLinkTitle, CloudIndexConfig, ColorScheme, Facet, OnAnswerGeneratedCallbackProps, OnAnswerSourceClickCallbackProps, OnChatMarkdownLinkClickedCallbackProps, OnSearchCompletedCallbackProps, OnSearchResultClickCallbackProps, ResultMap, SearchResult, SearchResultBySection, SourcesMap } from "./types/index"; +export { ChatMarkdownLinkHref, ChatMarkdownLinkTarget, ChatMarkdownLinkTitle, CloudIndexConfig, ColorScheme, Facet, OnAnswerGeneratedCallbackProps, OnAnswerSourceClickCallbackProps, OnChatMarkdownLinkClickedCallbackProps, OnSearchCompletedCallbackProps, OnSearchResultClickCallbackProps, ResultMap, SearchResultBySection, SourcesMap } from "./types/index"; export { TChatInteraction } from "./context/chatContext"; export { OramaClient } from "@oramacloud/client"; export { AnyOrama, Orama, SearchParams } from "@orama/orama"; @@ -517,7 +517,7 @@ declare global { new (): HTMLOramaSlidingPanelElement; }; interface HTMLOramaSourcesElementEventMap { - "answerSourceClick": SearchResult; + "answerSourceClick": OnAnswerSourceClickCallbackProps; } interface HTMLOramaSourcesElement extends Components.OramaSources, HTMLStencilElement { addEventListener(type: K, listener: (this: HTMLOramaSourcesElement, ev: OramaSourcesCustomEvent) => any, options?: boolean | AddEventListenerOptions): void; @@ -792,7 +792,7 @@ declare namespace LocalJSX { interface OramaSources { "linksRel"?: string; "linksTarget"?: string; - "onAnswerSourceClick"?: (event: OramaSourcesCustomEvent) => void; + "onAnswerSourceClick"?: (event: OramaSourcesCustomEvent) => void; "sourceBaseURL"?: string; "sources"?: any; "sourcesMap"?: SourcesMap; diff --git a/packages/ui-stencil/src/components/internal/orama-chat-messages-container/orama-chat-assistent-message/orama-sources/orama-sources.tsx b/packages/ui-stencil/src/components/internal/orama-chat-messages-container/orama-chat-assistent-message/orama-sources/orama-sources.tsx index aca4a4cf..66da7cb4 100644 --- a/packages/ui-stencil/src/components/internal/orama-chat-messages-container/orama-chat-assistent-message/orama-sources/orama-sources.tsx +++ b/packages/ui-stencil/src/components/internal/orama-chat-messages-container/orama-chat-assistent-message/orama-sources/orama-sources.tsx @@ -1,4 +1,4 @@ -import type { SourcesMap, SearchResult } from '@/types' +import type { SourcesMap, SearchResult, OnAnswerSourceClickCallbackProps } from '@/types' import { Component, Event, Prop, State, h, type EventEmitter } from '@stencil/core' import '@phosphor-icons/webcomponents/dist/icons/PhCaretLeft.mjs' import '@phosphor-icons/webcomponents/dist/icons/PhCaretRight.mjs' @@ -27,7 +27,8 @@ export class OramaSources { @State() isCarouselScrollAtEnd = false @State() isCarouselScrollAtStart = false - @Event({ bubbles: true, composed: true, cancelable: true }) answerSourceClick: EventEmitter + @Event({ bubbles: true, composed: true, cancelable: true }) + answerSourceClick: EventEmitter // TODO: Move this to utils private buildUrl(path: string): string { @@ -123,7 +124,7 @@ export class OramaSources { } handleItemClick = (originalOnClickEvent: MouseEvent, item: SearchResult) => { - const answerSourceClick = this.answerSourceClick.emit(item) + const answerSourceClick = this.answerSourceClick.emit({ source: item }) if (answerSourceClick.defaultPrevented) { originalOnClickEvent.preventDefault() diff --git a/packages/ui-stencil/src/components/internal/orama-chat-messages-container/orama-chat-assistent-message/orama-sources/readme.md b/packages/ui-stencil/src/components/internal/orama-chat-messages-container/orama-chat-assistent-message/orama-sources/readme.md index 14661922..d71b68fc 100644 --- a/packages/ui-stencil/src/components/internal/orama-chat-messages-container/orama-chat-assistent-message/orama-sources/readme.md +++ b/packages/ui-stencil/src/components/internal/orama-chat-messages-container/orama-chat-assistent-message/orama-sources/readme.md @@ -18,9 +18,9 @@ ## Events -| Event | Description | Type | -| ------------------- | ----------- | -------------------------------------------------------------------------------- | -| `answerSourceClick` | | `CustomEvent<{ id: string; title: string; description: string; path: string; }>` | +| Event | Description | Type | +| ------------------- | ----------- | ---------------------------------------- | +| `answerSourceClick` | | `CustomEvent<{ source: SearchResult; }>` | ## Dependencies