@cognigy/chat-components-vue 0.1.0 → 0.3.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/dist/chat-components-vue.css +1 -1
- package/dist/chat-components-vue.js +12386 -5741
- package/dist/components/Message.vue.d.ts +4 -0
- package/dist/components/common/Typography.vue.d.ts +1 -1
- package/dist/components/messages/AdaptiveCardRenderer.vue.d.ts +35 -0
- package/dist/components/messages/ListItem.vue.d.ts +1 -1
- package/dist/composables/useLiveRegion.d.ts +30 -0
- package/dist/index.d.ts +3 -2
- package/dist/types/index.d.ts +105 -1
- package/dist/utils/helpers.d.ts +3 -2
- package/dist/utils/matcher.d.ts +3 -3
- package/dist/utils/theme.d.ts +12 -1
- package/package.json +8 -3
- package/src/components/Message.vue +98 -55
- package/src/components/common/ActionButton.vue +16 -7
- package/src/components/common/ChatBubble.vue +8 -6
- package/src/components/common/ChatEvent.vue +5 -2
- package/src/components/common/TypingIndicator.vue +4 -1
- package/src/components/common/Typography.vue +56 -67
- package/src/components/messages/AdaptiveCard.vue +322 -225
- package/src/components/messages/AdaptiveCardRenderer.vue +260 -0
- package/src/components/messages/AudioMessage.vue +4 -1
- package/src/components/messages/DatePicker.vue +5 -27
- package/src/components/messages/FileMessage.vue +12 -3
- package/src/components/messages/Gallery.vue +96 -10
- package/src/components/messages/GalleryItem.vue +17 -5
- package/src/components/messages/ImageMessage.vue +20 -5
- package/src/components/messages/List.vue +56 -42
- package/src/components/messages/ListItem.vue +105 -68
- package/src/components/messages/TextMessage.vue +1 -1
- package/src/components/messages/TextWithButtons.vue +35 -11
- package/src/components/messages/VideoMessage.vue +35 -26
- package/src/composables/useCollation.ts +28 -45
- package/src/composables/useLiveRegion.ts +101 -0
- package/src/index.ts +4 -1
- package/src/types/index.ts +127 -2
- package/src/utils/helpers.ts +46 -24
- package/src/utils/matcher.ts +20 -6
- package/src/utils/sanitize.ts +1 -2
- package/src/utils/theme.ts +42 -1
package/src/utils/matcher.ts
CHANGED
|
@@ -10,6 +10,9 @@ import type { IMessage } from '@cognigy/socket-client'
|
|
|
10
10
|
import type { ChatConfig, MatchRule, MessagePlugin, MatchResult } from '../types'
|
|
11
11
|
import { isAdaptiveCardPayload } from '../types'
|
|
12
12
|
|
|
13
|
+
// Pre-compiled regex for escape sequence check
|
|
14
|
+
const ESCAPE_SEQUENCE_REGEX = /^[\n\t\r\v\f\s]*$/
|
|
15
|
+
|
|
13
16
|
/**
|
|
14
17
|
* Check if message has channel payload
|
|
15
18
|
*/
|
|
@@ -46,16 +49,17 @@ function isOnlyEscapeSequence(text: string | null | undefined): boolean {
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
const trimmed = text.trim()
|
|
49
|
-
return trimmed === '' ||
|
|
52
|
+
return trimmed === '' || ESCAPE_SEQUENCE_REGEX.test(trimmed)
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
56
|
* Default match rules for internal message types.
|
|
54
57
|
* These rules map message data structures to component names.
|
|
55
58
|
* Components are resolved by name lookup in Message.vue.
|
|
59
|
+
*
|
|
60
|
+
* Created once at module load for performance - rules are static.
|
|
56
61
|
*/
|
|
57
|
-
|
|
58
|
-
return [
|
|
62
|
+
const DEFAULT_MATCH_RULES: MatchRule[] = [
|
|
59
63
|
// xApp submit
|
|
60
64
|
{
|
|
61
65
|
name: 'XAppSubmit',
|
|
@@ -240,6 +244,14 @@ export function createDefaultMatchRules(): MatchRule[] {
|
|
|
240
244
|
},
|
|
241
245
|
},
|
|
242
246
|
]
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Returns a copy of the default match rules.
|
|
250
|
+
* Exposed for testing and extension purposes.
|
|
251
|
+
* Returns a new array to prevent mutation of internal rules.
|
|
252
|
+
*/
|
|
253
|
+
export function createDefaultMatchRules(): MatchRule[] {
|
|
254
|
+
return [...DEFAULT_MATCH_RULES]
|
|
243
255
|
}
|
|
244
256
|
|
|
245
257
|
/**
|
|
@@ -254,9 +266,11 @@ export function match(
|
|
|
254
266
|
config?: ChatConfig,
|
|
255
267
|
externalPlugins: MessagePlugin[] = []
|
|
256
268
|
): MatchResult[] {
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
const allRules: MatchResult[] =
|
|
269
|
+
// External plugins are checked first, then default rules
|
|
270
|
+
// Always create a new array to prevent mutation of DEFAULT_MATCH_RULES
|
|
271
|
+
const allRules: MatchResult[] = externalPlugins.length > 0
|
|
272
|
+
? [...externalPlugins, ...DEFAULT_MATCH_RULES]
|
|
273
|
+
: [...DEFAULT_MATCH_RULES]
|
|
260
274
|
|
|
261
275
|
const matchedRules: MatchResult[] = []
|
|
262
276
|
|
package/src/utils/sanitize.ts
CHANGED
|
@@ -95,8 +95,7 @@ export function sanitizeHTMLWithConfig(
|
|
|
95
95
|
})
|
|
96
96
|
|
|
97
97
|
try {
|
|
98
|
-
|
|
99
|
-
return sanitized
|
|
98
|
+
return DOMPurify.sanitize(text, config).toString()
|
|
100
99
|
} catch (error) {
|
|
101
100
|
console.error('sanitizeHTMLWithConfig: Sanitization failed', {
|
|
102
101
|
error,
|
package/src/utils/theme.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Theme utilities for config-driven CSS variable injection
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { ChatSettings } from '../types'
|
|
5
|
+
import type { ChatSettings, ChatTheme } from '../types'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Maps config.settings.colors to CSS custom properties.
|
|
@@ -47,8 +47,32 @@ export function configColorsToCssVariables(
|
|
|
47
47
|
'--cc-border-user-message': colors.borderUserMessage,
|
|
48
48
|
'--cc-border-agent-message': colors.borderAgentMessage,
|
|
49
49
|
|
|
50
|
+
// Media card borders
|
|
51
|
+
'--cc-border-media-card': colors.borderMediaCard,
|
|
52
|
+
|
|
53
|
+
// List divider color
|
|
54
|
+
'--cc-list-divider-color': colors.listDividerColor,
|
|
55
|
+
|
|
50
56
|
// Link color
|
|
51
57
|
'--cc-text-link-color': colors.textLinkColor,
|
|
58
|
+
|
|
59
|
+
// Adaptive Card colors
|
|
60
|
+
'--cc-adaptive-card-text-color': colors.adaptiveCardTextColor,
|
|
61
|
+
'--cc-adaptive-card-input-color': colors.adaptiveCardInputColor,
|
|
62
|
+
'--cc-adaptive-card-input-background': colors.adaptiveCardInputBackground,
|
|
63
|
+
'--cc-adaptive-card-input-border': colors.adaptiveCardInputBorder,
|
|
64
|
+
|
|
65
|
+
// File preview colors
|
|
66
|
+
'--cc-file-preview-background': colors.filePreviewBackground,
|
|
67
|
+
'--cc-file-preview-text-color': colors.filePreviewTextColor,
|
|
68
|
+
'--cc-file-preview-secondary-text-color': colors.filePreviewSecondaryTextColor,
|
|
69
|
+
|
|
70
|
+
// Chat event colors
|
|
71
|
+
'--cc-chat-event-background': colors.chatEventBackground,
|
|
72
|
+
'--cc-chat-event-text-color': colors.chatEventTextColor,
|
|
73
|
+
|
|
74
|
+
// Message shadow
|
|
75
|
+
'--cc-message-shadow': colors.messageShadow,
|
|
52
76
|
}
|
|
53
77
|
|
|
54
78
|
// Filter out undefined values and return only defined CSS variables
|
|
@@ -56,3 +80,20 @@ export function configColorsToCssVariables(
|
|
|
56
80
|
Object.entries(mapping).filter(([, value]) => value !== undefined)
|
|
57
81
|
) as Record<string, string>
|
|
58
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Maps a ChatTheme's fontFamily to the --cc-font-family CSS variable.
|
|
86
|
+
* Consumers can set this to override the default Figtree font.
|
|
87
|
+
*
|
|
88
|
+
* Components should reference font-family as:
|
|
89
|
+
* font-family: var(--cc-font-family, 'Figtree', sans-serif);
|
|
90
|
+
*
|
|
91
|
+
* @param theme - The ChatTheme object
|
|
92
|
+
* @returns A record with the --cc-font-family CSS variable, or empty object
|
|
93
|
+
*/
|
|
94
|
+
export function themeFontToCssVariable(
|
|
95
|
+
theme?: ChatTheme
|
|
96
|
+
): Record<string, string> {
|
|
97
|
+
if (!theme?.fontFamily) return {}
|
|
98
|
+
return { '--cc-font-family': theme.fontFamily }
|
|
99
|
+
}
|