Registry / communication / vue-advanced-chat

vue-advanced-chat

JSON →
library2.1.2jsnpmunverified

Vue Advanced Chat is a versatile, highly customizable chat rooms component built with Vue.js, but designed to be compatible with any JavaScript framework (Vue, React, Angular) or no framework at all, thanks to its Web Component support. Currently stable at version 2.1.2, it sees regular updates with minor bug fixes and feature enhancements, as evidenced by its consistent monthly or bi-monthly release cadence. Key differentiators include its backend-agnostic design, comprehensive feature set (images, videos, files, voice messages, emojis, message editing, replies, user tagging, text formatting), integrated UI elements for chat states (seen, typing, deleted), and support for online/offline statuses and light/dark themes. It ships with TypeScript types, facilitating robust development, and provides examples for integration with backends like Firestore, demonstrating its flexibility in handling real-time data.

npm install vue-advanced-chat
INSTALL
IMPORT
SIG · VUE-ADVANCED-CHAT
V
vue-advanced-chat
communicationjavascriptv2.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

VueAdvancedChat (as custom element registration)
import 'vue-advanced-chat';
import { VueAdvancedChat } from 'vue-advanced-chat';
This import primarily serves to register the `<vue-advanced-chat>` and `<emoji-picker>` custom elements globally in your application's entry point, rather than importing a specific JavaScript symbol. It's a side-effect import.
CSS Styles
import 'vue-advanced-chat/dist/vue-advanced-chat.css';
This stylesheet is essential for the component's appearance and should be imported in your main application entry file (e.g., `main.js` or `App.vue`'s script setup) or a global stylesheet.
TypeScript Types
import type { ChatMessage, Room, User } from 'vue-advanced-chat/dist/types';
import { ChatMessage } from 'vue-advanced-chat';
For type safety in TypeScript projects, import specific interfaces and types like `ChatMessage`, `Room`, or `User` directly from the `/dist/types` path, as they are not typically exported from the main package entry.

This quickstart demonstrates how to set up `vue-advanced-chat` in a Vue 3 application using Vite. It covers the necessary `vite.config.ts` modifications to recognize custom elements, global CSS and component registration, and a basic `App.vue` component structure with example rooms, messages, and event handlers for sending and fetching messages.

