@cognigy/chat-components-vue 0.1.0 → 0.2.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.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Host config input type - plain object that HostConfig constructor parses.
3
+ * We don't use Partial<HostConfig> because HostConfig properties are class instances,
4
+ * but the constructor accepts plain objects and converts them internally.
5
+ */
6
+ type HostConfigInput = Record<string, unknown>;
7
+ interface Props {
8
+ /**
9
+ * The Adaptive Card payload to render
10
+ */
11
+ payload?: Record<string, unknown>;
12
+ /**
13
+ * Host configuration for styling the card.
14
+ * Accepts a plain object matching the HostConfig structure - the library
15
+ * parses this internally when constructing the HostConfig instance.
16
+ */
17
+ hostConfig?: HostConfigInput;
18
+ /**
19
+ * When true, disables all inputs and buttons after rendering
20
+ * Useful for displaying submitted cards in chat history
21
+ */
22
+ readonly?: boolean;
23
+ /**
24
+ * Data to pre-fill into input fields
25
+ * Keys should match input element IDs in the card
26
+ * Used to show submitted values in chat history
27
+ */
28
+ inputData?: Record<string, unknown>;
29
+ }
30
+ declare const _default: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {
31
+ readonly: boolean;
32
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
33
+ targetRef: HTMLDivElement;
34
+ }, HTMLDivElement>;
35
+ export default _default;
@@ -79,6 +79,10 @@ export interface ChatSettings {
79
79
  borderUserMessage?: string;
80
80
  borderAgentMessage?: string;
81
81
  textLinkColor?: string;
82
+ adaptiveCardTextColor?: string;
83
+ adaptiveCardInputColor?: string;
84
+ adaptiveCardInputBackground?: string;
85
+ adaptiveCardInputBorder?: string;
82
86
  };
83
87
  behavior?: {
84
88
  renderMarkdown?: boolean;
@@ -86,6 +90,15 @@ export interface ChatSettings {
86
90
  messageDelay?: number;
87
91
  collateStreamedOutputs?: boolean;
88
92
  focusInputAfterPostback?: boolean;
93
+ /**
94
+ * Controls adaptive card interactivity.
95
+ * - `true`: All cards are readonly (presentation only), regardless of submitted data
96
+ * - `false` or `undefined`: Smart default - readonly only if card has submitted data
97
+ *
98
+ * Use `true` for chat history/transcript displays where no interaction is needed.
99
+ * Use `false`/omit for interactive chat interfaces with smart auto-detection.
100
+ */
101
+ adaptiveCardsReadonly?: boolean;
89
102
  };
90
103
  widgetSettings?: {
91
104
  enableDefaultPreview?: boolean;
@@ -271,5 +284,41 @@ export interface IWebchatChannelPayload {
271
284
  quick_replies?: QuickReply[];
272
285
  attachment?: TemplateAttachment | AudioAttachment | ImageAttachment | VideoAttachment;
273
286
  };
274
- adaptiveCard?: unknown;
287
+ adaptiveCard?: Record<string, unknown>;
288
+ /** Submitted adaptive card data */
289
+ adaptiveCardData?: Record<string, unknown>;
290
+ data?: Record<string, unknown>;
291
+ formData?: Record<string, unknown>;
292
+ }
293
+ /**
294
+ * Cognigy message data structure
295
+ * Shape of message.data._cognigy
296
+ */
297
+ export interface ICognigyData {
298
+ _webchat?: IWebchatChannelPayload;
299
+ _defaultPreview?: IWebchatChannelPayload;
300
+ _facebook?: IWebchatChannelPayload;
301
+ }
302
+ /**
303
+ * Plugin payload structure for custom message types
304
+ */
305
+ export interface IPluginPayload {
306
+ type?: string;
307
+ payload?: Record<string, unknown>;
308
+ }
309
+ /**
310
+ * Extended message data with Cognigy-specific fields
311
+ * Use this when accessing message.data with Cognigy payload structures
312
+ */
313
+ export interface IMessageDataExtended {
314
+ _cognigy?: ICognigyData;
315
+ _plugin?: IPluginPayload;
316
+ /** Adaptive card submission request data */
317
+ request?: {
318
+ value?: Record<string, unknown>;
319
+ };
320
+ /** Direct adaptive card data fields (fallback locations) */
321
+ adaptiveCardData?: Record<string, unknown>;
322
+ data?: Record<string, unknown>;
323
+ formData?: Record<string, unknown>;
275
324
  }
@@ -24,6 +24,7 @@ export declare function moveFocusToMessageFocusTarget(dataMessageId: string): vo
24
24
  * - Works with URLs starting with http/https, www., or just domain/subdomain
25
25
  * - Will only match URLs at the beginning or following whitespace
26
26
  * - Will not work with emails
27
+ * - URLs are escaped to prevent injection attacks
27
28
  */
28
29
  export declare function replaceUrlsWithHTMLanchorElem(text: string): string;
29
30
  /**
@@ -47,9 +48,9 @@ export declare function getFileExtension(fileNameWithExtension: string): string
47
48
  */
48
49
  export declare function getSizeLabel(size: number): string;
49
50
  /**
50
- * Valid image MIME types for file attachments
51
+ * Valid image MIME types for file attachments (Set for O(1) lookup)
51
52
  */
52
- export declare const VALID_IMAGE_MIME_TYPES: string[];
53
+ export declare const VALID_IMAGE_MIME_TYPES: Set<string>;
53
54
  /**
54
55
  * Checks if attachment is a valid image type
55
56
  */
@@ -5,9 +5,9 @@ import { ChatConfig, MatchRule, MessagePlugin, MatchResult } from '../types';
5
5
  */
6
6
  export declare function getChannelPayload(message: IMessage, config?: ChatConfig): any;
7
7
  /**
8
- * Default match rules for internal message types.
9
- * These rules map message data structures to component names.
10
- * Components are resolved by name lookup in Message.vue.
8
+ * Returns a copy of the default match rules.
9
+ * Exposed for testing and extension purposes.
10
+ * Returns a new array to prevent mutation of internal rules.
11
11
  */
12
12
  export declare function createDefaultMatchRules(): MatchRule[];
13
13
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cognigy/chat-components-vue",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Vue 3 version of @cognigy/chat-components",
6
6
  "license": "MIT",
@@ -63,11 +63,12 @@
63
63
  "@braintree/sanitize-url": "^7.1.1",
64
64
  "@cognigy/socket-client": "5.0.0-beta.25",
65
65
  "@fontsource/figtree": "5.2.10",
66
+ "adaptivecards": "^3.0.5",
66
67
  "dompurify": "^3.0.11",
67
68
  "flatpickr": "^4.6.13",
68
69
  "markdown-it": "^14.1.0",
69
70
  "moment": "^2.30.1",
70
- "swiper": "^12.0.3"
71
+ "swiper": "^11.2.10"
71
72
  },
