@vitral/chat 0.2.13 → 0.2.15
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/README.md +5 -0
- package/dist/chat.js +1 -0
- package/dist/chat.js.map +1 -1
- package/dist/engine/types.d.ts +2 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -56,3 +56,8 @@ its `feedback`. Copying shows a tick for a moment and is announced.
|
|
|
56
56
|
|
|
57
57
|
The classes and tokens are `@vitral/styles`' `chatStyle`, so a thread follows
|
|
58
58
|
whatever preset the page is themed with.
|
|
59
|
+
|
|
60
|
+
The thread and the code blocks in it wear the theme's drawn scrollbars, the ScrollPanel's, over native
|
|
61
|
+
scrolling: `scrollbar: 'hover'` (the default) shows them under the pointer and
|
|
62
|
+
while scrolling, `'always'` keeps them on the screen, `'native'` gives the
|
|
63
|
+
browser's own back.
|
package/dist/chat.js
CHANGED
package/dist/chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","names":[],"sources":["../src/chat.ts"],"sourcesContent":["import { en, isClient, loadStyle, type Locale } from '@vitral/core';\nimport { createOverlay } from '@vitral/controls';\nimport { createRoot, h, iconNode, mergeAttrs, partResolver, scrollbarSet, type Child, type VElement } from '@vitral/dom';\n// Aliased: this module has a `send` of its own, and a bare `x` reads as a variable.\nimport {\n close as closeIcon,\n getIcon,\n messageSquare as messageSquareIcon,\n paperclip as paperclipIcon,\n registerIcons,\n send as sendIcon,\n thumbsDown as thumbsDownIcon,\n thumbsUp as thumbsUpIcon\n} from '@vitral/icons';\nimport { baseStyle, chatStyle, scrollpanelStyle } from '@vitral/styles';\nimport { announcementOf, messageKeyTarget, showsAvatars } from './engine/state';\nimport type { ChatAttachment, ChatConfig, ChatMessage, ChatVariant } from './engine/types';\nimport { chatView, type ChatActions, type ViewContext } from './render/chat';\n\n/**\n * A conversation with no framework in it: it is handed a configuration, it\n * draws the thread into the element it is given, and it reports what the\n * reader did.\n *\n * The log is one tab stop with a roving focus inside it — the arrows move a\n * message, Home and End jump — so a thread of two hundred messages does not\n * bury the composer behind two hundred tab presses. A message that is still\n * arriving grows in place with a caret after it and is announced only once it\n * settles, because a live region that changes on every token says nothing a\n * screen reader can follow.\n *\n * It scrolls to the newest message as messages arrive, but only while the\n * reader is already at the bottom: scrolling someone away from what they were\n * reading is the one thing an auto-scrolling log must never do. When they have\n * scrolled off, a button offers to take them back.\n */\n\nexport interface ChatHandle {\n element: HTMLElement;\n update(next: Partial<ChatConfig>): void;\n setLocale(locale: Locale): void;\n /** Puts the caret in the composer. */\n focus(): void;\n /** Moves the log to the newest message. */\n scrollToBottom(smooth?: boolean): void;\n /** Whether the reader is at the newest message. */\n atBottom(): boolean;\n destroy(): void;\n}\n\nlet counter = 0;\n\nexport function createChat(element: HTMLElement, config: ChatConfig = {}): ChatHandle {\n let current: ChatConfig = { ...config };\n let destroyed = false;\n\n const id = current.id ?? `vt-chat-${++counter}`;\n const root = createRoot(element);\n const locale = (): Locale => current.locale ?? en;\n const part = partResolver({\n style: chatStyle,\n unstyled: () => !!current.unstyled,\n classes: () => current.classes,\n pt: () => current.pt,\n props: () => current as Record<string, unknown>\n });\n\n if (!current.unstyled) {\n const options = { nonce: current.nonce, cssLayer: current.cssLayer };\n loadStyle(baseStyle.name, baseStyle.css, options);\n loadStyle(chatStyle.name, chatStyle.css, options);\n }\n\n // The ScrollPanel's bars, so one theme dresses every bar.\n const bars = scrollbarSet(() => ({ mode: current.scrollbar, style: scrollpanelStyle, unstyled: current.unstyled, nonce: current.nonce, cssLayer: current.cssLayer }));\n\n // The composer and the launcher draw icons that are not in the base set,\n // so the addon brings its own rather than leaving an application to work\n // out which names it has to register before a chat will draw.\n registerIcons([paperclipIcon, sendIcon, closeIcon, messageSquareIcon, thumbsUpIcon, thumbsDownIcon]);\n // `copy`, `check` and `refresh`, which the other built-in message actions draw, are in the base set.\n\n // ---- what is on screen\n\n const messages = (): ChatMessage[] => current.messages ?? [];\n const variant = (): ChatVariant => current.variant ?? 'basic';\n\n let logEl: HTMLElement | null = null;\n let inputEl: HTMLTextAreaElement | null = null;\n let fileEl: HTMLInputElement | null = null;\n /** The message that holds the log's tab stop. */\n let tabIndex = 0;\n /** The reader has scrolled off the newest message. */\n let away = false;\n let announcement = '';\n /** The last message that had settled, so a stream is announced once it stops. */\n let announcedId: string | number | null = null;\n\n const emit = <K extends keyof NonNullable<ChatConfig['on']>>(name: K, ...args: Parameters<NonNullable<NonNullable<ChatConfig['on']>[K]>>) => {\n const handler = current.on?.[name] as ((...a: unknown[]) => void) | undefined;\n handler?.(...(args as unknown[]));\n };\n\n /** Within a few pixels of the end: a fractional scroll height must not read as \"away\". */\n const isAtBottom = (el: HTMLElement) => el.scrollHeight - el.scrollTop - el.clientHeight < 24;\n\n // ---- what the reader does\n\n function send() {\n if (current.disabled || current.readonly) return;\n const text = (current.draft ?? '').trim();\n const attachments = current.attachments ?? [];\n if (!text && attachments.length === 0) return;\n emit('send', { text, attachments });\n }\n\n const actions: ChatActions = {\n send,\n draft(text) {\n current = { ...current, draft: text };\n grow();\n emit('draft-change', text);\n render();\n },\n inputKeydown(event) {\n if (event.key !== 'Enter') return;\n // Enter sends and Shift+Enter breaks the line, unless the chat was\n // told otherwise — in which case the two swap over.\n const sends = current.sendOnEnter === false ? event.ctrlKey || event.metaKey : !event.shiftKey;\n if (!sends) return;\n event.preventDefault();\n send();\n },\n logKeydown(event) {\n const list = messages();\n const target = messageKeyTarget(tabIndex, event.key, list.length);\n if (target < 0 || target === tabIndex) return;\n event.preventDefault();\n tabIndex = target;\n render();\n focusTabbed();\n },\n focusMessage(index) {\n if (tabIndex === index) return;\n tabIndex = index;\n render();\n },\n retry(message) {\n emit('retry', message);\n },\n messageAction(action, message) {\n if (action.id === 'copy') void copy(message);\n emit('message-action', { action: action.id, message });\n },\n suggest(text) {\n emit('suggestion', text);\n },\n pickFiles() {\n fileEl?.click();\n },\n filesPicked(files) {\n if (files.length) emit('attach', files);\n // Cleared, or choosing the same file twice never fires again.\n if (fileEl) fileEl.value = '';\n },\n detach(attachment, index) {\n emit('detach', attachment, index);\n },\n scrolled(el) {\n const bottom = isAtBottom(el);\n if (bottom === !away) return;\n away = !bottom;\n emit('at-bottom-change', bottom);\n render();\n },\n jump() {\n handle.scrollToBottom(true);\n },\n toggleOpen() {\n const open = !current.open;\n current = { ...current, open };\n emit('open-change', open);\n render();\n }\n };\n\n /** The message just copied, which wears a tick until the timer takes it off. */\n let copied: string | number | null = null;\n let copiedTimer: ReturnType<typeof setTimeout> | undefined;\n async function copy(message: ChatMessage) {\n const text = message.content ?? '';\n try {\n if (typeof navigator === 'undefined' || !navigator.clipboard?.writeText) throw new Error('No clipboard here');\n await navigator.clipboard.writeText(text);\n } catch {\n return;\n }\n if (destroyed) return;\n copied = message.id;\n say(locale().chat.copied);\n clearTimeout(copiedTimer);\n copiedTimer = setTimeout(() => {\n copied = null;\n render();\n }, 2000);\n render();\n }\n\n /** Says something through the live region: emptied first, so the same words twice are read twice. */\n function say(words: string) {\n announcement = '';\n render();\n Promise.resolve().then(() => {\n if (destroyed) return;\n announcement = words;\n render();\n });\n }\n\n /** The composer grows with what is typed, up to `maxRows`, and then scrolls. */\n function grow() {\n if (!inputEl) return;\n const max = current.maxRows ?? 6;\n inputEl.style.height = 'auto';\n const line = parseFloat(getComputedStyle(inputEl).lineHeight) || 20;\n const padding = inputEl.offsetHeight - inputEl.clientHeight + (parseFloat(getComputedStyle(inputEl).paddingTop) || 0) * 2;\n inputEl.style.height = `${Math.min(inputEl.scrollHeight, line * max + padding)}px`;\n }\n\n function focusTabbed() {\n if (!isClient) return;\n logEl?.querySelector<HTMLElement>('[tabindex=\"0\"]')?.focus();\n }\n\n // ---- drawing\n\n const context = (): ViewContext => ({\n config: current,\n locale: locale(),\n variant: variant(),\n messages: messages(),\n ids: { log: `${id}-log`, input: `${id}-input`, message: (index) => `${id}-m${index}` },\n part,\n tabIndex: Math.min(tabIndex, Math.max(0, messages().length - 1)),\n away,\n announcement,\n copied,\n on: actions,\n refs: {\n log: (el) => (logEl = el as HTMLElement | null),\n input: (el) => (inputEl = el as HTMLTextAreaElement | null),\n file: (el) => (fileEl = el as HTMLInputElement | null)\n }\n });\n\n let drawing = false;\n function render() {\n if (destroyed || drawing) return;\n drawing = true;\n try {\n const widget = variant() === 'widget';\n root.attrs(part(widget ? 'widget' : 'root', { variant: variant(), readonly: current.readonly, disabled: current.disabled }));\n root.render(widget ? widgetView() : chatView(context()));\n // The thread, and the code blocks in it that run wider than their bubble.\n bars.sync(logEl ? [logEl, ...Array.from(logEl.querySelectorAll('pre'))] : []);\n if (!widget) panel.close();\n else if (current.open) (panel.isOpen ? panel.update : panel.open)();\n else panel.close();\n } finally {\n drawing = false;\n }\n }\n\n /**\n * The widget: a launcher, and the thread in a panel that opens over the\n * page. The shell is the handle's rather than the view's, because it is the\n * handle that owns whether the panel is open.\n *\n * The panel is hung from the launcher by an overlay rather than positioned\n * inside it. A launcher is dropped wherever an application has room, and\n * the first ancestor with a scrollbar or a hidden overflow would otherwise\n * cut the panel in half — which is exactly what a panel that opens over the\n * page must never let happen.\n */\n let launcherEl: HTMLElement | null = null;\n const panel = createOverlay({\n anchor: () => launcherEl,\n placement: 'top-end',\n offset: 12,\n target: () => current.overlayTarget,\n zIndex: current.zIndex,\n render: () => h('div', mergeAttrs({ id: `${id}-panel` }, part('root', { variant: 'widget' }), part('panel')), ...chatView(context())) as VElement,\n onClose: () => {\n if (!current.open) return;\n current = { ...current, open: false };\n emit('open-change', false);\n render();\n }\n });\n\n function widgetView(): Child[] {\n const open = !!current.open;\n const custom = current.slots?.launcher?.({ open });\n return [\n h(\n 'button',\n mergeAttrs({ key: 'launcher', type: 'button' }, part('launcher'), {\n 'aria-expanded': open ? 'true' : 'false',\n 'aria-controls': `${id}-panel`,\n 'aria-label': open ? locale().chat.closeChat : locale().chat.openChat,\n ref: (el: Element | null) => (launcherEl = el as HTMLElement | null),\n onClick: actions.toggleOpen\n }),\n custom !== null && custom !== undefined ? (custom as Child) : iconNode(getIcon(open ? 'close' : 'messageSquare'))\n )\n ];\n }\n\n // ---- what changed\n\n function afterUpdate(previous: ChatConfig) {\n const list = messages();\n const last = list[list.length - 1];\n\n // A message is announced once it has settled, not while it streams.\n if (last && !last.streaming && last.id !== announcedId) {\n announcedId = last.id;\n const author = last.author ?? (last.role === 'user' ? locale().chat.message : (current.ariaLabel ?? locale().chat.conversation));\n const words = announcementOf(last, author);\n if (words) {\n announcement = '';\n render();\n Promise.resolve().then(() => {\n if (destroyed) return;\n announcement = words;\n render();\n });\n }\n }\n\n // Follow the newest message, but only for a reader who was already there.\n const grew = list.length > (previous.messages?.length ?? 0);\n const streaming = !!last?.streaming;\n if ((grew || streaming) && !away) queueMicrotask(() => handle.scrollToBottom());\n }\n\n const handle: ChatHandle = {\n element,\n update(next) {\n if (destroyed) return;\n const previous = current;\n current = { ...current, ...next };\n // A thread that got shorter must not keep a tab stop past its end.\n tabIndex = Math.min(tabIndex, Math.max(0, messages().length - 1));\n render();\n grow();\n afterUpdate(previous);\n },\n setLocale(next) {\n handle.update({ locale: next });\n },\n focus() {\n inputEl?.focus();\n },\n scrollToBottom(smooth = false) {\n if (!logEl) return;\n // `scrollTo` with options is not everywhere — jsdom has no scrollTo\n // on an element at all — and this runs from a microtask, where a\n // throw goes unhandled and takes the next render with it.\n if (typeof logEl.scrollTo === 'function') logEl.scrollTo({ top: logEl.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });\n else logEl.scrollTop = logEl.scrollHeight;\n if (away) {\n away = false;\n emit('at-bottom-change', true);\n render();\n }\n },\n atBottom: () => !away,\n destroy() {\n if (destroyed) return;\n destroyed = true;\n clearTimeout(copiedTimer);\n panel.destroy();\n bars.destroy();\n root.clear();\n logEl = null;\n inputEl = null;\n fileEl = null;\n }\n };\n\n render();\n // The thread opens at its newest message, which is where a conversation is read from.\n queueMicrotask(() => {\n if (!destroyed) handle.scrollToBottom();\n });\n return handle;\n}\n"],"mappings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F;CAEA,MAAM,SAAqB;EACvB;EACA,OAAO,MAAM;GACT,IAAI,WAAW;GACf,MAAM,WAAW;GACjB,UAAU;IAAE,GAAG;IAAS,GAAG;GAAK;GAEhC,WAAW,KAAK,IAAI,UAAU,KAAK,IAAI,GAAG,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC;GAChE,OAAO;GACP,KAAK;GACL,YAAY,QAAQ;EACxB;EACA,UAAU,MAAM;GACZ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;EAClC;EACA,QAAQ;GACJ,SAAS,MAAM;EACnB;EACA,eAAe,SAAS,OAAO;GAC3B,IAAI,CAAC,OAAO;GAIZ,IAAI,OAAO,MAAM,aAAa,YAAY,MAAM,SAAS;IAAE,KAAK,MAAM;IAAc,UAAU,SAAS,WAAW;GAAO,CAAC;QACrH,MAAM,YAAY,MAAM;GAC7B,IAAI,MAAM;IACN,OAAO;IACP,KAAK,oBAAoB,IAAI;IAC7B,OAAO;GACX;EACJ;EACA,gBAAgB,CAAC;EACjB,UAAU;GACN,IAAI,WAAW;GACf,YAAY;GACZ,aAAa,WAAW;GACxB,MAAM,QAAQ;GACd,KAAK,QAAQ;GACb,KAAK,MAAM;GACX,QAAQ;GACR,UAAU;GACV,SAAS;EACb;CACJ;CAEA,OAAO;CAEP,qBAAqB;EACjB,IAAI,CAAC,WAAW,OAAO,eAAe;CAC1C,CAAC;CACD,OAAO;AACX"}
|
|
1
|
+
{"version":3,"file":"chat.js","names":[],"sources":["../src/chat.ts"],"sourcesContent":["import { en, isClient, loadStyle, type Locale } from '@vitral/core';\nimport { createOverlay } from '@vitral/controls';\nimport { createRoot, h, iconNode, mergeAttrs, partResolver, scrollbarSet, type Child, type VElement } from '@vitral/dom';\n// Aliased: this module has a `send` of its own, and a bare `x` reads as a variable.\nimport {\n close as closeIcon,\n getIcon,\n messageSquare as messageSquareIcon,\n paperclip as paperclipIcon,\n registerIcons,\n send as sendIcon,\n thumbsDown as thumbsDownIcon,\n thumbsUp as thumbsUpIcon\n} from '@vitral/icons';\nimport { baseStyle, chatStyle, scrollpanelStyle } from '@vitral/styles';\nimport { announcementOf, messageKeyTarget, showsAvatars } from './engine/state';\nimport type { ChatAttachment, ChatConfig, ChatMessage, ChatVariant } from './engine/types';\nimport { chatView, type ChatActions, type ViewContext } from './render/chat';\n\n/**\n * A conversation with no framework in it: it is handed a configuration, it\n * draws the thread into the element it is given, and it reports what the\n * reader did.\n *\n * The log is one tab stop with a roving focus inside it — the arrows move a\n * message, Home and End jump — so a thread of two hundred messages does not\n * bury the composer behind two hundred tab presses. A message that is still\n * arriving grows in place with a caret after it and is announced only once it\n * settles, because a live region that changes on every token says nothing a\n * screen reader can follow.\n *\n * It scrolls to the newest message as messages arrive, but only while the\n * reader is already at the bottom: scrolling someone away from what they were\n * reading is the one thing an auto-scrolling log must never do. When they have\n * scrolled off, a button offers to take them back.\n */\n\nexport interface ChatHandle {\n element: HTMLElement;\n update(next: Partial<ChatConfig>): void;\n setLocale(locale: Locale): void;\n /** Puts the caret in the composer. */\n focus(): void;\n /** Moves the log to the newest message. */\n scrollToBottom(smooth?: boolean): void;\n /** Whether the reader is at the newest message. */\n atBottom(): boolean;\n destroy(): void;\n}\n\nlet counter = 0;\n\nexport function createChat(element: HTMLElement, config: ChatConfig = {}): ChatHandle {\n let current: ChatConfig = { ...config };\n let destroyed = false;\n\n const id = current.id ?? `vt-chat-${++counter}`;\n const root = createRoot(element);\n const locale = (): Locale => current.locale ?? en;\n const part = partResolver({\n style: chatStyle,\n unstyled: () => !!current.unstyled,\n classes: () => current.classes,\n pt: () => current.pt,\n props: () => current as Record<string, unknown>\n });\n\n if (!current.unstyled) {\n const options = { nonce: current.nonce, cssLayer: current.cssLayer };\n loadStyle(baseStyle.name, baseStyle.css, options);\n loadStyle(chatStyle.name, chatStyle.css, options);\n }\n\n // The ScrollPanel's bars, so one theme dresses every bar.\n const bars = scrollbarSet(() => ({ mode: current.scrollbar, arrows: current.scrollbarArrows, style: scrollpanelStyle, unstyled: current.unstyled, nonce: current.nonce, cssLayer: current.cssLayer }));\n\n // The composer and the launcher draw icons that are not in the base set,\n // so the addon brings its own rather than leaving an application to work\n // out which names it has to register before a chat will draw.\n registerIcons([paperclipIcon, sendIcon, closeIcon, messageSquareIcon, thumbsUpIcon, thumbsDownIcon]);\n // `copy`, `check` and `refresh`, which the other built-in message actions draw, are in the base set.\n\n // ---- what is on screen\n\n const messages = (): ChatMessage[] => current.messages ?? [];\n const variant = (): ChatVariant => current.variant ?? 'basic';\n\n let logEl: HTMLElement | null = null;\n let inputEl: HTMLTextAreaElement | null = null;\n let fileEl: HTMLInputElement | null = null;\n /** The message that holds the log's tab stop. */\n let tabIndex = 0;\n /** The reader has scrolled off the newest message. */\n let away = false;\n let announcement = '';\n /** The last message that had settled, so a stream is announced once it stops. */\n let announcedId: string | number | null = null;\n\n const emit = <K extends keyof NonNullable<ChatConfig['on']>>(name: K, ...args: Parameters<NonNullable<NonNullable<ChatConfig['on']>[K]>>) => {\n const handler = current.on?.[name] as ((...a: unknown[]) => void) | undefined;\n handler?.(...(args as unknown[]));\n };\n\n /** Within a few pixels of the end: a fractional scroll height must not read as \"away\". */\n const isAtBottom = (el: HTMLElement) => el.scrollHeight - el.scrollTop - el.clientHeight < 24;\n\n // ---- what the reader does\n\n function send() {\n if (current.disabled || current.readonly) return;\n const text = (current.draft ?? '').trim();\n const attachments = current.attachments ?? [];\n if (!text && attachments.length === 0) return;\n emit('send', { text, attachments });\n }\n\n const actions: ChatActions = {\n send,\n draft(text) {\n current = { ...current, draft: text };\n grow();\n emit('draft-change', text);\n render();\n },\n inputKeydown(event) {\n if (event.key !== 'Enter') return;\n // Enter sends and Shift+Enter breaks the line, unless the chat was\n // told otherwise — in which case the two swap over.\n const sends = current.sendOnEnter === false ? event.ctrlKey || event.metaKey : !event.shiftKey;\n if (!sends) return;\n event.preventDefault();\n send();\n },\n logKeydown(event) {\n const list = messages();\n const target = messageKeyTarget(tabIndex, event.key, list.length);\n if (target < 0 || target === tabIndex) return;\n event.preventDefault();\n tabIndex = target;\n render();\n focusTabbed();\n },\n focusMessage(index) {\n if (tabIndex === index) return;\n tabIndex = index;\n render();\n },\n retry(message) {\n emit('retry', message);\n },\n messageAction(action, message) {\n if (action.id === 'copy') void copy(message);\n emit('message-action', { action: action.id, message });\n },\n suggest(text) {\n emit('suggestion', text);\n },\n pickFiles() {\n fileEl?.click();\n },\n filesPicked(files) {\n if (files.length) emit('attach', files);\n // Cleared, or choosing the same file twice never fires again.\n if (fileEl) fileEl.value = '';\n },\n detach(attachment, index) {\n emit('detach', attachment, index);\n },\n scrolled(el) {\n const bottom = isAtBottom(el);\n if (bottom === !away) return;\n away = !bottom;\n emit('at-bottom-change', bottom);\n render();\n },\n jump() {\n handle.scrollToBottom(true);\n },\n toggleOpen() {\n const open = !current.open;\n current = { ...current, open };\n emit('open-change', open);\n render();\n }\n };\n\n /** The message just copied, which wears a tick until the timer takes it off. */\n let copied: string | number | null = null;\n let copiedTimer: ReturnType<typeof setTimeout> | undefined;\n async function copy(message: ChatMessage) {\n const text = message.content ?? '';\n try {\n if (typeof navigator === 'undefined' || !navigator.clipboard?.writeText) throw new Error('No clipboard here');\n await navigator.clipboard.writeText(text);\n } catch {\n return;\n }\n if (destroyed) return;\n copied = message.id;\n say(locale().chat.copied);\n clearTimeout(copiedTimer);\n copiedTimer = setTimeout(() => {\n copied = null;\n render();\n }, 2000);\n render();\n }\n\n /** Says something through the live region: emptied first, so the same words twice are read twice. */\n function say(words: string) {\n announcement = '';\n render();\n Promise.resolve().then(() => {\n if (destroyed) return;\n announcement = words;\n render();\n });\n }\n\n /** The composer grows with what is typed, up to `maxRows`, and then scrolls. */\n function grow() {\n if (!inputEl) return;\n const max = current.maxRows ?? 6;\n inputEl.style.height = 'auto';\n const line = parseFloat(getComputedStyle(inputEl).lineHeight) || 20;\n const padding = inputEl.offsetHeight - inputEl.clientHeight + (parseFloat(getComputedStyle(inputEl).paddingTop) || 0) * 2;\n inputEl.style.height = `${Math.min(inputEl.scrollHeight, line * max + padding)}px`;\n }\n\n function focusTabbed() {\n if (!isClient) return;\n logEl?.querySelector<HTMLElement>('[tabindex=\"0\"]')?.focus();\n }\n\n // ---- drawing\n\n const context = (): ViewContext => ({\n config: current,\n locale: locale(),\n variant: variant(),\n messages: messages(),\n ids: { log: `${id}-log`, input: `${id}-input`, message: (index) => `${id}-m${index}` },\n part,\n tabIndex: Math.min(tabIndex, Math.max(0, messages().length - 1)),\n away,\n announcement,\n copied,\n on: actions,\n refs: {\n log: (el) => (logEl = el as HTMLElement | null),\n input: (el) => (inputEl = el as HTMLTextAreaElement | null),\n file: (el) => (fileEl = el as HTMLInputElement | null)\n }\n });\n\n let drawing = false;\n function render() {\n if (destroyed || drawing) return;\n drawing = true;\n try {\n const widget = variant() === 'widget';\n root.attrs(part(widget ? 'widget' : 'root', { variant: variant(), readonly: current.readonly, disabled: current.disabled }));\n root.render(widget ? widgetView() : chatView(context()));\n // The thread, and the code blocks in it that run wider than their bubble.\n bars.sync(logEl ? [logEl, ...Array.from(logEl.querySelectorAll('pre'))] : []);\n if (!widget) panel.close();\n else if (current.open) (panel.isOpen ? panel.update : panel.open)();\n else panel.close();\n } finally {\n drawing = false;\n }\n }\n\n /**\n * The widget: a launcher, and the thread in a panel that opens over the\n * page. The shell is the handle's rather than the view's, because it is the\n * handle that owns whether the panel is open.\n *\n * The panel is hung from the launcher by an overlay rather than positioned\n * inside it. A launcher is dropped wherever an application has room, and\n * the first ancestor with a scrollbar or a hidden overflow would otherwise\n * cut the panel in half — which is exactly what a panel that opens over the\n * page must never let happen.\n */\n let launcherEl: HTMLElement | null = null;\n const panel = createOverlay({\n anchor: () => launcherEl,\n placement: 'top-end',\n offset: 12,\n target: () => current.overlayTarget,\n zIndex: current.zIndex,\n render: () => h('div', mergeAttrs({ id: `${id}-panel` }, part('root', { variant: 'widget' }), part('panel')), ...chatView(context())) as VElement,\n onClose: () => {\n if (!current.open) return;\n current = { ...current, open: false };\n emit('open-change', false);\n render();\n }\n });\n\n function widgetView(): Child[] {\n const open = !!current.open;\n const custom = current.slots?.launcher?.({ open });\n return [\n h(\n 'button',\n mergeAttrs({ key: 'launcher', type: 'button' }, part('launcher'), {\n 'aria-expanded': open ? 'true' : 'false',\n 'aria-controls': `${id}-panel`,\n 'aria-label': open ? locale().chat.closeChat : locale().chat.openChat,\n ref: (el: Element | null) => (launcherEl = el as HTMLElement | null),\n onClick: actions.toggleOpen\n }),\n custom !== null && custom !== undefined ? (custom as Child) : iconNode(getIcon(open ? 'close' : 'messageSquare'))\n )\n ];\n }\n\n // ---- what changed\n\n function afterUpdate(previous: ChatConfig) {\n const list = messages();\n const last = list[list.length - 1];\n\n // A message is announced once it has settled, not while it streams.\n if (last && !last.streaming && last.id !== announcedId) {\n announcedId = last.id;\n const author = last.author ?? (last.role === 'user' ? locale().chat.message : (current.ariaLabel ?? locale().chat.conversation));\n const words = announcementOf(last, author);\n if (words) {\n announcement = '';\n render();\n Promise.resolve().then(() => {\n if (destroyed) return;\n announcement = words;\n render();\n });\n }\n }\n\n // Follow the newest message, but only for a reader who was already there.\n const grew = list.length > (previous.messages?.length ?? 0);\n const streaming = !!last?.streaming;\n if ((grew || streaming) && !away) queueMicrotask(() => handle.scrollToBottom());\n }\n\n const handle: ChatHandle = {\n element,\n update(next) {\n if (destroyed) return;\n const previous = current;\n current = { ...current, ...next };\n // A thread that got shorter must not keep a tab stop past its end.\n tabIndex = Math.min(tabIndex, Math.max(0, messages().length - 1));\n render();\n grow();\n afterUpdate(previous);\n },\n setLocale(next) {\n handle.update({ locale: next });\n },\n focus() {\n inputEl?.focus();\n },\n scrollToBottom(smooth = false) {\n if (!logEl) return;\n // `scrollTo` with options is not everywhere — jsdom has no scrollTo\n // on an element at all — and this runs from a microtask, where a\n // throw goes unhandled and takes the next render with it.\n if (typeof logEl.scrollTo === 'function') logEl.scrollTo({ top: logEl.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });\n else logEl.scrollTop = logEl.scrollHeight;\n if (away) {\n away = false;\n emit('at-bottom-change', true);\n render();\n }\n },\n atBottom: () => !away,\n destroy() {\n if (destroyed) return;\n destroyed = true;\n clearTimeout(copiedTimer);\n panel.destroy();\n bars.destroy();\n root.clear();\n logEl = null;\n inputEl = null;\n fileEl = null;\n }\n };\n\n render();\n // The thread opens at its newest message, which is where a conversation is read from.\n queueMicrotask(() => {\n if (!destroyed) handle.scrollToBottom();\n });\n return handle;\n}\n"],"mappings":";;;;;;;;AAkDA,IAAI,UAAU;AAEd,SAAgB,WAAW,SAAsB,SAAqB,CAAC,GAAe;CAClF,IAAI,UAAsB,EAAE,GAAG,OAAO;CACtC,IAAI,YAAY;CAEhB,MAAM,KAAK,QAAQ,MAAM,WAAW,EAAE;CACtC,MAAM,OAAO,WAAW,OAAO;CAC/B,MAAM,eAAuB,QAAQ,UAAU;CAC/C,MAAM,OAAO,aAAa;EACtB,OAAO;EACP,gBAAgB,CAAC,CAAC,QAAQ;EAC1B,eAAe,QAAQ;EACvB,UAAU,QAAQ;EAClB,aAAa;CACjB,CAAC;CAED,IAAI,CAAC,QAAQ,UAAU;EACnB,MAAM,UAAU;GAAE,OAAO,QAAQ;GAAO,UAAU,QAAQ;EAAS;EACnE,UAAU,UAAU,MAAM,UAAU,KAAK,OAAO;EAChD,UAAU,UAAU,MAAM,UAAU,KAAK,OAAO;CACpD;CAGA,MAAM,OAAO,oBAAoB;EAAE,MAAM,QAAQ;EAAW,QAAQ,QAAQ;EAAiB,OAAO;EAAkB,UAAU,QAAQ;EAAU,OAAO,QAAQ;EAAO,UAAU,QAAQ;CAAS,EAAE;CAKrM,cAAc;EAAC;EAAe;EAAU;EAAW;EAAmB;EAAc;CAAc,CAAC;CAKnG,MAAM,iBAAgC,QAAQ,YAAY,CAAC;CAC3D,MAAM,gBAA6B,QAAQ,WAAW;CAEtD,IAAI,QAA4B;CAChC,IAAI,UAAsC;CAC1C,IAAI,SAAkC;;CAEtC,IAAI,WAAW;;CAEf,IAAI,OAAO;CACX,I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export interface ChatConfig {
|
|
|
198
198
|
* (`'native'`).
|
|
199
199
|
*/
|
|
200
200
|
scrollbar?: ScrollbarMode;
|
|
201
|
+
/** Arrows at the ends of the drawn bars, as a native bar has. Off by default. */
|
|
202
|
+
scrollbarArrows?: boolean;
|
|
201
203
|
classes?: Partial<Record<string, ClassEntry>>;
|
|
202
204
|
pt?: PassThrough;
|
|
203
205
|
nonce?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitral/chat",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "Framework-free chat for Vitral: the engine (messages, grouping, streaming, the composer) and a DOM renderer with roving focus and live announcements, which the Vue, React and Angular components wrap.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vitral",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@vitral/
|
|
49
|
-
"@vitral/
|
|
50
|
-
"@vitral/
|
|
51
|
-
"@vitral/
|
|
52
|
-
"@vitral/styles": "0.2.
|
|
48
|
+
"@vitral/dom": "0.2.15",
|
|
49
|
+
"@vitral/controls": "0.2.15",
|
|
50
|
+
"@vitral/core": "0.2.15",
|
|
51
|
+
"@vitral/icons": "0.2.15",
|
|
52
|
+
"@vitral/styles": "0.2.15"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "vite build && tsc -p tsconfig.build.json"
|