npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-chat-simulation

v0.2.2

Published

Simple UI chat simulation web component

Downloads

7

Readme

vue-chat-simulation

Simple UI chat simulation web component with a sender and a recipient

component-visualization

Setting up

npm install vue-chat-simulation

Usage

You can use the component as a webcomponent or as a vue component.

Using as a web component

Add the following to head:

<script src="https://unpkg.com/vue"></script>
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="/node_modules/vue-chat-simulation/dist/chat-session.min.js"></script>

or as bundle:

<script src="/node_modules/vue-chat-simulation/dist/chat-session.bundle.js"></script>

Now you can use the component as web component in your HTML document with its props and attributes:

<chat-session
    state="true"
    sender-name="Carol"
    sender-avatar="https://i.pravatar.cc/300?img=1"
    sender-box-animation="fadeInLeft"
    recipient-name="Mia"
    recipient-avatar="https://i.pravatar.cc/300?img=20"
    recipient-box-animation="fadeInRight"
    session-theme=""
    awaiting-respond-animation="elastic"
    responded-animation="bounceIn"
    turn-off-button-info="This button closes the chat session"
    :chat-style="{ fontFamily: 'Arial' }"
></chat-session>

To provide a chat data, you need to keep registered component in a variable or constant:

const Chat = window.ChatSession._wrapper.$refs.inner

The chat data format must be in form of either javascript array or parsed JSON as in /node_modules/vue-chat-simulation/src/assets/data.js:

export const sampleSessionData = [
    {
        id: 0,
        sender: {
            messages: {
                correct: 'Sample correct typed Message from id 0',
                close: null,
                wrong: 'Sample wrong typed Message from id 0'
            },
            status: 0
        },
        recipient: {
            messages: {
                correct: 'Sample correct typed respond from id 0',
                close: null,
                wrong: 'Sample wrong typed respond from id 0'
            },
            status: 0
        },
        redirect: {
            correct: 1,
            close: null,
            wrong: -1
        },
        respond: null,
        feedback: 'Some optional feedback text for id 0',
        status: 0
    },
    {
        id: 1,
        ...
    },
    ...
]

You can override the data as follows:

const sampleOverrideData = [
    {
        id: 0,
        sender: {
            messages: {
                correct: 'Sample correct typed Message from id 0',
                close: 'Sample close typed Message from id 0',
                wrong: 'Sample wrong typed Message from id 0'
            },
            status: 0
        },
        recipient: {
            messages: {
                correct: 'Sample correct typed respond from id 0',
                close: 'Sample close typed respond from id 0',
                wrong: 'Sample wrong typed respond from id 0'
            },
            status: 0
        },
        redirect: {
            correct: -1,
            close: -1,
            wrong: -1
        },
        respond: null,
        feedback: 'Some optional feedback text for id 0',
        status: 0
    }
]

Chat.sessionData = sampleOverrideData

Callbacks

There are some component lifecycle based callbacks and a chat session finished callback

Chat.onCreate = () => {
    console.log('Callback tick for onCreate')
}
Chat.onMount = () => {
    console.log('Callback tick for onMount')
}
Chat.onUpdate = () => {
    console.log('Callback tick for onUpdate')
}
Chat.onDestroyed = () => {
    console.log('Callback tick for onDestroyed')
}
Chat.onFinishSession = (redirect, sessions) => {
    console.log('Callback tick for onFinishSession')
    console.log(redirect, sessions)
}

Using as a vue component

For global or local usage of component add the following

import ChatSimulation from 'vue-chat-simulation'

then register as a component in your component definition:

components: [
    ChatSimulation
]

and finally use in the template:

<ChatSimulation
    state="true"
    sender-name="Carol"
    sender-avatar="https://i.pravatar.cc/300?img=1"
    sender-box-animation="fadeInLeft"
    recipient-name="Mia"
    recipient-avatar="https://i.pravatar.cc/300?img=20"
    recipient-box-animation="fadeInRight"
    session-theme=""
    awaiting-respond-animation="elastic"
    responded-animation="bounceIn"
    turn-off-button-info="This button closes the chat session"
    :chat-style="{ fontFamily: 'Arial' }"
></ChatSimulation>

Tech stack

  • Bootstrap 4
  • Vue CLI 3
  • webcomponentsjs

Contribution

Any contribution is welcome. You can play with the vue component (src/components/ChatSession.vue) any way you want

License

ISC