@nanahoshi/mona-ui 0.43.1 → 0.45.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/chat/package.json +4 -0
- package/docs/api/chat.json +1 -0
- package/docs/api/chat.md +212 -0
- package/docs/api/i18n.json +1 -1
- package/docs/api/i18n.md +34 -0
- package/docs/api/index.json +1 -1
- package/docs/api/locales.json +1 -1
- package/docs/api/locales.md +14 -14
- package/docs/api/timeline.json +1 -0
- package/docs/api/timeline.md +188 -0
- package/docs/chat.md +480 -0
- package/docs/manifest.json +1 -1
- package/docs/timeline.md +482 -0
- package/fesm2022/nanahoshi-mona-ui-chat.mjs +1230 -0
- package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +1 -6
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +37 -0
- package/fesm2022/nanahoshi-mona-ui-internal.mjs +6 -1
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +29 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +29 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +19 -0
- package/fesm2022/nanahoshi-mona-ui-timeline.mjs +1028 -0
- package/i18n/catalogs/en-US.messages.json +19 -0
- package/llms.txt +8 -1
- package/locales/ar-sa/ar-sa.messages.json +19 -0
- package/locales/de-de/de-de.messages.json +19 -0
- package/locales/es-es/es-es.messages.json +19 -0
- package/locales/fr-fr/fr-fr.messages.json +19 -0
- package/locales/id-id/id-id.messages.json +19 -0
- package/locales/it-it/it-it.messages.json +19 -0
- package/locales/ja-jp/ja-jp.messages.json +19 -0
- package/locales/ko-kr/ko-kr.messages.json +19 -0
- package/locales/pl-pl/pl-pl.messages.json +19 -0
- package/locales/pt-br/pt-br.messages.json +19 -0
- package/locales/ru-ru/ru-ru.messages.json +19 -0
- package/locales/tr-tr/tr-tr.messages.json +19 -0
- package/locales/zh-cn/zh-cn.messages.json +19 -0
- package/locales/zh-tw/zh-tw.messages.json +19 -0
- package/package.json +9 -1
- package/timeline/package.json +4 -0
- package/types/nanahoshi-mona-ui-chat.d.ts +424 -0
- package/types/nanahoshi-mona-ui-i18n.d.ts +43 -0
- package/types/nanahoshi-mona-ui-internal.d.ts +4 -0
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +19 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +19 -0
- package/types/nanahoshi-mona-ui-timeline.d.ts +338 -0
|
@@ -0,0 +1,1230 @@
|
|
|
1
|
+
import { NgTemplateOutlet } from "@angular/common";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { Component, DestroyRef, Directive, Injector, TemplateRef, afterNextRender, booleanAttribute, computed, contentChild, effect, inject, input, model, output, signal, untracked, viewChild } from "@angular/core";
|
|
4
|
+
import { LucideArrowDown, LucideFile, LucidePaperclip, LucideSendHorizontal, LucideSquare, LucideX } from "@lucide/angular";
|
|
5
|
+
import { AvatarComponent } from "@nanahoshi/mona-ui/avatar";
|
|
6
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
7
|
+
import { formatFileSize } from "@nanahoshi/mona-ui/file-upload";
|
|
8
|
+
import { MonaI18nService, formatGregorianDateToLocaleString, formatNumber } from "@nanahoshi/mona-ui/i18n";
|
|
9
|
+
import { injectLiveAnnouncer } from "@nanahoshi/mona-ui/internal/live-announcer";
|
|
10
|
+
import { twMerge } from "tailwind-merge";
|
|
11
|
+
import { themeControlSurfaceClasses } from "@nanahoshi/mona-ui/internal";
|
|
12
|
+
import { cva } from "class-variance-authority";
|
|
13
|
+
import { DateTime } from "luxon";
|
|
14
|
+
var ChatAttachmentTemplateDirective = class ChatAttachmentTemplateDirective {
|
|
15
|
+
static ngTemplateContextGuard(_directive, _context) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
static {
|
|
19
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
20
|
+
minVersion: "12.0.0",
|
|
21
|
+
version: "22.2.6",
|
|
22
|
+
ngImport: i0,
|
|
23
|
+
type: ChatAttachmentTemplateDirective,
|
|
24
|
+
deps: [],
|
|
25
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
static {
|
|
29
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
30
|
+
minVersion: "14.0.0",
|
|
31
|
+
version: "22.2.6",
|
|
32
|
+
type: ChatAttachmentTemplateDirective,
|
|
33
|
+
isStandalone: true,
|
|
34
|
+
selector: "ng-template[monaChatAttachmentTemplate]",
|
|
35
|
+
ngImport: i0
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
40
|
+
minVersion: "12.0.0",
|
|
41
|
+
version: "22.2.6",
|
|
42
|
+
ngImport: i0,
|
|
43
|
+
type: ChatAttachmentTemplateDirective,
|
|
44
|
+
decorators: [{
|
|
45
|
+
type: Directive,
|
|
46
|
+
args: [{ selector: "ng-template[monaChatAttachmentTemplate]" }]
|
|
47
|
+
}]
|
|
48
|
+
});
|
|
49
|
+
var ChatEmptyTemplateDirective = class ChatEmptyTemplateDirective {
|
|
50
|
+
static {
|
|
51
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
52
|
+
minVersion: "12.0.0",
|
|
53
|
+
version: "22.2.6",
|
|
54
|
+
ngImport: i0,
|
|
55
|
+
type: ChatEmptyTemplateDirective,
|
|
56
|
+
deps: [],
|
|
57
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
static {
|
|
61
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
62
|
+
minVersion: "14.0.0",
|
|
63
|
+
version: "22.2.6",
|
|
64
|
+
type: ChatEmptyTemplateDirective,
|
|
65
|
+
isStandalone: true,
|
|
66
|
+
selector: "ng-template[monaChatEmptyTemplate]",
|
|
67
|
+
ngImport: i0
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
72
|
+
minVersion: "12.0.0",
|
|
73
|
+
version: "22.2.6",
|
|
74
|
+
ngImport: i0,
|
|
75
|
+
type: ChatEmptyTemplateDirective,
|
|
76
|
+
decorators: [{
|
|
77
|
+
type: Directive,
|
|
78
|
+
args: [{ selector: "ng-template[monaChatEmptyTemplate]" }]
|
|
79
|
+
}]
|
|
80
|
+
});
|
|
81
|
+
var ChatMessageTemplateDirective = class ChatMessageTemplateDirective {
|
|
82
|
+
static ngTemplateContextGuard(_directive, _context) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
static {
|
|
86
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
87
|
+
minVersion: "12.0.0",
|
|
88
|
+
version: "22.2.6",
|
|
89
|
+
ngImport: i0,
|
|
90
|
+
type: ChatMessageTemplateDirective,
|
|
91
|
+
deps: [],
|
|
92
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
static {
|
|
96
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
97
|
+
minVersion: "14.0.0",
|
|
98
|
+
version: "22.2.6",
|
|
99
|
+
type: ChatMessageTemplateDirective,
|
|
100
|
+
isStandalone: true,
|
|
101
|
+
selector: "ng-template[monaChatMessageTemplate]",
|
|
102
|
+
ngImport: i0
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
107
|
+
minVersion: "12.0.0",
|
|
108
|
+
version: "22.2.6",
|
|
109
|
+
ngImport: i0,
|
|
110
|
+
type: ChatMessageTemplateDirective,
|
|
111
|
+
decorators: [{
|
|
112
|
+
type: Directive,
|
|
113
|
+
args: [{ selector: "ng-template[monaChatMessageTemplate]" }]
|
|
114
|
+
}]
|
|
115
|
+
});
|
|
116
|
+
function localizeNumber(value, options) {
|
|
117
|
+
return formatNumber(value, "en-US", options);
|
|
118
|
+
}
|
|
119
|
+
const CHAT_DEFAULT_MESSAGES = {
|
|
120
|
+
attachFiles: "Attach files",
|
|
121
|
+
messageBox: "Message",
|
|
122
|
+
messages: "Messages",
|
|
123
|
+
newMessage: (name, text) => `${name}: ${text}`,
|
|
124
|
+
newMessages: "New messages",
|
|
125
|
+
noMessages: "No messages yet",
|
|
126
|
+
notSent: "Not sent",
|
|
127
|
+
placeholder: "Type a message",
|
|
128
|
+
removeFile: (name) => `Remove ${name}`,
|
|
129
|
+
retry: "Retry",
|
|
130
|
+
send: "Send",
|
|
131
|
+
sending: "Sending",
|
|
132
|
+
stop: "Stop",
|
|
133
|
+
suggestions: "Suggested replies",
|
|
134
|
+
typing: (names, count) => count === 1 ? `${names} is typing` : `${names} are typing`,
|
|
135
|
+
typingMany: (count) => count === 1 ? `${localizeNumber(count)} person is typing` : `${localizeNumber(count)} people are typing`,
|
|
136
|
+
you: "You"
|
|
137
|
+
};
|
|
138
|
+
const chatBaseThemeVariants = cva(`
|
|
139
|
+
flex h-128 w-full min-w-0 flex-col overflow-hidden
|
|
140
|
+
rounded-lg border border-border bg-surface text-foreground
|
|
141
|
+
`);
|
|
142
|
+
const CHAT_LOG_FRAME_CLASSES = "relative flex min-h-0 flex-1 flex-col";
|
|
143
|
+
const CHAT_LOG_CLASSES = `
|
|
144
|
+
flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain p-4
|
|
145
|
+
focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus-indicator
|
|
146
|
+
`;
|
|
147
|
+
const CHAT_EMPTY_CLASSES = "m-auto max-w-full text-center text-sm text-muted-foreground";
|
|
148
|
+
const CHAT_DAY_CLASSES = "flex flex-col gap-4";
|
|
149
|
+
const CHAT_DAY_LABEL_CLASSES = `
|
|
150
|
+
flex items-center gap-3 text-xs font-medium text-muted-foreground
|
|
151
|
+
before:h-px before:flex-1 before:bg-border after:h-px after:flex-1 after:bg-border
|
|
152
|
+
forced-colors:before:bg-[GrayText] forced-colors:after:bg-[GrayText]
|
|
153
|
+
`;
|
|
154
|
+
const chatRunThemeVariants = cva("flex min-w-0 gap-2", {
|
|
155
|
+
variants: { mine: {
|
|
156
|
+
true: "justify-end",
|
|
157
|
+
false: "justify-start"
|
|
158
|
+
} },
|
|
159
|
+
defaultVariants: { mine: false }
|
|
160
|
+
});
|
|
161
|
+
const CHAT_AVATAR_CLASSES = "mt-5 shrink-0";
|
|
162
|
+
const chatRunBodyThemeVariants = cva("flex min-w-0 max-w-[min(36rem,85%)] flex-col gap-1", {
|
|
163
|
+
variants: { mine: {
|
|
164
|
+
true: "items-end",
|
|
165
|
+
false: "items-start"
|
|
166
|
+
} },
|
|
167
|
+
defaultVariants: { mine: false }
|
|
168
|
+
});
|
|
169
|
+
const CHAT_AUTHOR_CLASSES = "px-1 text-xs font-medium text-muted-foreground";
|
|
170
|
+
const chatBubbleThemeVariants = cva("max-w-full min-w-0 rounded-2xl border border-transparent px-3 py-2 text-sm wrap-break-word [&>p:has(+[data-chat-caret])]:inline", {
|
|
171
|
+
variants: {
|
|
172
|
+
mine: {
|
|
173
|
+
true: "bg-primary text-primary-foreground",
|
|
174
|
+
false: "bg-surface-muted text-foreground"
|
|
175
|
+
},
|
|
176
|
+
sending: {
|
|
177
|
+
true: "opacity-70",
|
|
178
|
+
false: ""
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
defaultVariants: {
|
|
182
|
+
mine: false,
|
|
183
|
+
sending: false
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
const CHAT_TEXT_CLASSES = "m-0 whitespace-pre-wrap";
|
|
187
|
+
const CHAT_CARET_CLASSES = `
|
|
188
|
+
ms-0.5 inline-block h-[1em] w-[0.45em] translate-y-[0.15em] rounded-[1px] bg-current
|
|
189
|
+
animate-pulse motion-reduce:animate-none forced-color-adjust-none forced-colors:bg-[CanvasText]
|
|
190
|
+
`;
|
|
191
|
+
const CHAT_ATTACHMENTS_CLASSES = "m-0 mt-2 flex list-none flex-col gap-1.5 p-0 first:mt-0";
|
|
192
|
+
const CHAT_ATTACHMENT_CLASSES = "flex min-w-0 flex-col gap-1";
|
|
193
|
+
const CHAT_ATTACHMENT_IMAGE_CLASSES = "block max-h-48 max-w-full rounded-lg object-cover";
|
|
194
|
+
const CHAT_ATTACHMENT_ROW_CLASSES = "flex min-w-0 items-center gap-1.5";
|
|
195
|
+
const chatAttachmentLinkThemeVariants = cva("min-w-0 truncate underline underline-offset-2", {
|
|
196
|
+
variants: { mine: {
|
|
197
|
+
true: "text-primary-foreground",
|
|
198
|
+
false: "text-foreground"
|
|
199
|
+
} },
|
|
200
|
+
defaultVariants: { mine: false }
|
|
201
|
+
});
|
|
202
|
+
const CHAT_ATTACHMENT_SIZE_CLASSES = "shrink-0 text-xs opacity-80";
|
|
203
|
+
const CHAT_STATUS_CLASSES = "flex items-center gap-2 px-1 text-xs text-muted-foreground";
|
|
204
|
+
const CHAT_FAILED_CLASSES = "flex items-center gap-2 px-1 text-xs text-error";
|
|
205
|
+
const CHAT_TIME_CLASSES = "px-1 text-xs text-muted-foreground";
|
|
206
|
+
const CHAT_NEW_MESSAGES_CLASSES = "absolute inset-x-0 bottom-3 mx-auto w-fit shadow-(--shadow-raised)";
|
|
207
|
+
const CHAT_TYPING_CLASSES = "flex min-h-5 items-center gap-2 px-4 text-xs text-muted-foreground";
|
|
208
|
+
const CHAT_TYPING_DOTS_CLASSES = `
|
|
209
|
+
flex items-center gap-0.5
|
|
210
|
+
[&>span]:size-1 [&>span]:rounded-full [&>span]:bg-current
|
|
211
|
+
[&>span]:animate-bounce motion-reduce:[&>span]:animate-none
|
|
212
|
+
[&>span:nth-child(2)]:[animation-delay:150ms] [&>span:nth-child(3)]:[animation-delay:300ms]
|
|
213
|
+
forced-color-adjust-none forced-colors:[&>span]:bg-[CanvasText]
|
|
214
|
+
`;
|
|
215
|
+
const CHAT_SUGGESTIONS_CLASSES = "flex flex-wrap gap-2 px-4 pt-1";
|
|
216
|
+
const CHAT_COMPOSER_CLASSES = "flex flex-col gap-2 p-3";
|
|
217
|
+
const CHAT_FILES_CLASSES = "m-0 flex list-none flex-wrap gap-2 p-0";
|
|
218
|
+
const CHAT_FILE_CLASSES = `
|
|
219
|
+
flex max-w-full min-w-0 items-center gap-1.5 rounded-md border border-border bg-surface-muted
|
|
220
|
+
py-0.5 ps-2 pe-0.5 text-xs
|
|
221
|
+
`;
|
|
222
|
+
const CHAT_FILE_NAME_CLASSES = "min-w-0 truncate";
|
|
223
|
+
const CHAT_FIELD_CLASSES = `
|
|
224
|
+
flex items-end gap-1 rounded-xl p-1
|
|
225
|
+
${themeControlSurfaceClasses}
|
|
226
|
+
border border-input-border shadow-(--shadow-control)
|
|
227
|
+
transition-[color,box-shadow,border] duration-(--mona-motion-standard) ease-in-out
|
|
228
|
+
focus-within:border-focus-indicator focus-within:ring-2 focus-within:ring-focus-indicator/35
|
|
229
|
+
data-[disabled]:cursor-not-allowed data-[disabled]:border-disabled-border data-[disabled]:bg-disabled-background
|
|
230
|
+
data-[disabled]:shadow-none
|
|
231
|
+
`;
|
|
232
|
+
const CHAT_TEXTAREA_CLASSES = `
|
|
233
|
+
max-h-60 min-h-8 min-w-0 flex-1 resize-none border-0 bg-transparent px-2 py-1.5 text-sm text-foreground
|
|
234
|
+
outline-none focus-visible:outline-hidden placeholder:text-muted-foreground
|
|
235
|
+
disabled:cursor-not-allowed disabled:text-disabled-foreground
|
|
236
|
+
`;
|
|
237
|
+
function chatMessageKey(message) {
|
|
238
|
+
return message.id ?? message;
|
|
239
|
+
}
|
|
240
|
+
function chatDayLabel(date, now, locale) {
|
|
241
|
+
const days = DateTime.fromJSDate(date).startOf("day").diff(DateTime.fromJSDate(now).startOf("day"), "days").days;
|
|
242
|
+
const offset = Math.round(days);
|
|
243
|
+
if (Math.abs(offset) <= 1) {
|
|
244
|
+
const text = new Intl.RelativeTimeFormat(locale, { numeric: "auto" }).format(offset, "day");
|
|
245
|
+
return text.charAt(0).toLocaleUpperCase(locale) + text.slice(1);
|
|
246
|
+
}
|
|
247
|
+
const options = {
|
|
248
|
+
day: "numeric",
|
|
249
|
+
month: "long",
|
|
250
|
+
weekday: "long"
|
|
251
|
+
};
|
|
252
|
+
if (date.getFullYear() !== now.getFullYear()) return formatGregorianDateToLocaleString(date, locale, {
|
|
253
|
+
...options,
|
|
254
|
+
year: "numeric"
|
|
255
|
+
});
|
|
256
|
+
return formatGregorianDateToLocaleString(date, locale, options);
|
|
257
|
+
}
|
|
258
|
+
function buildChatDays(messages, options) {
|
|
259
|
+
const days = [];
|
|
260
|
+
let previous = null;
|
|
261
|
+
for (const message of messages) {
|
|
262
|
+
const timestamp = validDate(message.timestamp);
|
|
263
|
+
const dayKey = timestamp == null ? null : DateTime.fromJSDate(timestamp).toISODate();
|
|
264
|
+
let day = days.at(-1);
|
|
265
|
+
if (day == null || dayKey != null && day.key !== dayKey) {
|
|
266
|
+
day = {
|
|
267
|
+
dateTime: dayKey,
|
|
268
|
+
key: dayKey ?? "",
|
|
269
|
+
label: timestamp == null ? "" : chatDayLabel(timestamp, options.now, options.locale),
|
|
270
|
+
runs: []
|
|
271
|
+
};
|
|
272
|
+
days.push(day);
|
|
273
|
+
previous = null;
|
|
274
|
+
}
|
|
275
|
+
const entry = {
|
|
276
|
+
attachments: message.attachments ?? [],
|
|
277
|
+
key: chatMessageKey(message),
|
|
278
|
+
message,
|
|
279
|
+
mine: message.author.id === options.userId
|
|
280
|
+
};
|
|
281
|
+
let run = day.runs.at(-1);
|
|
282
|
+
if (run == null || previous == null || !continuesRun(previous, message)) {
|
|
283
|
+
run = {
|
|
284
|
+
author: message.author,
|
|
285
|
+
dateTime: null,
|
|
286
|
+
entries: [],
|
|
287
|
+
key: entry.key,
|
|
288
|
+
mine: entry.mine,
|
|
289
|
+
timeText: ""
|
|
290
|
+
};
|
|
291
|
+
day.runs.push(run);
|
|
292
|
+
}
|
|
293
|
+
run.entries.push(entry);
|
|
294
|
+
if (timestamp != null) {
|
|
295
|
+
run.dateTime = DateTime.fromJSDate(timestamp).toISO({ suppressMilliseconds: true });
|
|
296
|
+
run.timeText = formatGregorianDateToLocaleString(timestamp, options.locale, options.timeFormat);
|
|
297
|
+
}
|
|
298
|
+
previous = message;
|
|
299
|
+
}
|
|
300
|
+
return days;
|
|
301
|
+
}
|
|
302
|
+
function continuesRun(previous, message) {
|
|
303
|
+
if (previous.author.id !== message.author.id) return false;
|
|
304
|
+
const before = validDate(previous.timestamp);
|
|
305
|
+
const after = validDate(message.timestamp);
|
|
306
|
+
return before == null || after == null || after.getTime() - before.getTime() <= 3e5;
|
|
307
|
+
}
|
|
308
|
+
function validDate(value) {
|
|
309
|
+
return value instanceof Date && Number.isFinite(value.getTime()) ? value : null;
|
|
310
|
+
}
|
|
311
|
+
function sameFile(a, b) {
|
|
312
|
+
return a.name === b.name && a.size === b.size && a.lastModified === b.lastModified;
|
|
313
|
+
}
|
|
314
|
+
var ChatComposerComponent = class ChatComposerComponent {
|
|
315
|
+
#i18n;
|
|
316
|
+
#injector;
|
|
317
|
+
constructor() {
|
|
318
|
+
this.#i18n = inject(MonaI18nService);
|
|
319
|
+
this.#injector = inject(Injector);
|
|
320
|
+
this.canSend = computed(() => !this.disabled() && !this.streaming() && (this.draft().trim().length > 0 || this.files().length > 0), ...ngDevMode ? [{ debugName: "canSend" }] : /* istanbul ignore next */ []);
|
|
321
|
+
this.composerClass = CHAT_COMPOSER_CLASSES;
|
|
322
|
+
this.fieldClass = CHAT_FIELD_CLASSES;
|
|
323
|
+
this.fileClass = CHAT_FILE_CLASSES;
|
|
324
|
+
this.fileNameClass = CHAT_FILE_NAME_CLASSES;
|
|
325
|
+
this.files = signal([], ...ngDevMode ? [{ debugName: "files" }] : /* istanbul ignore next */ []);
|
|
326
|
+
this.filesClass = CHAT_FILES_CLASSES;
|
|
327
|
+
this.messages = this.#i18n.componentMessages("chat", CHAT_DEFAULT_MESSAGES);
|
|
328
|
+
this.placeholderText = computed(() => this.placeholder() || this.messages().placeholder, ...ngDevMode ? [{ debugName: "placeholderText" }] : /* istanbul ignore next */ []);
|
|
329
|
+
this.textAreaClass = CHAT_TEXTAREA_CLASSES;
|
|
330
|
+
this.textAreaRef = viewChild.required("textArea", ...ngDevMode ? [{ debugName: "textAreaRef" }] : /* istanbul ignore next */ []);
|
|
331
|
+
this.accept = input("", ...ngDevMode ? [{ debugName: "accept" }] : /* istanbul ignore next */ []);
|
|
332
|
+
this.allowFiles = input(false, {
|
|
333
|
+
...ngDevMode ? { debugName: "allowFiles" } : /* istanbul ignore next */ {},
|
|
334
|
+
transform: booleanAttribute
|
|
335
|
+
});
|
|
336
|
+
this.disabled = input(false, {
|
|
337
|
+
...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
|
|
338
|
+
transform: booleanAttribute
|
|
339
|
+
});
|
|
340
|
+
this.draft = model("", ...ngDevMode ? [{ debugName: "draft" }] : /* istanbul ignore next */ []);
|
|
341
|
+
this.placeholder = input("", ...ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []);
|
|
342
|
+
this.send = output();
|
|
343
|
+
this.stop = output();
|
|
344
|
+
this.streaming = input(false, {
|
|
345
|
+
...ngDevMode ? { debugName: "streaming" } : /* istanbul ignore next */ {},
|
|
346
|
+
transform: booleanAttribute
|
|
347
|
+
});
|
|
348
|
+
effect(() => {
|
|
349
|
+
this.draft();
|
|
350
|
+
untracked(() => afterNextRender(() => this.#fitTextArea(), { injector: this.#injector }));
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
focus() {
|
|
354
|
+
this.textAreaRef().nativeElement.focus();
|
|
355
|
+
}
|
|
356
|
+
fileSize(file) {
|
|
357
|
+
return formatFileSize(file.size, this.#i18n.localeId());
|
|
358
|
+
}
|
|
359
|
+
onFilesPicked(picker) {
|
|
360
|
+
const picked = Array.from(picker.files ?? []);
|
|
361
|
+
picker.value = "";
|
|
362
|
+
this.files.update((files) => [...files, ...picked.filter((file) => !files.some((other) => sameFile(file, other)))]);
|
|
363
|
+
this.focus();
|
|
364
|
+
}
|
|
365
|
+
onInput(textArea) {
|
|
366
|
+
this.draft.set(textArea.value);
|
|
367
|
+
this.#fitTextArea();
|
|
368
|
+
}
|
|
369
|
+
onKeydown(event) {
|
|
370
|
+
if (event.key !== "Enter" || event.shiftKey || event.isComposing || event.keyCode === 229) return;
|
|
371
|
+
event.preventDefault();
|
|
372
|
+
this.submit();
|
|
373
|
+
}
|
|
374
|
+
removeFile(file) {
|
|
375
|
+
this.files.update((files) => files.filter((other) => other !== file));
|
|
376
|
+
this.focus();
|
|
377
|
+
}
|
|
378
|
+
submit() {
|
|
379
|
+
if (!this.canSend()) return;
|
|
380
|
+
this.send.emit({
|
|
381
|
+
files: this.files(),
|
|
382
|
+
text: this.draft().trim()
|
|
383
|
+
});
|
|
384
|
+
this.draft.set("");
|
|
385
|
+
this.files.set([]);
|
|
386
|
+
this.focus();
|
|
387
|
+
}
|
|
388
|
+
#fitTextArea() {
|
|
389
|
+
const textArea = this.textAreaRef().nativeElement;
|
|
390
|
+
textArea.style.height = "auto";
|
|
391
|
+
textArea.style.height = `${textArea.scrollHeight}px`;
|
|
392
|
+
}
|
|
393
|
+
static {
|
|
394
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
395
|
+
minVersion: "12.0.0",
|
|
396
|
+
version: "22.2.6",
|
|
397
|
+
ngImport: i0,
|
|
398
|
+
type: ChatComposerComponent,
|
|
399
|
+
deps: [],
|
|
400
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
static {
|
|
404
|
+
this.ɵcmp = i0.ɵɵngDeclareComponent({
|
|
405
|
+
minVersion: "17.0.0",
|
|
406
|
+
version: "22.2.6",
|
|
407
|
+
type: ChatComposerComponent,
|
|
408
|
+
isStandalone: true,
|
|
409
|
+
selector: "mona-chat-composer",
|
|
410
|
+
inputs: {
|
|
411
|
+
accept: {
|
|
412
|
+
classPropertyName: "accept",
|
|
413
|
+
publicName: "accept",
|
|
414
|
+
isSignal: true,
|
|
415
|
+
isRequired: false,
|
|
416
|
+
transformFunction: null
|
|
417
|
+
},
|
|
418
|
+
allowFiles: {
|
|
419
|
+
classPropertyName: "allowFiles",
|
|
420
|
+
publicName: "allowFiles",
|
|
421
|
+
isSignal: true,
|
|
422
|
+
isRequired: false,
|
|
423
|
+
transformFunction: null
|
|
424
|
+
},
|
|
425
|
+
disabled: {
|
|
426
|
+
classPropertyName: "disabled",
|
|
427
|
+
publicName: "disabled",
|
|
428
|
+
isSignal: true,
|
|
429
|
+
isRequired: false,
|
|
430
|
+
transformFunction: null
|
|
431
|
+
},
|
|
432
|
+
draft: {
|
|
433
|
+
classPropertyName: "draft",
|
|
434
|
+
publicName: "draft",
|
|
435
|
+
isSignal: true,
|
|
436
|
+
isRequired: false,
|
|
437
|
+
transformFunction: null
|
|
438
|
+
},
|
|
439
|
+
placeholder: {
|
|
440
|
+
classPropertyName: "placeholder",
|
|
441
|
+
publicName: "placeholder",
|
|
442
|
+
isSignal: true,
|
|
443
|
+
isRequired: false,
|
|
444
|
+
transformFunction: null
|
|
445
|
+
},
|
|
446
|
+
streaming: {
|
|
447
|
+
classPropertyName: "streaming",
|
|
448
|
+
publicName: "streaming",
|
|
449
|
+
isSignal: true,
|
|
450
|
+
isRequired: false,
|
|
451
|
+
transformFunction: null
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
outputs: {
|
|
455
|
+
draft: "draftChange",
|
|
456
|
+
send: "send",
|
|
457
|
+
stop: "stop"
|
|
458
|
+
},
|
|
459
|
+
host: { properties: { "class": "composerClass" } },
|
|
460
|
+
viewQueries: [{
|
|
461
|
+
propertyName: "textAreaRef",
|
|
462
|
+
first: true,
|
|
463
|
+
predicate: ["textArea"],
|
|
464
|
+
descendants: true,
|
|
465
|
+
isSignal: true
|
|
466
|
+
}],
|
|
467
|
+
ngImport: i0,
|
|
468
|
+
template: "@if (files().length > 0) {\n <ul [class]=\"filesClass\">\n @for (file of files(); track file) {\n <li [class]=\"fileClass\">\n <span dir=\"auto\" [class]=\"fileNameClass\">{{ file.name }}</span>\n <span class=\"shrink-0 text-muted-foreground\">{{ fileSize(file) }}</span>\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n [iconOnly]=\"true\"\n [attr.aria-label]=\"messages().removeFile(file.name)\"\n (click)=\"removeFile(file)\">\n <svg lucideX [size]=\"14\" aria-hidden=\"true\"></svg>\n </button>\n </li>\n }\n </ul>\n}\n<div [class]=\"fieldClass\" [attr.data-disabled]=\"disabled() || null\">\n @if (allowFiles()) {\n <button\n monaButton\n look=\"ghost\"\n [iconOnly]=\"true\"\n [disabled]=\"disabled()\"\n [attr.aria-label]=\"messages().attachFiles\"\n (click)=\"picker.click()\">\n <svg lucidePaperclip [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n <input #picker type=\"file\" multiple hidden tabindex=\"-1\" [accept]=\"accept()\" (change)=\"onFilesPicked(picker)\" />\n }\n <!-- Empty, the box and its placeholder follow the page; with text, the text's own direction. -->\n <textarea\n #textArea\n rows=\"1\"\n enterkeyhint=\"send\"\n [class]=\"textAreaClass\"\n [attr.dir]=\"draft() ? 'auto' : null\"\n [attr.aria-label]=\"messages().messageBox\"\n [placeholder]=\"placeholderText()\"\n [disabled]=\"disabled()\"\n [value]=\"draft()\"\n (input)=\"onInput(textArea)\"\n (keydown)=\"onKeydown($event)\"></textarea>\n @if (streaming()) {\n <button monaButton look=\"primary\" [iconOnly]=\"true\" [attr.aria-label]=\"messages().stop\" (click)=\"stop.emit()\">\n <svg lucideSquare [size]=\"14\" aria-hidden=\"true\"></svg>\n </button>\n } @else {\n <button\n monaButton\n look=\"primary\"\n [iconOnly]=\"true\"\n [disabled]=\"!canSend()\"\n [attr.aria-label]=\"messages().send\"\n (click)=\"submit()\">\n <svg lucideSendHorizontal [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n</div>\n",
|
|
469
|
+
dependencies: [
|
|
470
|
+
{
|
|
471
|
+
kind: "directive",
|
|
472
|
+
type: ButtonDirective,
|
|
473
|
+
selector: "button[monaButton]",
|
|
474
|
+
inputs: [
|
|
475
|
+
"aria-haspopup",
|
|
476
|
+
"disabled",
|
|
477
|
+
"iconOnly",
|
|
478
|
+
"loading",
|
|
479
|
+
"look",
|
|
480
|
+
"rounded",
|
|
481
|
+
"selected",
|
|
482
|
+
"size",
|
|
483
|
+
"tabindex",
|
|
484
|
+
"toggleable",
|
|
485
|
+
"type",
|
|
486
|
+
"class",
|
|
487
|
+
"value"
|
|
488
|
+
],
|
|
489
|
+
outputs: ["lookChange", "selectedChange"]
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
kind: "component",
|
|
493
|
+
type: LucidePaperclip,
|
|
494
|
+
selector: "svg[lucidePaperclip]"
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
kind: "component",
|
|
498
|
+
type: LucideSendHorizontal,
|
|
499
|
+
selector: "svg[lucideSendHorizontal], svg[lucideSendHorizonal]"
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
kind: "component",
|
|
503
|
+
type: LucideSquare,
|
|
504
|
+
selector: "svg[lucideSquare]"
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
kind: "component",
|
|
508
|
+
type: LucideX,
|
|
509
|
+
selector: "svg[lucideX]"
|
|
510
|
+
}
|
|
511
|
+
]
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
516
|
+
minVersion: "12.0.0",
|
|
517
|
+
version: "22.2.6",
|
|
518
|
+
ngImport: i0,
|
|
519
|
+
type: ChatComposerComponent,
|
|
520
|
+
decorators: [{
|
|
521
|
+
type: Component,
|
|
522
|
+
args: [{
|
|
523
|
+
selector: "mona-chat-composer",
|
|
524
|
+
imports: [
|
|
525
|
+
ButtonDirective,
|
|
526
|
+
LucidePaperclip,
|
|
527
|
+
LucideSendHorizontal,
|
|
528
|
+
LucideSquare,
|
|
529
|
+
LucideX
|
|
530
|
+
],
|
|
531
|
+
host: { "[class]": "composerClass" },
|
|
532
|
+
template: "@if (files().length > 0) {\n <ul [class]=\"filesClass\">\n @for (file of files(); track file) {\n <li [class]=\"fileClass\">\n <span dir=\"auto\" [class]=\"fileNameClass\">{{ file.name }}</span>\n <span class=\"shrink-0 text-muted-foreground\">{{ fileSize(file) }}</span>\n <button\n monaButton\n look=\"ghost\"\n size=\"small\"\n [iconOnly]=\"true\"\n [attr.aria-label]=\"messages().removeFile(file.name)\"\n (click)=\"removeFile(file)\">\n <svg lucideX [size]=\"14\" aria-hidden=\"true\"></svg>\n </button>\n </li>\n }\n </ul>\n}\n<div [class]=\"fieldClass\" [attr.data-disabled]=\"disabled() || null\">\n @if (allowFiles()) {\n <button\n monaButton\n look=\"ghost\"\n [iconOnly]=\"true\"\n [disabled]=\"disabled()\"\n [attr.aria-label]=\"messages().attachFiles\"\n (click)=\"picker.click()\">\n <svg lucidePaperclip [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n <input #picker type=\"file\" multiple hidden tabindex=\"-1\" [accept]=\"accept()\" (change)=\"onFilesPicked(picker)\" />\n }\n <!-- Empty, the box and its placeholder follow the page; with text, the text's own direction. -->\n <textarea\n #textArea\n rows=\"1\"\n enterkeyhint=\"send\"\n [class]=\"textAreaClass\"\n [attr.dir]=\"draft() ? 'auto' : null\"\n [attr.aria-label]=\"messages().messageBox\"\n [placeholder]=\"placeholderText()\"\n [disabled]=\"disabled()\"\n [value]=\"draft()\"\n (input)=\"onInput(textArea)\"\n (keydown)=\"onKeydown($event)\"></textarea>\n @if (streaming()) {\n <button monaButton look=\"primary\" [iconOnly]=\"true\" [attr.aria-label]=\"messages().stop\" (click)=\"stop.emit()\">\n <svg lucideSquare [size]=\"14\" aria-hidden=\"true\"></svg>\n </button>\n } @else {\n <button\n monaButton\n look=\"primary\"\n [iconOnly]=\"true\"\n [disabled]=\"!canSend()\"\n [attr.aria-label]=\"messages().send\"\n (click)=\"submit()\">\n <svg lucideSendHorizontal [size]=\"16\" aria-hidden=\"true\"></svg>\n </button>\n }\n</div>\n"
|
|
533
|
+
}]
|
|
534
|
+
}],
|
|
535
|
+
ctorParameters: () => [],
|
|
536
|
+
propDecorators: {
|
|
537
|
+
textAreaRef: [{
|
|
538
|
+
type: i0.ViewChild,
|
|
539
|
+
args: ["textArea", { isSignal: true }]
|
|
540
|
+
}],
|
|
541
|
+
accept: [{
|
|
542
|
+
type: i0.Input,
|
|
543
|
+
args: [{
|
|
544
|
+
isSignal: true,
|
|
545
|
+
alias: "accept",
|
|
546
|
+
required: false
|
|
547
|
+
}]
|
|
548
|
+
}],
|
|
549
|
+
allowFiles: [{
|
|
550
|
+
type: i0.Input,
|
|
551
|
+
args: [{
|
|
552
|
+
isSignal: true,
|
|
553
|
+
alias: "allowFiles",
|
|
554
|
+
required: false
|
|
555
|
+
}]
|
|
556
|
+
}],
|
|
557
|
+
disabled: [{
|
|
558
|
+
type: i0.Input,
|
|
559
|
+
args: [{
|
|
560
|
+
isSignal: true,
|
|
561
|
+
alias: "disabled",
|
|
562
|
+
required: false
|
|
563
|
+
}]
|
|
564
|
+
}],
|
|
565
|
+
draft: [{
|
|
566
|
+
type: i0.Input,
|
|
567
|
+
args: [{
|
|
568
|
+
isSignal: true,
|
|
569
|
+
alias: "draft",
|
|
570
|
+
required: false
|
|
571
|
+
}]
|
|
572
|
+
}, {
|
|
573
|
+
type: i0.Output,
|
|
574
|
+
args: ["draftChange"]
|
|
575
|
+
}],
|
|
576
|
+
placeholder: [{
|
|
577
|
+
type: i0.Input,
|
|
578
|
+
args: [{
|
|
579
|
+
isSignal: true,
|
|
580
|
+
alias: "placeholder",
|
|
581
|
+
required: false
|
|
582
|
+
}]
|
|
583
|
+
}],
|
|
584
|
+
send: [{
|
|
585
|
+
type: i0.Output,
|
|
586
|
+
args: ["send"]
|
|
587
|
+
}],
|
|
588
|
+
stop: [{
|
|
589
|
+
type: i0.Output,
|
|
590
|
+
args: ["stop"]
|
|
591
|
+
}],
|
|
592
|
+
streaming: [{
|
|
593
|
+
type: i0.Input,
|
|
594
|
+
args: [{
|
|
595
|
+
isSignal: true,
|
|
596
|
+
alias: "streaming",
|
|
597
|
+
required: false
|
|
598
|
+
}]
|
|
599
|
+
}]
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
const BOTTOM_SLACK = 32;
|
|
603
|
+
var ChatComponent = class ChatComponent {
|
|
604
|
+
#announcer;
|
|
605
|
+
#i18n;
|
|
606
|
+
#injector;
|
|
607
|
+
#messageList;
|
|
608
|
+
#atBottom;
|
|
609
|
+
#known;
|
|
610
|
+
#messageCount;
|
|
611
|
+
constructor() {
|
|
612
|
+
this.#announcer = injectLiveAnnouncer();
|
|
613
|
+
this.#i18n = inject(MonaI18nService);
|
|
614
|
+
this.#injector = inject(Injector);
|
|
615
|
+
this.#messageList = computed(() => Array.from(this.messages()), ...ngDevMode ? [{ debugName: "#messageList" }] : /* istanbul ignore next */ []);
|
|
616
|
+
this.#atBottom = true;
|
|
617
|
+
this.#known = null;
|
|
618
|
+
this.#messageCount = 0;
|
|
619
|
+
this.attachmentClass = CHAT_ATTACHMENT_CLASSES;
|
|
620
|
+
this.attachmentImageClass = CHAT_ATTACHMENT_IMAGE_CLASSES;
|
|
621
|
+
this.attachmentRowClass = CHAT_ATTACHMENT_ROW_CLASSES;
|
|
622
|
+
this.attachmentSizeClass = CHAT_ATTACHMENT_SIZE_CLASSES;
|
|
623
|
+
this.attachmentTemplate = contentChild(ChatAttachmentTemplateDirective, {
|
|
624
|
+
...ngDevMode ? { debugName: "attachmentTemplate" } : /* istanbul ignore next */ {},
|
|
625
|
+
read: TemplateRef
|
|
626
|
+
});
|
|
627
|
+
this.attachmentsClass = CHAT_ATTACHMENTS_CLASSES;
|
|
628
|
+
this.authorClass = CHAT_AUTHOR_CLASSES;
|
|
629
|
+
this.avatarClass = CHAT_AVATAR_CLASSES;
|
|
630
|
+
this.baseClass = computed(() => twMerge(chatBaseThemeVariants(), this.userClass()), ...ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []);
|
|
631
|
+
this.caretClass = CHAT_CARET_CLASSES;
|
|
632
|
+
this.composerRef = viewChild.required(ChatComposerComponent, ...ngDevMode ? [{ debugName: "composerRef" }] : /* istanbul ignore next */ []);
|
|
633
|
+
this.dayClass = CHAT_DAY_CLASSES;
|
|
634
|
+
this.dayLabelClass = CHAT_DAY_LABEL_CLASSES;
|
|
635
|
+
this.days = computed(() => buildChatDays(this.#messageList(), {
|
|
636
|
+
locale: this.#i18n.localeId(),
|
|
637
|
+
now: /* @__PURE__ */ new Date(),
|
|
638
|
+
timeFormat: this.timeFormat(),
|
|
639
|
+
userId: this.user().id
|
|
640
|
+
}), ...ngDevMode ? [{ debugName: "days" }] : /* istanbul ignore next */ []);
|
|
641
|
+
this.emptyClass = CHAT_EMPTY_CLASSES;
|
|
642
|
+
this.emptyTemplate = contentChild(ChatEmptyTemplateDirective, {
|
|
643
|
+
...ngDevMode ? { debugName: "emptyTemplate" } : /* istanbul ignore next */ {},
|
|
644
|
+
read: TemplateRef
|
|
645
|
+
});
|
|
646
|
+
this.failedClass = CHAT_FAILED_CLASSES;
|
|
647
|
+
this.labels = this.#i18n.componentMessages("chat", CHAT_DEFAULT_MESSAGES);
|
|
648
|
+
this.logClass = CHAT_LOG_CLASSES;
|
|
649
|
+
this.logFrameClass = CHAT_LOG_FRAME_CLASSES;
|
|
650
|
+
this.logLabel = computed(() => this.ariaLabel().trim() || this.labels().messages, ...ngDevMode ? [{ debugName: "logLabel" }] : /* istanbul ignore next */ []);
|
|
651
|
+
this.logRef = viewChild.required("log", ...ngDevMode ? [{ debugName: "logRef" }] : /* istanbul ignore next */ []);
|
|
652
|
+
this.messageTemplate = contentChild(ChatMessageTemplateDirective, {
|
|
653
|
+
...ngDevMode ? { debugName: "messageTemplate" } : /* istanbul ignore next */ {},
|
|
654
|
+
read: TemplateRef
|
|
655
|
+
});
|
|
656
|
+
this.newMessagesClass = CHAT_NEW_MESSAGES_CLASSES;
|
|
657
|
+
this.statusClass = CHAT_STATUS_CLASSES;
|
|
658
|
+
this.streaming = computed(() => this.#messageList().some((message) => message.streaming === true), ...ngDevMode ? [{ debugName: "streaming" }] : /* istanbul ignore next */ []);
|
|
659
|
+
this.suggestionsClass = CHAT_SUGGESTIONS_CLASSES;
|
|
660
|
+
this.textClass = CHAT_TEXT_CLASSES;
|
|
661
|
+
this.timeClass = CHAT_TIME_CLASSES;
|
|
662
|
+
this.typingClass = CHAT_TYPING_CLASSES;
|
|
663
|
+
this.typingDotsClass = CHAT_TYPING_DOTS_CLASSES;
|
|
664
|
+
this.typingText = computed(() => {
|
|
665
|
+
const users = this.typing();
|
|
666
|
+
const labels = this.labels();
|
|
667
|
+
if (users.length === 0) return "";
|
|
668
|
+
if (users.length > 3) return labels.typingMany(users.length);
|
|
669
|
+
const names = new Intl.ListFormat(this.#i18n.localeId(), {
|
|
670
|
+
style: "long",
|
|
671
|
+
type: "conjunction"
|
|
672
|
+
}).format(users.map((user) => user.name));
|
|
673
|
+
return labels.typing(names, users.length);
|
|
674
|
+
}, ...ngDevMode ? [{ debugName: "typingText" }] : /* istanbul ignore next */ []);
|
|
675
|
+
this.unseen = signal(false, ...ngDevMode ? [{ debugName: "unseen" }] : /* istanbul ignore next */ []);
|
|
676
|
+
this.accept = input("", ...ngDevMode ? [{ debugName: "accept" }] : /* istanbul ignore next */ []);
|
|
677
|
+
this.allowFiles = input(false, {
|
|
678
|
+
...ngDevMode ? { debugName: "allowFiles" } : /* istanbul ignore next */ {},
|
|
679
|
+
transform: booleanAttribute
|
|
680
|
+
});
|
|
681
|
+
this.ariaLabel = input("", {
|
|
682
|
+
...ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {},
|
|
683
|
+
alias: "aria-label"
|
|
684
|
+
});
|
|
685
|
+
this.disabled = input(false, {
|
|
686
|
+
...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
|
|
687
|
+
transform: booleanAttribute
|
|
688
|
+
});
|
|
689
|
+
this.draft = model("", ...ngDevMode ? [{ debugName: "draft" }] : /* istanbul ignore next */ []);
|
|
690
|
+
this.messages = input([], ...ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []);
|
|
691
|
+
this.placeholder = input("", ...ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []);
|
|
692
|
+
this.retry = output();
|
|
693
|
+
this.send = output();
|
|
694
|
+
this.stop = output();
|
|
695
|
+
this.suggestions = input([], ...ngDevMode ? [{ debugName: "suggestions" }] : /* istanbul ignore next */ []);
|
|
696
|
+
this.timeFormat = input({
|
|
697
|
+
hour: "numeric",
|
|
698
|
+
minute: "2-digit"
|
|
699
|
+
}, ...ngDevMode ? [{ debugName: "timeFormat" }] : /* istanbul ignore next */ []);
|
|
700
|
+
this.typing = input([], ...ngDevMode ? [{ debugName: "typing" }] : /* istanbul ignore next */ []);
|
|
701
|
+
this.user = input.required(...ngDevMode ? [{ debugName: "user" }] : /* istanbul ignore next */ []);
|
|
702
|
+
this.userClass = input("", {
|
|
703
|
+
...ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {},
|
|
704
|
+
alias: "class"
|
|
705
|
+
});
|
|
706
|
+
effect(() => {
|
|
707
|
+
const messages = this.#messageList();
|
|
708
|
+
this.days();
|
|
709
|
+
untracked(() => this.#onMessagesChange(messages));
|
|
710
|
+
});
|
|
711
|
+
const destroyRef = inject(DestroyRef);
|
|
712
|
+
afterNextRender(() => {
|
|
713
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
714
|
+
const observer = new ResizeObserver(() => {
|
|
715
|
+
if (this.#atBottom) this.#scrollToBottom();
|
|
716
|
+
});
|
|
717
|
+
observer.observe(this.logRef().nativeElement);
|
|
718
|
+
destroyRef.onDestroy(() => observer.disconnect());
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
focus() {
|
|
722
|
+
this.composerRef().focus();
|
|
723
|
+
}
|
|
724
|
+
attachmentContext(attachment, entry) {
|
|
725
|
+
return {
|
|
726
|
+
$implicit: attachment,
|
|
727
|
+
message: entry.message,
|
|
728
|
+
mine: entry.mine
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
attachmentLinkClass(mine) {
|
|
732
|
+
return chatAttachmentLinkThemeVariants({ mine });
|
|
733
|
+
}
|
|
734
|
+
bubbleClass(entry) {
|
|
735
|
+
return chatBubbleThemeVariants({
|
|
736
|
+
mine: entry.mine,
|
|
737
|
+
sending: entry.message.status === "sending"
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
fileSize(size) {
|
|
741
|
+
return formatFileSize(size, this.#i18n.localeId());
|
|
742
|
+
}
|
|
743
|
+
initials(name) {
|
|
744
|
+
return name.trim().split(/\s+/).slice(0, 2).map((word) => Array.from(word)[0] ?? "").join("").toLocaleUpperCase(this.#i18n.localeId());
|
|
745
|
+
}
|
|
746
|
+
isImage(attachment) {
|
|
747
|
+
return !!attachment.url && !!attachment.type?.startsWith("image/");
|
|
748
|
+
}
|
|
749
|
+
messageContext(entry) {
|
|
750
|
+
return {
|
|
751
|
+
$implicit: entry.message,
|
|
752
|
+
mine: entry.mine
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
onMediaLoad() {
|
|
756
|
+
if (this.#atBottom) this.#scrollToBottom();
|
|
757
|
+
}
|
|
758
|
+
onRetry(message) {
|
|
759
|
+
this.retry.emit(message);
|
|
760
|
+
this.focus();
|
|
761
|
+
}
|
|
762
|
+
onScroll() {
|
|
763
|
+
const log = this.logRef().nativeElement;
|
|
764
|
+
this.#atBottom = log.scrollHeight - log.scrollTop - log.clientHeight <= BOTTOM_SLACK;
|
|
765
|
+
if (this.#atBottom) this.unseen.set(false);
|
|
766
|
+
}
|
|
767
|
+
onSend(event) {
|
|
768
|
+
this.#atBottom = true;
|
|
769
|
+
this.send.emit(event);
|
|
770
|
+
}
|
|
771
|
+
onSuggestion(text) {
|
|
772
|
+
this.onSend({
|
|
773
|
+
files: [],
|
|
774
|
+
text
|
|
775
|
+
});
|
|
776
|
+
this.focus();
|
|
777
|
+
}
|
|
778
|
+
runBodyClass(mine) {
|
|
779
|
+
return chatRunBodyThemeVariants({ mine });
|
|
780
|
+
}
|
|
781
|
+
runClass(mine) {
|
|
782
|
+
return chatRunThemeVariants({ mine });
|
|
783
|
+
}
|
|
784
|
+
showNewMessages() {
|
|
785
|
+
this.#scrollToBottom();
|
|
786
|
+
this.unseen.set(false);
|
|
787
|
+
this.focus();
|
|
788
|
+
}
|
|
789
|
+
#announce(messages) {
|
|
790
|
+
const known = this.#known;
|
|
791
|
+
const next = /* @__PURE__ */ new Map();
|
|
792
|
+
const userId = this.user().id;
|
|
793
|
+
const announcements = [];
|
|
794
|
+
for (const message of messages) {
|
|
795
|
+
const key = chatMessageKey(message);
|
|
796
|
+
const streaming = message.streaming === true;
|
|
797
|
+
next.set(key, streaming);
|
|
798
|
+
if (known == null || streaming || message.author.id === userId || known.get(key) === false) continue;
|
|
799
|
+
const text = message.text?.trim() || (message.attachments ?? []).map((file) => file.name).join(", ");
|
|
800
|
+
if (text) announcements.push(this.labels().newMessage(message.author.name, text));
|
|
801
|
+
}
|
|
802
|
+
this.#known = next;
|
|
803
|
+
if (announcements.length > 0) this.#announcer.announce(announcements.join("\n"), "polite");
|
|
804
|
+
}
|
|
805
|
+
#onMessagesChange(messages) {
|
|
806
|
+
const added = messages.length > this.#messageCount;
|
|
807
|
+
const latestIsMine = added && messages.at(-1)?.author.id === this.user().id;
|
|
808
|
+
this.#messageCount = messages.length;
|
|
809
|
+
this.#announce(messages);
|
|
810
|
+
afterNextRender(() => {
|
|
811
|
+
if (this.#atBottom || latestIsMine) this.#scrollToBottom();
|
|
812
|
+
else if (added) this.unseen.set(true);
|
|
813
|
+
}, { injector: this.#injector });
|
|
814
|
+
}
|
|
815
|
+
#scrollToBottom() {
|
|
816
|
+
const log = this.logRef().nativeElement;
|
|
817
|
+
log.scrollTop = log.scrollHeight;
|
|
818
|
+
this.#atBottom = true;
|
|
819
|
+
}
|
|
820
|
+
static {
|
|
821
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
822
|
+
minVersion: "12.0.0",
|
|
823
|
+
version: "22.2.6",
|
|
824
|
+
ngImport: i0,
|
|
825
|
+
type: ChatComponent,
|
|
826
|
+
deps: [],
|
|
827
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
static {
|
|
831
|
+
this.ɵcmp = i0.ɵɵngDeclareComponent({
|
|
832
|
+
minVersion: "17.0.0",
|
|
833
|
+
version: "22.2.6",
|
|
834
|
+
type: ChatComponent,
|
|
835
|
+
isStandalone: true,
|
|
836
|
+
selector: "mona-chat",
|
|
837
|
+
inputs: {
|
|
838
|
+
accept: {
|
|
839
|
+
classPropertyName: "accept",
|
|
840
|
+
publicName: "accept",
|
|
841
|
+
isSignal: true,
|
|
842
|
+
isRequired: false,
|
|
843
|
+
transformFunction: null
|
|
844
|
+
},
|
|
845
|
+
allowFiles: {
|
|
846
|
+
classPropertyName: "allowFiles",
|
|
847
|
+
publicName: "allowFiles",
|
|
848
|
+
isSignal: true,
|
|
849
|
+
isRequired: false,
|
|
850
|
+
transformFunction: null
|
|
851
|
+
},
|
|
852
|
+
ariaLabel: {
|
|
853
|
+
classPropertyName: "ariaLabel",
|
|
854
|
+
publicName: "aria-label",
|
|
855
|
+
isSignal: true,
|
|
856
|
+
isRequired: false,
|
|
857
|
+
transformFunction: null
|
|
858
|
+
},
|
|
859
|
+
disabled: {
|
|
860
|
+
classPropertyName: "disabled",
|
|
861
|
+
publicName: "disabled",
|
|
862
|
+
isSignal: true,
|
|
863
|
+
isRequired: false,
|
|
864
|
+
transformFunction: null
|
|
865
|
+
},
|
|
866
|
+
draft: {
|
|
867
|
+
classPropertyName: "draft",
|
|
868
|
+
publicName: "draft",
|
|
869
|
+
isSignal: true,
|
|
870
|
+
isRequired: false,
|
|
871
|
+
transformFunction: null
|
|
872
|
+
},
|
|
873
|
+
messages: {
|
|
874
|
+
classPropertyName: "messages",
|
|
875
|
+
publicName: "messages",
|
|
876
|
+
isSignal: true,
|
|
877
|
+
isRequired: false,
|
|
878
|
+
transformFunction: null
|
|
879
|
+
},
|
|
880
|
+
placeholder: {
|
|
881
|
+
classPropertyName: "placeholder",
|
|
882
|
+
publicName: "placeholder",
|
|
883
|
+
isSignal: true,
|
|
884
|
+
isRequired: false,
|
|
885
|
+
transformFunction: null
|
|
886
|
+
},
|
|
887
|
+
suggestions: {
|
|
888
|
+
classPropertyName: "suggestions",
|
|
889
|
+
publicName: "suggestions",
|
|
890
|
+
isSignal: true,
|
|
891
|
+
isRequired: false,
|
|
892
|
+
transformFunction: null
|
|
893
|
+
},
|
|
894
|
+
timeFormat: {
|
|
895
|
+
classPropertyName: "timeFormat",
|
|
896
|
+
publicName: "timeFormat",
|
|
897
|
+
isSignal: true,
|
|
898
|
+
isRequired: false,
|
|
899
|
+
transformFunction: null
|
|
900
|
+
},
|
|
901
|
+
typing: {
|
|
902
|
+
classPropertyName: "typing",
|
|
903
|
+
publicName: "typing",
|
|
904
|
+
isSignal: true,
|
|
905
|
+
isRequired: false,
|
|
906
|
+
transformFunction: null
|
|
907
|
+
},
|
|
908
|
+
user: {
|
|
909
|
+
classPropertyName: "user",
|
|
910
|
+
publicName: "user",
|
|
911
|
+
isSignal: true,
|
|
912
|
+
isRequired: true,
|
|
913
|
+
transformFunction: null
|
|
914
|
+
},
|
|
915
|
+
userClass: {
|
|
916
|
+
classPropertyName: "userClass",
|
|
917
|
+
publicName: "class",
|
|
918
|
+
isSignal: true,
|
|
919
|
+
isRequired: false,
|
|
920
|
+
transformFunction: null
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
outputs: {
|
|
924
|
+
draft: "draftChange",
|
|
925
|
+
retry: "retry",
|
|
926
|
+
send: "send",
|
|
927
|
+
stop: "stop"
|
|
928
|
+
},
|
|
929
|
+
host: { properties: {
|
|
930
|
+
"attr.aria-label": "null",
|
|
931
|
+
"class": "baseClass()"
|
|
932
|
+
} },
|
|
933
|
+
queries: [
|
|
934
|
+
{
|
|
935
|
+
propertyName: "attachmentTemplate",
|
|
936
|
+
first: true,
|
|
937
|
+
predicate: ChatAttachmentTemplateDirective,
|
|
938
|
+
descendants: true,
|
|
939
|
+
read: TemplateRef,
|
|
940
|
+
isSignal: true
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
propertyName: "emptyTemplate",
|
|
944
|
+
first: true,
|
|
945
|
+
predicate: ChatEmptyTemplateDirective,
|
|
946
|
+
descendants: true,
|
|
947
|
+
read: TemplateRef,
|
|
948
|
+
isSignal: true
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
propertyName: "messageTemplate",
|
|
952
|
+
first: true,
|
|
953
|
+
predicate: ChatMessageTemplateDirective,
|
|
954
|
+
descendants: true,
|
|
955
|
+
read: TemplateRef,
|
|
956
|
+
isSignal: true
|
|
957
|
+
}
|
|
958
|
+
],
|
|
959
|
+
viewQueries: [{
|
|
960
|
+
propertyName: "composerRef",
|
|
961
|
+
first: true,
|
|
962
|
+
predicate: ChatComposerComponent,
|
|
963
|
+
descendants: true,
|
|
964
|
+
isSignal: true
|
|
965
|
+
}, {
|
|
966
|
+
propertyName: "logRef",
|
|
967
|
+
first: true,
|
|
968
|
+
predicate: ["log"],
|
|
969
|
+
descendants: true,
|
|
970
|
+
isSignal: true
|
|
971
|
+
}],
|
|
972
|
+
ngImport: i0,
|
|
973
|
+
template: "<div [class]=\"logFrameClass\">\n <!-- Not live: the chat announces new messages itself, once each, rather than each word of a reply streaming in. -->\n <div\n #log\n role=\"log\"\n aria-live=\"off\"\n tabindex=\"0\"\n [class]=\"logClass\"\n [attr.aria-label]=\"logLabel()\"\n (scroll)=\"onScroll()\">\n @for (day of days(); track day.key) {\n <div [class]=\"dayClass\">\n @if (day.label) {\n <div [class]=\"dayLabelClass\">\n <time [attr.datetime]=\"day.dateTime\">{{ day.label }}</time>\n </div>\n }\n @for (run of day.runs; track run.key) {\n <div [class]=\"runClass(run.mine)\">\n @if (!run.mine) {\n <!-- The name is in the text beside it. -->\n <span aria-hidden=\"true\" [class]=\"avatarClass\">\n <mona-avatar\n width=\"2rem\"\n height=\"2rem\"\n borderRadius=\"9999px\"\n borderWidth=\"0\"\n labelFontSize=\"0.75rem\"\n [image]=\"run.author.avatarUrl ?? ''\"\n [label]=\"initials(run.author.name)\" />\n </span>\n }\n <div [class]=\"runBodyClass(run.mine)\">\n <span dir=\"auto\" [class]=\"run.mine ? 'sr-only' : authorClass\">\n {{ run.mine ? labels().you : run.author.name }}\n </span>\n @for (entry of run.entries; track entry.key) {\n <div\n [class]=\"bubbleClass(entry)\"\n [attr.aria-busy]=\"entry.message.streaming ? 'true' : null\">\n @if (messageTemplate(); as template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"messageContext(entry)\" />\n } @else if (entry.message.text) {\n <!-- A message reads in its own direction, whatever the page's. -->\n <p dir=\"auto\" [class]=\"textClass\">{{ entry.message.text }}</p>\n }\n @if (entry.message.streaming) {\n <span data-chat-caret aria-hidden=\"true\" [class]=\"caretClass\"></span>\n }\n @if (entry.attachments.length > 0) {\n <ul [class]=\"attachmentsClass\">\n @for (attachment of entry.attachments; track $index) {\n <li [class]=\"attachmentClass\">\n @if (attachmentTemplate(); as template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"\n attachmentContext(attachment, entry)\n \" />\n } @else {\n @if (isImage(attachment)) {\n <img\n alt=\"\"\n loading=\"lazy\"\n [class]=\"attachmentImageClass\"\n [src]=\"attachment.url\"\n (load)=\"onMediaLoad()\" />\n }\n <span [class]=\"attachmentRowClass\">\n <svg\n lucideFile\n class=\"shrink-0\"\n [size]=\"14\"\n aria-hidden=\"true\"></svg>\n @if (attachment.url) {\n <a\n dir=\"auto\"\n [class]=\"attachmentLinkClass(entry.mine)\"\n [href]=\"attachment.url\"\n target=\"_blank\"\n rel=\"noopener\">\n {{ attachment.name }}\n </a>\n } @else {\n <span dir=\"auto\" class=\"min-w-0 truncate\">\n {{ attachment.name }}\n </span>\n }\n @if (attachment.size !== undefined) {\n <span [class]=\"attachmentSizeClass\">\n {{ fileSize(attachment.size) }}\n </span>\n }\n </span>\n }\n </li>\n }\n </ul>\n }\n </div>\n @if (entry.mine && entry.message.status === \"sending\") {\n <div [class]=\"statusClass\">{{ labels().sending }}</div>\n } @else if (entry.mine && entry.message.status === \"failed\") {\n <div [class]=\"failedClass\">\n <span>{{ labels().notSent }}</span>\n <button\n monaButton\n look=\"link\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (click)=\"onRetry(entry.message)\">\n {{ labels().retry }}\n </button>\n </div>\n }\n }\n @if (run.timeText) {\n <time [class]=\"timeClass\" [attr.datetime]=\"run.dateTime\">{{ run.timeText }}</time>\n }\n </div>\n </div>\n }\n </div>\n } @empty {\n <div [class]=\"emptyClass\">\n @if (emptyTemplate(); as template) {\n <ng-container [ngTemplateOutlet]=\"template\" />\n } @else {\n {{ labels().noMessages }}\n }\n </div>\n }\n </div>\n @if (unseen()) {\n <button monaButton size=\"small\" rounded=\"full\" [class]=\"newMessagesClass\" (click)=\"showNewMessages()\">\n <svg lucideArrowDown [size]=\"14\" aria-hidden=\"true\"></svg>\n {{ labels().newMessages }}\n </button>\n }\n</div>\n<div [class]=\"typingClass\">\n @if (typingText()) {\n <span aria-hidden=\"true\" [class]=\"typingDotsClass\"><span></span><span></span><span></span></span>\n <span>{{ typingText() }}</span>\n }\n</div>\n@if (suggestions().length > 0 && !streaming()) {\n <div role=\"group\" [class]=\"suggestionsClass\" [attr.aria-label]=\"labels().suggestions\">\n @for (suggestion of suggestions(); track $index) {\n <button\n monaButton\n look=\"outline\"\n size=\"small\"\n rounded=\"full\"\n [disabled]=\"disabled()\"\n (click)=\"onSuggestion(suggestion)\">\n {{ suggestion }}\n </button>\n }\n </div>\n}\n<mona-chat-composer\n [accept]=\"accept()\"\n [allowFiles]=\"allowFiles()\"\n [disabled]=\"disabled()\"\n [placeholder]=\"placeholder()\"\n [streaming]=\"streaming()\"\n [(draft)]=\"draft\"\n (send)=\"onSend($event)\"\n (stop)=\"stop.emit()\" />\n",
|
|
974
|
+
dependencies: [
|
|
975
|
+
{
|
|
976
|
+
kind: "component",
|
|
977
|
+
type: AvatarComponent,
|
|
978
|
+
selector: "mona-avatar",
|
|
979
|
+
inputs: [
|
|
980
|
+
"alt",
|
|
981
|
+
"aria-label",
|
|
982
|
+
"backgroundColor",
|
|
983
|
+
"borderColor",
|
|
984
|
+
"borderRadius",
|
|
985
|
+
"borderWidth",
|
|
986
|
+
"customStyles",
|
|
987
|
+
"height",
|
|
988
|
+
"image",
|
|
989
|
+
"label",
|
|
990
|
+
"labelColor",
|
|
991
|
+
"labelFontSize",
|
|
992
|
+
"labelFontWeight",
|
|
993
|
+
"class",
|
|
994
|
+
"width"
|
|
995
|
+
]
|
|
996
|
+
},
|
|
997
|
+
{
|
|
998
|
+
kind: "directive",
|
|
999
|
+
type: ButtonDirective,
|
|
1000
|
+
selector: "button[monaButton]",
|
|
1001
|
+
inputs: [
|
|
1002
|
+
"aria-haspopup",
|
|
1003
|
+
"disabled",
|
|
1004
|
+
"iconOnly",
|
|
1005
|
+
"loading",
|
|
1006
|
+
"look",
|
|
1007
|
+
"rounded",
|
|
1008
|
+
"selected",
|
|
1009
|
+
"size",
|
|
1010
|
+
"tabindex",
|
|
1011
|
+
"toggleable",
|
|
1012
|
+
"type",
|
|
1013
|
+
"class",
|
|
1014
|
+
"value"
|
|
1015
|
+
],
|
|
1016
|
+
outputs: ["lookChange", "selectedChange"]
|
|
1017
|
+
},
|
|
1018
|
+
{
|
|
1019
|
+
kind: "component",
|
|
1020
|
+
type: ChatComposerComponent,
|
|
1021
|
+
selector: "mona-chat-composer",
|
|
1022
|
+
inputs: [
|
|
1023
|
+
"accept",
|
|
1024
|
+
"allowFiles",
|
|
1025
|
+
"disabled",
|
|
1026
|
+
"draft",
|
|
1027
|
+
"placeholder",
|
|
1028
|
+
"streaming"
|
|
1029
|
+
],
|
|
1030
|
+
outputs: [
|
|
1031
|
+
"draftChange",
|
|
1032
|
+
"send",
|
|
1033
|
+
"stop"
|
|
1034
|
+
]
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
kind: "component",
|
|
1038
|
+
type: LucideArrowDown,
|
|
1039
|
+
selector: "svg[lucideArrowDown]"
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
kind: "component",
|
|
1043
|
+
type: LucideFile,
|
|
1044
|
+
selector: "svg[lucideFile]"
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
kind: "directive",
|
|
1048
|
+
type: NgTemplateOutlet,
|
|
1049
|
+
selector: "[ngTemplateOutlet]",
|
|
1050
|
+
inputs: [
|
|
1051
|
+
"ngTemplateOutletContext",
|
|
1052
|
+
"ngTemplateOutlet",
|
|
1053
|
+
"ngTemplateOutletInjector"
|
|
1054
|
+
]
|
|
1055
|
+
}
|
|
1056
|
+
]
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1061
|
+
minVersion: "12.0.0",
|
|
1062
|
+
version: "22.2.6",
|
|
1063
|
+
ngImport: i0,
|
|
1064
|
+
type: ChatComponent,
|
|
1065
|
+
decorators: [{
|
|
1066
|
+
type: Component,
|
|
1067
|
+
args: [{
|
|
1068
|
+
selector: "mona-chat",
|
|
1069
|
+
imports: [
|
|
1070
|
+
AvatarComponent,
|
|
1071
|
+
ButtonDirective,
|
|
1072
|
+
ChatComposerComponent,
|
|
1073
|
+
LucideArrowDown,
|
|
1074
|
+
LucideFile,
|
|
1075
|
+
NgTemplateOutlet
|
|
1076
|
+
],
|
|
1077
|
+
host: {
|
|
1078
|
+
"[attr.aria-label]": "null",
|
|
1079
|
+
"[class]": "baseClass()"
|
|
1080
|
+
},
|
|
1081
|
+
template: "<div [class]=\"logFrameClass\">\n <!-- Not live: the chat announces new messages itself, once each, rather than each word of a reply streaming in. -->\n <div\n #log\n role=\"log\"\n aria-live=\"off\"\n tabindex=\"0\"\n [class]=\"logClass\"\n [attr.aria-label]=\"logLabel()\"\n (scroll)=\"onScroll()\">\n @for (day of days(); track day.key) {\n <div [class]=\"dayClass\">\n @if (day.label) {\n <div [class]=\"dayLabelClass\">\n <time [attr.datetime]=\"day.dateTime\">{{ day.label }}</time>\n </div>\n }\n @for (run of day.runs; track run.key) {\n <div [class]=\"runClass(run.mine)\">\n @if (!run.mine) {\n <!-- The name is in the text beside it. -->\n <span aria-hidden=\"true\" [class]=\"avatarClass\">\n <mona-avatar\n width=\"2rem\"\n height=\"2rem\"\n borderRadius=\"9999px\"\n borderWidth=\"0\"\n labelFontSize=\"0.75rem\"\n [image]=\"run.author.avatarUrl ?? ''\"\n [label]=\"initials(run.author.name)\" />\n </span>\n }\n <div [class]=\"runBodyClass(run.mine)\">\n <span dir=\"auto\" [class]=\"run.mine ? 'sr-only' : authorClass\">\n {{ run.mine ? labels().you : run.author.name }}\n </span>\n @for (entry of run.entries; track entry.key) {\n <div\n [class]=\"bubbleClass(entry)\"\n [attr.aria-busy]=\"entry.message.streaming ? 'true' : null\">\n @if (messageTemplate(); as template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"messageContext(entry)\" />\n } @else if (entry.message.text) {\n <!-- A message reads in its own direction, whatever the page's. -->\n <p dir=\"auto\" [class]=\"textClass\">{{ entry.message.text }}</p>\n }\n @if (entry.message.streaming) {\n <span data-chat-caret aria-hidden=\"true\" [class]=\"caretClass\"></span>\n }\n @if (entry.attachments.length > 0) {\n <ul [class]=\"attachmentsClass\">\n @for (attachment of entry.attachments; track $index) {\n <li [class]=\"attachmentClass\">\n @if (attachmentTemplate(); as template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"\n attachmentContext(attachment, entry)\n \" />\n } @else {\n @if (isImage(attachment)) {\n <img\n alt=\"\"\n loading=\"lazy\"\n [class]=\"attachmentImageClass\"\n [src]=\"attachment.url\"\n (load)=\"onMediaLoad()\" />\n }\n <span [class]=\"attachmentRowClass\">\n <svg\n lucideFile\n class=\"shrink-0\"\n [size]=\"14\"\n aria-hidden=\"true\"></svg>\n @if (attachment.url) {\n <a\n dir=\"auto\"\n [class]=\"attachmentLinkClass(entry.mine)\"\n [href]=\"attachment.url\"\n target=\"_blank\"\n rel=\"noopener\">\n {{ attachment.name }}\n </a>\n } @else {\n <span dir=\"auto\" class=\"min-w-0 truncate\">\n {{ attachment.name }}\n </span>\n }\n @if (attachment.size !== undefined) {\n <span [class]=\"attachmentSizeClass\">\n {{ fileSize(attachment.size) }}\n </span>\n }\n </span>\n }\n </li>\n }\n </ul>\n }\n </div>\n @if (entry.mine && entry.message.status === \"sending\") {\n <div [class]=\"statusClass\">{{ labels().sending }}</div>\n } @else if (entry.mine && entry.message.status === \"failed\") {\n <div [class]=\"failedClass\">\n <span>{{ labels().notSent }}</span>\n <button\n monaButton\n look=\"link\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (click)=\"onRetry(entry.message)\">\n {{ labels().retry }}\n </button>\n </div>\n }\n }\n @if (run.timeText) {\n <time [class]=\"timeClass\" [attr.datetime]=\"run.dateTime\">{{ run.timeText }}</time>\n }\n </div>\n </div>\n }\n </div>\n } @empty {\n <div [class]=\"emptyClass\">\n @if (emptyTemplate(); as template) {\n <ng-container [ngTemplateOutlet]=\"template\" />\n } @else {\n {{ labels().noMessages }}\n }\n </div>\n }\n </div>\n @if (unseen()) {\n <button monaButton size=\"small\" rounded=\"full\" [class]=\"newMessagesClass\" (click)=\"showNewMessages()\">\n <svg lucideArrowDown [size]=\"14\" aria-hidden=\"true\"></svg>\n {{ labels().newMessages }}\n </button>\n }\n</div>\n<div [class]=\"typingClass\">\n @if (typingText()) {\n <span aria-hidden=\"true\" [class]=\"typingDotsClass\"><span></span><span></span><span></span></span>\n <span>{{ typingText() }}</span>\n }\n</div>\n@if (suggestions().length > 0 && !streaming()) {\n <div role=\"group\" [class]=\"suggestionsClass\" [attr.aria-label]=\"labels().suggestions\">\n @for (suggestion of suggestions(); track $index) {\n <button\n monaButton\n look=\"outline\"\n size=\"small\"\n rounded=\"full\"\n [disabled]=\"disabled()\"\n (click)=\"onSuggestion(suggestion)\">\n {{ suggestion }}\n </button>\n }\n </div>\n}\n<mona-chat-composer\n [accept]=\"accept()\"\n [allowFiles]=\"allowFiles()\"\n [disabled]=\"disabled()\"\n [placeholder]=\"placeholder()\"\n [streaming]=\"streaming()\"\n [(draft)]=\"draft\"\n (send)=\"onSend($event)\"\n (stop)=\"stop.emit()\" />\n"
|
|
1082
|
+
}]
|
|
1083
|
+
}],
|
|
1084
|
+
ctorParameters: () => [],
|
|
1085
|
+
propDecorators: {
|
|
1086
|
+
attachmentTemplate: [{
|
|
1087
|
+
type: i0.ContentChild,
|
|
1088
|
+
args: [i0.forwardRef(() => ChatAttachmentTemplateDirective), {
|
|
1089
|
+
read: TemplateRef,
|
|
1090
|
+
isSignal: true
|
|
1091
|
+
}]
|
|
1092
|
+
}],
|
|
1093
|
+
composerRef: [{
|
|
1094
|
+
type: i0.ViewChild,
|
|
1095
|
+
args: [i0.forwardRef(() => ChatComposerComponent), { isSignal: true }]
|
|
1096
|
+
}],
|
|
1097
|
+
emptyTemplate: [{
|
|
1098
|
+
type: i0.ContentChild,
|
|
1099
|
+
args: [i0.forwardRef(() => ChatEmptyTemplateDirective), {
|
|
1100
|
+
read: TemplateRef,
|
|
1101
|
+
isSignal: true
|
|
1102
|
+
}]
|
|
1103
|
+
}],
|
|
1104
|
+
logRef: [{
|
|
1105
|
+
type: i0.ViewChild,
|
|
1106
|
+
args: ["log", { isSignal: true }]
|
|
1107
|
+
}],
|
|
1108
|
+
messageTemplate: [{
|
|
1109
|
+
type: i0.ContentChild,
|
|
1110
|
+
args: [i0.forwardRef(() => ChatMessageTemplateDirective), {
|
|
1111
|
+
read: TemplateRef,
|
|
1112
|
+
isSignal: true
|
|
1113
|
+
}]
|
|
1114
|
+
}],
|
|
1115
|
+
accept: [{
|
|
1116
|
+
type: i0.Input,
|
|
1117
|
+
args: [{
|
|
1118
|
+
isSignal: true,
|
|
1119
|
+
alias: "accept",
|
|
1120
|
+
required: false
|
|
1121
|
+
}]
|
|
1122
|
+
}],
|
|
1123
|
+
allowFiles: [{
|
|
1124
|
+
type: i0.Input,
|
|
1125
|
+
args: [{
|
|
1126
|
+
isSignal: true,
|
|
1127
|
+
alias: "allowFiles",
|
|
1128
|
+
required: false
|
|
1129
|
+
}]
|
|
1130
|
+
}],
|
|
1131
|
+
ariaLabel: [{
|
|
1132
|
+
type: i0.Input,
|
|
1133
|
+
args: [{
|
|
1134
|
+
isSignal: true,
|
|
1135
|
+
alias: "aria-label",
|
|
1136
|
+
required: false
|
|
1137
|
+
}]
|
|
1138
|
+
}],
|
|
1139
|
+
disabled: [{
|
|
1140
|
+
type: i0.Input,
|
|
1141
|
+
args: [{
|
|
1142
|
+
isSignal: true,
|
|
1143
|
+
alias: "disabled",
|
|
1144
|
+
required: false
|
|
1145
|
+
}]
|
|
1146
|
+
}],
|
|
1147
|
+
draft: [{
|
|
1148
|
+
type: i0.Input,
|
|
1149
|
+
args: [{
|
|
1150
|
+
isSignal: true,
|
|
1151
|
+
alias: "draft",
|
|
1152
|
+
required: false
|
|
1153
|
+
}]
|
|
1154
|
+
}, {
|
|
1155
|
+
type: i0.Output,
|
|
1156
|
+
args: ["draftChange"]
|
|
1157
|
+
}],
|
|
1158
|
+
messages: [{
|
|
1159
|
+
type: i0.Input,
|
|
1160
|
+
args: [{
|
|
1161
|
+
isSignal: true,
|
|
1162
|
+
alias: "messages",
|
|
1163
|
+
required: false
|
|
1164
|
+
}]
|
|
1165
|
+
}],
|
|
1166
|
+
placeholder: [{
|
|
1167
|
+
type: i0.Input,
|
|
1168
|
+
args: [{
|
|
1169
|
+
isSignal: true,
|
|
1170
|
+
alias: "placeholder",
|
|
1171
|
+
required: false
|
|
1172
|
+
}]
|
|
1173
|
+
}],
|
|
1174
|
+
retry: [{
|
|
1175
|
+
type: i0.Output,
|
|
1176
|
+
args: ["retry"]
|
|
1177
|
+
}],
|
|
1178
|
+
send: [{
|
|
1179
|
+
type: i0.Output,
|
|
1180
|
+
args: ["send"]
|
|
1181
|
+
}],
|
|
1182
|
+
stop: [{
|
|
1183
|
+
type: i0.Output,
|
|
1184
|
+
args: ["stop"]
|
|
1185
|
+
}],
|
|
1186
|
+
suggestions: [{
|
|
1187
|
+
type: i0.Input,
|
|
1188
|
+
args: [{
|
|
1189
|
+
isSignal: true,
|
|
1190
|
+
alias: "suggestions",
|
|
1191
|
+
required: false
|
|
1192
|
+
}]
|
|
1193
|
+
}],
|
|
1194
|
+
timeFormat: [{
|
|
1195
|
+
type: i0.Input,
|
|
1196
|
+
args: [{
|
|
1197
|
+
isSignal: true,
|
|
1198
|
+
alias: "timeFormat",
|
|
1199
|
+
required: false
|
|
1200
|
+
}]
|
|
1201
|
+
}],
|
|
1202
|
+
typing: [{
|
|
1203
|
+
type: i0.Input,
|
|
1204
|
+
args: [{
|
|
1205
|
+
isSignal: true,
|
|
1206
|
+
alias: "typing",
|
|
1207
|
+
required: false
|
|
1208
|
+
}]
|
|
1209
|
+
}],
|
|
1210
|
+
user: [{
|
|
1211
|
+
type: i0.Input,
|
|
1212
|
+
args: [{
|
|
1213
|
+
isSignal: true,
|
|
1214
|
+
alias: "user",
|
|
1215
|
+
required: true
|
|
1216
|
+
}]
|
|
1217
|
+
}],
|
|
1218
|
+
userClass: [{
|
|
1219
|
+
type: i0.Input,
|
|
1220
|
+
args: [{
|
|
1221
|
+
isSignal: true,
|
|
1222
|
+
alias: "class",
|
|
1223
|
+
required: false
|
|
1224
|
+
}]
|
|
1225
|
+
}]
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
export { CHAT_DEFAULT_MESSAGES, ChatAttachmentTemplateDirective, ChatComponent, ChatEmptyTemplateDirective, ChatMessageTemplateDirective };
|
|
1229
|
+
|
|
1230
|
+
//# sourceMappingURL=nanahoshi-mona-ui-chat.mjs.map
|