- threads: reply counts, ChatThreadPane with replies, live replies and thread mute - channel pins in ChatPinsPanel; a refused pin hides the action for the session - reactions, attachments with upload progress and bearer downloads, inline edits, the delete dialog (moderators also in channels) - link cards with the registerEmbedRenderer registry; linkify for escaped text - slash commands: the command picker over chatbots, dispatch with sender-only answers - slots conversation-actions (DMs only) and sidebar-footer - chat-tokens.css and chat-base.css, EN and PL copy, README
86 lines
3.8 KiB
TypeScript
86 lines
3.8 KiB
TypeScript
// vue-chat-layer: the member chat of the SummerCMS chat plugins
|
|
// (golem15.chat /_chat/api/v1, golem15.chatchannels /_chatchannels/api/v1
|
|
// and golem15.chatbots /_chatbots/api/v1) as a Nuxt layer: channels, DMs,
|
|
// threads, mentions, reactions, attachments, pins, slash commands and live
|
|
// updates over the site's one Centrifuge connection.
|
|
//
|
|
// An app consumes it with `extends: ['vue-chat-layer']`, provides the
|
|
// `$chatAuth` hook from a Nuxt plugin (README, "Auth hook"), sets
|
|
// `runtimeConfig.public.chat.hostApiBase` to the base of its host bootstrap
|
|
// (README, "Host bootstrap contract") and renders <ChatPage> and
|
|
// <ChatFloatingPanel>, each inside <ClientOnly>: the components use window,
|
|
// WebSocket and the DOM. The layer adds no pages and no route rules; the
|
|
// app owns its routes and its copy.
|
|
//
|
|
// Every path below is absolute and built from this file's directory: a
|
|
// relative or ~ path in a layer config resolves against the consuming
|
|
// project, not the layer.
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const currentDir = fileURLToPath(new URL('.', import.meta.url))
|
|
const langDir = `${currentDir}i18n/locales/`
|
|
|
|
/** Copy locales the layer ships, each in i18n/locales/<code>.json. */
|
|
const LAYER_LOCALES = ['pl', 'en'] as const
|
|
|
|
/** Locale codes the project enables in its i18n config (strings or objects). */
|
|
function enabledLocaleCodes(locales: unknown): string[] {
|
|
if (!Array.isArray(locales)) return []
|
|
return locales
|
|
.map((l) => (typeof l === 'string' ? l : l && typeof l === 'object' ? (l as { code?: unknown }).code : undefined))
|
|
.filter((c): c is string => typeof c === 'string')
|
|
}
|
|
|
|
export default defineNuxtConfig({
|
|
compatibilityDate: '2025-07-15',
|
|
devtools: { enabled: false },
|
|
|
|
// Declared once here, so the app never re-lists @nuxtjs/i18n (two copies
|
|
// split locale state). The inline module registers the layer's chat.*
|
|
// strings only for the locales the app enables: @nuxtjs/i18n merges every
|
|
// locale a layer declares into the app, which would add locales the app
|
|
// does not have. An app overrides any chat.* key in its own messages.
|
|
modules: [
|
|
'@nuxtjs/i18n',
|
|
(_options: unknown, nuxt: { options: { i18n?: { locales?: unknown } }; hook: (...args: any[]) => void }) => {
|
|
nuxt.hook(
|
|
'i18n:registerModule',
|
|
(register: (config: { langDir: string; locales: Array<{ code: string; file: string }> }) => void) => {
|
|
const enabled = enabledLocaleCodes(nuxt.options.i18n?.locales)
|
|
const locales = LAYER_LOCALES.filter((code) => enabled.includes(code)).map((code) => ({ code, file: `${code}.json` }))
|
|
if (locales.length > 0) register({ langDir, locales })
|
|
},
|
|
)
|
|
},
|
|
],
|
|
|
|
// Tokens first, then the neutral styles that use them. The app's own css
|
|
// array loads after these, so its token overrides win.
|
|
css: [`${currentDir}app/assets/css/chat-tokens.css`, `${currentDir}app/assets/css/chat-base.css`],
|
|
|
|
runtimeConfig: {
|
|
chat: {
|
|
// Server-only base of the chat API for server-side fetches
|
|
// (NUXT_CHAT_API_BASE). The components fetch in the browser only;
|
|
// the key exists for an app page that renders chat data on the
|
|
// server. It never comes from request input.
|
|
apiBase: 'http://127.0.0.1:8096/_chat/api/v1',
|
|
},
|
|
public: {
|
|
chat: {
|
|
// Same-origin bases for browser fetches
|
|
// (NUXT_PUBLIC_CHAT_API_BASE, NUXT_PUBLIC_CHAT_CHANNELS_API_BASE,
|
|
// NUXT_PUBLIC_CHAT_BOTS_API_BASE).
|
|
apiBase: '/_chat/api/v1',
|
|
channelsApiBase: '/_chatchannels/api/v1',
|
|
botsApiBase: '/_chatbots/api/v1',
|
|
// The base of the host's bootstrap routes GET {hostApiBase}/chat and
|
|
// GET {hostApiBase}/chat/members (NUXT_PUBLIC_CHAT_HOST_API_BASE).
|
|
// No default: the host names it, and the chat does not start
|
|
// without it.
|
|
hostApiBase: '',
|
|
},
|
|
},
|
|
},
|
|
})
|