/* vite.config.ts */ import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; export default defineConfig({ plugins: [ vue({ template: { compilerOptions: { // Crucial for Vue to recognize vue-advanced-chat and emoji-picker as custom elements isCustomElement: tagName => tagName === 'vue-advanced-chat' || tagName === 'emoji-picker' } } }) ] }); /* main.ts or main.js */ import { createApp } from 'vue'; import App from './App.vue'; import 'vue-advanced-chat/dist/vue-advanced-chat.css'; // Essential styles import 'vue-advanced-chat'; // Registers the custom Web Components const app = createApp(App); app.mount('#app'); /* App.vue */ <template> <div id="app-container"> <vue-advanced-chat height="100vh" :current-user-id="currentUserId" :rooms="JSON.stringify(rooms)" :rooms-loaded="true" :messages="JSON.stringify(messages)" :messages-loaded="true" @send-message="handleSendMessage" @fetch-messages="handleFetchMessages" /> </div> </template> <script setup lang="ts"> import { ref } from 'vue'; // For type safety, if using TypeScript // import type { ChatMessage, Room } from 'vue-advanced-chat/dist/types'; const currentUserId = 'user1'; const rooms = ref([ { roomId: 'room1', roomName: 'General Chat', avatar: 'https://via.placeholder.com/150', users: [ { _id: 'user1', username: 'Alice' }, { _id: 'user2', username: 'Bob' } ], lastMessage: { content: 'Hello everyone!', senderId: 'user2', timestamp: Date.now() } }, { roomId: 'room2', roomName: 'Private Discussion', users: [ { _id: 'user1', username: 'Alice' }, { _id: 'user3', username: 'Charlie' } ], lastMessage: { content: 'Meeting at 3 PM?', senderId: 'user3', timestamp: Date.now() } } ]); const messages = ref([ { _id: 'msg1', content: 'Hi there!', senderId: 'user1', timestamp: Date.now() - 60000 }, { _id: 'msg2', content: 'Hello Alice!', senderId: 'user2', timestamp: Date.now() - 30000 }, { _id: 'msg3', content: 'How are you two?', senderId: 'user1', timestamp: Date.now() - 10000 } ]); const handleSendMessage = ({ detail }: any) => { const { roomId, content, files, replyMessage } = detail; // 'detail' contains the event payload console.log('New message:', { roomId, content, files, replyMessage }); messages.value.push({ _id: `msg${Date.now()}`, content: content, senderId: currentUserId, timestamp: Date.now() }); // In a real app, send this message to your backend }; const handleFetchMessages = ({ detail }: any) => { const { room, options } = detail; console.log('Fetching messages for room:', room.roomId, options); // Simulate async fetch for older messages setTimeout(() => { // Add logic to load historical messages based on 'options.reset' or 'options.direction' }, 500); }; </script> <style> body, html, #app { margin: 0; padding: 0; height: 100%; overflow: hidden; /* Important for full-height chat layout */ } #app-container { height: 100vh; width: 100vw; } </style>
Debug
Known issues
gotchaWhen using `vue-advanced-chat` within a Vue.js application, it functions as a Web Component. It is crucial to configure your Vue compiler (e.g., in `vite.config.js` or `vue.config.js`) to recognize `vue-advanced-chat` and `emoji-picker` as custom elements. Failing to do so will result in 'Failed to resolve component' errors.
fix
Add the `isCustomElement` option to your Vue plugin configuration: `compilerOptions: { isCustomElement: tagName => tagName === 'vue-advanced-chat' || tagName === 'emoji-picker' }`.
affects: >=2.0.0
gotchaThe `rooms` and `messages` props on the `<vue-advanced-chat>` component expect stringified JSON arrays, not direct JavaScript objects. Passing raw objects will likely lead to incorrect rendering or runtime errors.
fix
Ensure you `JSON.stringify()` your `rooms` and `messages` data arrays before passing them as props: `:rooms="JSON.stringify(rooms)"` and `:messages="JSON.stringify(messages)"`.
affects: >=2.0.0
gotchaThe component requires a specific CSS file for its styling. If this stylesheet is not imported, the chat interface will appear unstyled, broken, or not function correctly.
fix
Include `import 'vue-advanced-chat/dist/vue-advanced-chat.css';` in your application's entry file (e.g., `main.js`, `main.ts`, or a global styling file) to load the necessary styles.
affects: >=2.0.0
gotchaVue Advanced Chat is backend-agnostic, meaning it does not come with built-in real-time communication logic. You must implement your own backend and integrate it using the component's event API (e.g., `@send-message`, `@fetch-messages`).
fix
Develop or integrate an existing real-time backend solution (e.g., WebSockets, Firebase, Pusher) and connect its data flow to the component's events and prop updates.
affects: >=2.0.0
Errors
Common errors & fixes
[Vue warn]: Failed to resolve component: vue-advanced-chat
`vue-advanced-chat` is being used as a custom HTML element but is not registered as such in your Vue application's compiler options.
fix
In your Vue build configuration (e.g., `vite.config.js` for Vite or `vue.config.js` for Vue CLI), add `isCustomElement: tagName => tagName === 'vue-advanced-chat' || tagName === 'emoji-picker'` within your Vue plugin's `template.compilerOptions`.
(Component appears unstyled or with broken layout)
The core CSS stylesheet for `vue-advanced-chat` has not been imported into your application.
fix
Add `import 'vue-advanced-chat/dist/vue-advanced-chat.css';` to your main JavaScript/TypeScript entry file (e.g., `main.js`, `main.ts`) or a global style entry point.
TypeError: Converting circular structure to JSON
You are passing complex JavaScript objects directly to `rooms` or `messages` props, but the component expects these props to be pre-stringified JSON.
fix
Ensure that the `rooms` and `messages` props are explicitly converted to JSON strings using `JSON.stringify()` before being passed to the component, e.g., `:rooms="JSON.stringify(myRoomsArray)"`.
Messages or rooms do not display, or sending messages does nothing.
The component is backend-agnostic and requires you to implement the logic for fetching and sending messages using its event API. It does not handle data persistence or real-time communication out-of-the-box.
fix
Implement handlers for events like `@send-message` and `@fetch-messages` to interact with your chosen backend service. Update the component's `messages` and `rooms` props with data retrieved from your backend.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
37 hits · last 30 days
node
30
OpenAI (training)
1
Resources
vue-advanced-chat — npm install vue-advanced-chat · libregistry