Skip to content

Commit

Permalink
Fix events types
Browse files Browse the repository at this point in the history
  • Loading branch information
rjborba committed Nov 27, 2024
1 parent 61f9219 commit 116e3e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/ui-stencil/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -517,7 +517,7 @@ declare global {
new (): HTMLOramaSlidingPanelElement;
};
interface HTMLOramaSourcesElementEventMap {
"answerSourceClick": SearchResult;
"answerSourceClick": OnAnswerSourceClickCallbackProps;
}
interface HTMLOramaSourcesElement extends Components.OramaSources, HTMLStencilElement {
addEventListener<K extends keyof HTMLOramaSourcesElementEventMap>(type: K, listener: (this: HTMLOramaSourcesElement, ev: OramaSourcesCustomEvent<HTMLOramaSourcesElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
Expand Down Expand Up @@ -792,7 +792,7 @@ declare namespace LocalJSX {
interface OramaSources {
"linksRel"?: string;
"linksTarget"?: string;
"onAnswerSourceClick"?: (event: OramaSourcesCustomEvent<SearchResult>) => void;
"onAnswerSourceClick"?: (event: OramaSourcesCustomEvent<OnAnswerSourceClickCallbackProps>) => void;
"sourceBaseURL"?: string;
"sources"?: any;
"sourcesMap"?: SourcesMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -27,7 +27,8 @@ export class OramaSources {
@State() isCarouselScrollAtEnd = false
@State() isCarouselScrollAtStart = false

@Event({ bubbles: true, composed: true, cancelable: true }) answerSourceClick: EventEmitter<SearchResult>
@Event({ bubbles: true, composed: true, cancelable: true })
answerSourceClick: EventEmitter<OnAnswerSourceClickCallbackProps>

// TODO: Move this to utils
private buildUrl(path: string): string {
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 116e3e5

Please sign in to comment.