72
73
  "devDependencies": {
73
74
  "@types/markdown-it": "^14.1.2",
@@ -22,12 +22,12 @@
22
22
  </template>
23
23
 
24
24
  <script setup lang="ts">
25
- import { computed, useCssModule, type Component } from 'vue'
25
+ import { computed, reactive, watchEffect, useCssModule, type Component } from 'vue'
26
26
  import { match } from '../utils/matcher'
27
27
  import { configColorsToCssVariables } from '../utils/theme'
28
28
  import { provideMessageContext } from '../composables/useMessageContext'
29
29
  import { getMessageId, isMessagePlugin } from '../types'
30
- import type { MessageProps } from '../types'
30
+ import type { MessageProps, MessageContext } from '../types'
31
31
 
32
32
  const $style = useCssModule()
33
33
 
@@ -57,13 +57,24 @@ const props = withDefaults(defineProps<MessageProps>(), {
57
57
  const dataMessageId = computed(() => getMessageId(props.message))
58
58
 
59
59
  // Provide message context for child components
60
- provideMessageContext({
60
+ // Using reactive object synced via watchEffect for proper reactivity tracking
61
+ const messageContext = reactive<MessageContext>({
61
62
  message: props.message,
62
- config: props.config || {},
63
- action: props.action || (() => {}),
64
- onEmitAnalytics: props.onEmitAnalytics || (() => {}),
63
+ config: props.config,
64
+ action: props.action,
65
+ onEmitAnalytics: props.onEmitAnalytics,
65
66
  })
66
67
 
68
+ // Keep context in sync with props changes
69
+ watchEffect(() => {
70
+ messageContext.message = props.message
71
+ messageContext.config = props.config
72
+ messageContext.action = props.action
73
+ messageContext.onEmitAnalytics = props.onEmitAnalytics
74
+ })
75
+
76
+ provideMessageContext(messageContext)
77
+
67
78
  // Component map for internal match rules (maps rule names to Vue components)
68
79
  const componentMap: Record<string, Component> = {
69
80
  'Text': TextMessage,