@erplora/outfitkit 0.1.1
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/LICENSE +21 -0
- package/README.md +457 -0
- package/dist/base/anchor.d.ts +13 -0
- package/dist/base/define.d.ts +1 -0
- package/dist/base/relay.d.ts +1 -0
- package/dist/cdn.d.ts +96 -0
- package/dist/components/ok-app-launcher/ok-app-launcher.d.ts +57 -0
- package/dist/components/ok-audio/ok-audio.d.ts +45 -0
- package/dist/components/ok-avatar/ok-avatar.d.ts +36 -0
- package/dist/components/ok-avatar-group/ok-avatar-group.d.ts +38 -0
- package/dist/components/ok-bar-list/ok-bar-list.d.ts +36 -0
- package/dist/components/ok-bento/ok-bento.d.ts +17 -0
- package/dist/components/ok-bento-item/ok-bento-item.d.ts +34 -0
- package/dist/components/ok-calculator/ok-calculator.d.ts +46 -0
- package/dist/components/ok-calendar/ok-calendar.d.ts +63 -0
- package/dist/components/ok-carousel/ok-carousel.d.ts +48 -0
- package/dist/components/ok-chart/ok-chart.d.ts +55 -0
- package/dist/components/ok-chat/ok-chat.d.ts +54 -0
- package/dist/components/ok-coachmark/ok-coachmark.d.ts +69 -0
- package/dist/components/ok-code/ok-code.d.ts +28 -0
- package/dist/components/ok-color-picker/ok-color-picker.d.ts +63 -0
- package/dist/components/ok-combo/ok-combo.d.ts +46 -0
- package/dist/components/ok-command-palette/ok-command-palette.d.ts +72 -0
- package/dist/components/ok-contact-form/ok-contact-form.d.ts +54 -0
- package/dist/components/ok-cropper/ok-cropper.d.ts +60 -0
- package/dist/components/ok-cta-band/ok-cta-band.d.ts +18 -0
- package/dist/components/ok-currency/ok-currency.d.ts +31 -0
- package/dist/components/ok-data-table/ok-data-table.d.ts +312 -0
- package/dist/components/ok-date-picker/ok-date-picker.d.ts +81 -0
- package/dist/components/ok-detail-list/ok-detail-list.d.ts +30 -0
- package/dist/components/ok-diff/ok-diff.d.ts +38 -0
- package/dist/components/ok-donut/ok-donut.d.ts +38 -0
- package/dist/components/ok-drawer/ok-drawer.d.ts +56 -0
- package/dist/components/ok-dropzone/ok-dropzone.d.ts +48 -0
- package/dist/components/ok-empty-state/ok-empty-state.d.ts +16 -0
- package/dist/components/ok-error-page/ok-error-page.d.ts +77 -0
- package/dist/components/ok-event-card/ok-event-card.d.ts +56 -0
- package/dist/components/ok-feature-card/ok-feature-card.d.ts +23 -0
- package/dist/components/ok-file-item/ok-file-item.d.ts +31 -0
- package/dist/components/ok-file-manager/ok-file-manager.d.ts +145 -0
- package/dist/components/ok-footer/ok-footer.d.ts +10 -0
- package/dist/components/ok-funnel/ok-funnel.d.ts +31 -0
- package/dist/components/ok-gallery/ok-gallery.d.ts +34 -0
- package/dist/components/ok-gauge/ok-gauge.d.ts +49 -0
- package/dist/components/ok-heatmap/ok-heatmap.d.ts +45 -0
- package/dist/components/ok-hero/ok-hero.d.ts +10 -0
- package/dist/components/ok-hover-card/ok-hover-card.d.ts +76 -0
- package/dist/components/ok-icon-tile/ok-icon-tile.d.ts +24 -0
- package/dist/components/ok-image/ok-image.d.ts +56 -0
- package/dist/components/ok-inline-feedback/ok-inline-feedback.d.ts +33 -0
- package/dist/components/ok-invoice/ok-invoice.d.ts +137 -0
- package/dist/components/ok-json-viewer/ok-json-viewer.d.ts +31 -0
- package/dist/components/ok-kanban/ok-kanban.d.ts +56 -0
- package/dist/components/ok-kbd/ok-kbd.d.ts +21 -0
- package/dist/components/ok-keyboard/ok-keyboard.d.ts +35 -0
- package/dist/components/ok-kpi/ok-kpi.d.ts +24 -0
- package/dist/components/ok-language-select/ok-language-select.d.ts +31 -0
- package/dist/components/ok-lightbox/ok-lightbox.d.ts +59 -0
- package/dist/components/ok-logo-cloud/ok-logo-cloud.d.ts +14 -0
- package/dist/components/ok-loyalty-card/ok-loyalty-card.d.ts +35 -0
- package/dist/components/ok-mail/ok-mail.d.ts +117 -0
- package/dist/components/ok-menu/ok-menu.d.ts +75 -0
- package/dist/components/ok-menubar/ok-menubar.d.ts +75 -0
- package/dist/components/ok-navbar/ok-navbar.d.ts +42 -0
- package/dist/components/ok-notification-center/ok-notification-center.d.ts +79 -0
- package/dist/components/ok-org-chart/ok-org-chart.d.ts +67 -0
- package/dist/components/ok-otp/ok-otp.d.ts +31 -0
- package/dist/components/ok-page-header/ok-page-header.d.ts +23 -0
- package/dist/components/ok-pagination/ok-pagination.d.ts +44 -0
- package/dist/components/ok-pdf/ok-pdf.d.ts +32 -0
- package/dist/components/ok-phone/ok-phone.d.ts +48 -0
- package/dist/components/ok-pinpad/ok-pinpad.d.ts +29 -0
- package/dist/components/ok-pricing-card/ok-pricing-card.d.ts +31 -0
- package/dist/components/ok-product-card/ok-product-card.d.ts +25 -0
- package/dist/components/ok-qr/ok-qr.d.ts +24 -0
- package/dist/components/ok-qty-stepper/ok-qty-stepper.d.ts +35 -0
- package/dist/components/ok-range-dual/ok-range-dual.d.ts +38 -0
- package/dist/components/ok-rating/ok-rating.d.ts +33 -0
- package/dist/components/ok-receipt/ok-receipt.d.ts +103 -0
- package/dist/components/ok-reveal/ok-reveal.d.ts +21 -0
- package/dist/components/ok-rich-text/ok-rich-text.d.ts +46 -0
- package/dist/components/ok-scheduler/ok-scheduler.d.ts +74 -0
- package/dist/components/ok-select-card/ok-select-card.d.ts +37 -0
- package/dist/components/ok-signature/ok-signature.d.ts +55 -0
- package/dist/components/ok-skeleton/ok-skeleton.d.ts +40 -0
- package/dist/components/ok-sparkline/ok-sparkline.d.ts +27 -0
- package/dist/components/ok-split-button/ok-split-button.d.ts +49 -0
- package/dist/components/ok-splitter/ok-splitter.d.ts +36 -0
- package/dist/components/ok-stat/ok-stat.d.ts +16 -0
- package/dist/components/ok-status-dot/ok-status-dot.d.ts +24 -0
- package/dist/components/ok-status-pill/ok-status-pill.d.ts +22 -0
- package/dist/components/ok-stepper/ok-stepper.d.ts +33 -0
- package/dist/components/ok-store/ok-store.d.ts +33 -0
- package/dist/components/ok-tag-input/ok-tag-input.d.ts +39 -0
- package/dist/components/ok-testimonial/ok-testimonial.d.ts +21 -0
- package/dist/components/ok-time-picker/ok-time-picker.d.ts +50 -0
- package/dist/components/ok-timeline/ok-timeline.d.ts +33 -0
- package/dist/components/ok-tree/ok-tree.d.ts +46 -0
- package/dist/components/ok-video/ok-video.d.ts +49 -0
- package/dist/components/ok-widget-board/ok-widget-board.d.ts +71 -0
- package/dist/components/ok-wizard/ok-wizard.d.ts +30 -0
- package/dist/define.js +8 -0
- package/dist/erplora.css +112 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.js +197 -0
- package/dist/layout.css +338 -0
- package/dist/ok-app-launcher.js +396 -0
- package/dist/ok-audio.js +308 -0
- package/dist/ok-avatar-group.js +158 -0
- package/dist/ok-avatar.js +179 -0
- package/dist/ok-bar-list.js +189 -0
- package/dist/ok-bento-item.js +168 -0
- package/dist/ok-bento.js +63 -0
- package/dist/ok-calculator.js +406 -0
- package/dist/ok-calendar.js +541 -0
- package/dist/ok-carousel.js +352 -0
- package/dist/ok-chart.js +325 -0
- package/dist/ok-chat.js +320 -0
- package/dist/ok-coachmark.js +500 -0
- package/dist/ok-code.js +190 -0
- package/dist/ok-color-picker.js +569 -0
- package/dist/ok-combo.js +294 -0
- package/dist/ok-command-palette.js +448 -0
- package/dist/ok-contact-form.js +288 -0
- package/dist/ok-cropper.js +404 -0
- package/dist/ok-cta-band.js +134 -0
- package/dist/ok-currency.js +172 -0
- package/dist/ok-data-table.js +1281 -0
- package/dist/ok-date-picker.js +736 -0
- package/dist/ok-detail-list.js +156 -0
- package/dist/ok-diff.js +200 -0
- package/dist/ok-donut.js +280 -0
- package/dist/ok-drawer.js +357 -0
- package/dist/ok-dropzone.js +376 -0
- package/dist/ok-empty-state.js +104 -0
- package/dist/ok-error-page.js +547 -0
- package/dist/ok-event-card.js +384 -0
- package/dist/ok-feature-card.js +152 -0
- package/dist/ok-file-item.js +259 -0
- package/dist/ok-file-manager.js +1116 -0
- package/dist/ok-footer.js +67 -0
- package/dist/ok-funnel.js +181 -0
- package/dist/ok-gallery.js +293 -0
- package/dist/ok-gauge.js +385 -0
- package/dist/ok-heatmap.js +268 -0
- package/dist/ok-hero.js +43 -0
- package/dist/ok-hover-card.js +480 -0
- package/dist/ok-icon-tile.js +123 -0
- package/dist/ok-image.js +471 -0
- package/dist/ok-inline-feedback.js +221 -0
- package/dist/ok-invoice.js +229 -0
- package/dist/ok-json-viewer.js +330 -0
- package/dist/ok-kanban.js +427 -0
- package/dist/ok-kbd.js +159 -0
- package/dist/ok-keyboard.js +402 -0
- package/dist/ok-kpi.js +147 -0
- package/dist/ok-language-select.js +188 -0
- package/dist/ok-lightbox.js +490 -0
- package/dist/ok-logo-cloud.js +92 -0
- package/dist/ok-loyalty-card.js +353 -0
- package/dist/ok-mail.js +562 -0
- package/dist/ok-menu.js +529 -0
- package/dist/ok-menubar.js +628 -0
- package/dist/ok-navbar.js +306 -0
- package/dist/ok-notification-center.js +545 -0
- package/dist/ok-org-chart.js +619 -0
- package/dist/ok-otp.js +199 -0
- package/dist/ok-page-header.js +202 -0
- package/dist/ok-pagination.js +366 -0
- package/dist/ok-pdf.js +160 -0
- package/dist/ok-phone.js +225 -0
- package/dist/ok-pinpad.js +171 -0
- package/dist/ok-pricing-card.js +184 -0
- package/dist/ok-product-card.js +178 -0
- package/dist/ok-qr.js +652 -0
- package/dist/ok-qty-stepper.js +212 -0
- package/dist/ok-range-dual.js +280 -0
- package/dist/ok-rating.js +199 -0
- package/dist/ok-receipt.js +183 -0
- package/dist/ok-reveal.js +94 -0
- package/dist/ok-rich-text.js +538 -0
- package/dist/ok-scheduler.js +518 -0
- package/dist/ok-select-card.js +231 -0
- package/dist/ok-signature.js +267 -0
- package/dist/ok-skeleton.js +345 -0
- package/dist/ok-sparkline.js +150 -0
- package/dist/ok-split-button.js +251 -0
- package/dist/ok-splitter.js +289 -0
- package/dist/ok-stat.js +77 -0
- package/dist/ok-status-dot.js +163 -0
- package/dist/ok-status-pill.js +123 -0
- package/dist/ok-stepper.js +299 -0
- package/dist/ok-store.js +83 -0
- package/dist/ok-tag-input.js +358 -0
- package/dist/ok-testimonial.js +136 -0
- package/dist/ok-time-picker.js +472 -0
- package/dist/ok-timeline.js +251 -0
- package/dist/ok-tree.js +266 -0
- package/dist/ok-video.js +362 -0
- package/dist/ok-widget-board.js +265 -0
- package/dist/ok-wizard.js +153 -0
- package/dist/outfitkit.js +96 -0
- package/dist/shared/anchor.js +14 -0
- package/dist/store/controller.d.ts +17 -0
- package/dist/store/idb.d.ts +16 -0
- package/dist/store/store.d.ts +39 -0
- package/dist/store-controller.js +31 -0
- package/dist/store.js +182 -0
- package/dist/theme.example.css +70 -0
- package/package.json +147 -0
package/dist/ok-chat.js
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { LitElement, css, html } from "lit";
|
|
2
|
+
import { property, query } from "lit/decorators.js";
|
|
3
|
+
import { define } from "./define.js";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
6
|
+
var result = void 0;
|
|
7
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
if (decorator = decorators[i])
|
|
9
|
+
result = decorator(target, key, result) || result;
|
|
10
|
+
if (result) __defProp(target, key, result);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
const DEFAULT_LABELS = {
|
|
14
|
+
composerPlaceholder: "Type a message…",
|
|
15
|
+
send: "Send"
|
|
16
|
+
};
|
|
17
|
+
class OkChat extends LitElement {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.messages = [];
|
|
21
|
+
this.title = "";
|
|
22
|
+
this.placeholder = "";
|
|
23
|
+
this.readonly = false;
|
|
24
|
+
this.labels = {};
|
|
25
|
+
}
|
|
26
|
+
static {
|
|
27
|
+
this.styles = css`
|
|
28
|
+
:host {
|
|
29
|
+
/* Vars overridable (estilo Ionic), default = cadena --ok-* → --ion-* → hex */
|
|
30
|
+
--color: var(--ok-text, var(--ion-text-color, #1c1b17));
|
|
31
|
+
--color-muted: var(--ok-text-muted, rgba(var(--ion-text-color-rgb, 28, 27, 23), 0.55));
|
|
32
|
+
--surface: var(--ok-surface, var(--ion-color-step-50, #f5f5f4));
|
|
33
|
+
--surface-2: var(--ok-surface-2, var(--ion-background-color, #ffffff));
|
|
34
|
+
--border-soft: var(--ok-border-soft, rgba(var(--ion-text-color-rgb, 28, 27, 23), 0.12));
|
|
35
|
+
--primary-color: var(--ok-primary, var(--ion-color-primary, #3880ff));
|
|
36
|
+
--primary-rgb: var(--ok-primary-rgb, var(--ion-color-primary-rgb, 56, 128, 255));
|
|
37
|
+
--primary-contrast: var(--ok-primary-contrast, var(--ion-color-primary-contrast, #ffffff));
|
|
38
|
+
--bubble-self: rgba(var(--primary-rgb), 0.14);
|
|
39
|
+
--border-radius: var(--ok-radius, 14px);
|
|
40
|
+
--font: var(--ok-font, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
|
|
41
|
+
|
|
42
|
+
/* Rellena el contenedor: columna flex de alto/ancho completo. */
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
height: 100%;
|
|
46
|
+
width: 100%;
|
|
47
|
+
min-height: 0;
|
|
48
|
+
color: var(--color);
|
|
49
|
+
font-family: var(--font);
|
|
50
|
+
font-size: 0.95rem;
|
|
51
|
+
background: var(--surface-2);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* Cabecera opcional. */
|
|
55
|
+
.header {
|
|
56
|
+
flex: 0 0 auto;
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
padding: 0.7rem 1rem;
|
|
60
|
+
font-weight: 600;
|
|
61
|
+
border-bottom: 1px solid var(--border-soft);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* Lista scrollable de burbujas. */
|
|
65
|
+
.log {
|
|
66
|
+
flex: 1 1 auto;
|
|
67
|
+
min-height: 0;
|
|
68
|
+
overflow-y: auto;
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-direction: column;
|
|
71
|
+
gap: 0.15rem;
|
|
72
|
+
padding: 0.85rem 1rem;
|
|
73
|
+
box-sizing: border-box;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* Fila de un mensaje (avatar + burbuja). */
|
|
77
|
+
.msg {
|
|
78
|
+
display: flex;
|
|
79
|
+
align-items: flex-end;
|
|
80
|
+
gap: 0.5rem;
|
|
81
|
+
max-width: 100%;
|
|
82
|
+
}
|
|
83
|
+
.msg.self {
|
|
84
|
+
flex-direction: row-reverse;
|
|
85
|
+
}
|
|
86
|
+
/* Separación extra entre grupos (cambio de lado/autor). */
|
|
87
|
+
.msg.group-start {
|
|
88
|
+
margin-top: 0.6rem;
|
|
89
|
+
}
|
|
90
|
+
.msg.group-start:first-child {
|
|
91
|
+
margin-top: 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Avatar (imagen o iniciales) — solo en mensajes ajenos. */
|
|
95
|
+
.avatar {
|
|
96
|
+
flex: 0 0 auto;
|
|
97
|
+
width: 30px;
|
|
98
|
+
height: 30px;
|
|
99
|
+
border-radius: 50%;
|
|
100
|
+
overflow: hidden;
|
|
101
|
+
display: inline-flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: center;
|
|
104
|
+
font-size: 0.72rem;
|
|
105
|
+
font-weight: 600;
|
|
106
|
+
background: var(--surface);
|
|
107
|
+
color: var(--color-muted);
|
|
108
|
+
border: 1px solid var(--border-soft);
|
|
109
|
+
}
|
|
110
|
+
.avatar img {
|
|
111
|
+
width: 100%;
|
|
112
|
+
height: 100%;
|
|
113
|
+
object-fit: cover;
|
|
114
|
+
}
|
|
115
|
+
/* Hueco del avatar cuando no toca mostrarlo (mantiene alineación del grupo). */
|
|
116
|
+
.avatar.spacer {
|
|
117
|
+
visibility: hidden;
|
|
118
|
+
border: 0;
|
|
119
|
+
background: none;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* Burbuja. */
|
|
123
|
+
.bubble {
|
|
124
|
+
max-width: min(78%, 560px);
|
|
125
|
+
box-sizing: border-box;
|
|
126
|
+
padding: 0.5rem 0.7rem;
|
|
127
|
+
border-radius: var(--border-radius);
|
|
128
|
+
background: var(--surface);
|
|
129
|
+
border: 1px solid var(--border-soft);
|
|
130
|
+
word-wrap: break-word;
|
|
131
|
+
overflow-wrap: anywhere;
|
|
132
|
+
}
|
|
133
|
+
.msg.self .bubble {
|
|
134
|
+
background: var(--bubble-self);
|
|
135
|
+
border-color: transparent;
|
|
136
|
+
}
|
|
137
|
+
/* Esquinas: "pico" hacia su lado en el primer mensaje del grupo. */
|
|
138
|
+
.msg.group-start:not(.self) .bubble {
|
|
139
|
+
border-top-left-radius: 4px;
|
|
140
|
+
}
|
|
141
|
+
.msg.group-start.self .bubble {
|
|
142
|
+
border-top-right-radius: 4px;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.author {
|
|
146
|
+
display: block;
|
|
147
|
+
font-size: 0.72rem;
|
|
148
|
+
font-weight: 600;
|
|
149
|
+
color: var(--primary-color);
|
|
150
|
+
margin-bottom: 0.15rem;
|
|
151
|
+
}
|
|
152
|
+
.text {
|
|
153
|
+
white-space: pre-wrap;
|
|
154
|
+
line-height: 1.35;
|
|
155
|
+
}
|
|
156
|
+
.time {
|
|
157
|
+
display: block;
|
|
158
|
+
margin-top: 0.2rem;
|
|
159
|
+
font-size: 0.66rem;
|
|
160
|
+
color: var(--color-muted);
|
|
161
|
+
text-align: right;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* Compositor abajo. */
|
|
165
|
+
.composer {
|
|
166
|
+
flex: 0 0 auto;
|
|
167
|
+
display: flex;
|
|
168
|
+
align-items: flex-end;
|
|
169
|
+
gap: 0.4rem;
|
|
170
|
+
padding: 0.55rem 0.7rem;
|
|
171
|
+
border-top: 1px solid var(--border-soft);
|
|
172
|
+
background: var(--surface-2);
|
|
173
|
+
}
|
|
174
|
+
.composer ion-textarea {
|
|
175
|
+
flex: 1 1 auto;
|
|
176
|
+
--background: var(--surface);
|
|
177
|
+
--border-radius: var(--border-radius);
|
|
178
|
+
--padding-start: 0.7rem;
|
|
179
|
+
--padding-end: 0.7rem;
|
|
180
|
+
--padding-top: 0.4rem;
|
|
181
|
+
--padding-bottom: 0.4rem;
|
|
182
|
+
}
|
|
183
|
+
.composer ion-button {
|
|
184
|
+
flex: 0 0 auto;
|
|
185
|
+
margin: 0;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@media (max-width: 480px) {
|
|
189
|
+
.bubble {
|
|
190
|
+
max-width: 84%;
|
|
191
|
+
}
|
|
192
|
+
.log {
|
|
193
|
+
padding: 0.7rem 0.7rem;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
/** Textos efectivos (defaults inglés + overrides). */
|
|
199
|
+
get t() {
|
|
200
|
+
return { ...DEFAULT_LABELS, ...this.labels };
|
|
201
|
+
}
|
|
202
|
+
/** Placeholder efectivo: prop explícita o el de labels. */
|
|
203
|
+
get effectivePlaceholder() {
|
|
204
|
+
return this.placeholder || this.t.composerPlaceholder;
|
|
205
|
+
}
|
|
206
|
+
// ¿El mensaje empieza un nuevo grupo? (cambia el lado o el autor respecto al anterior).
|
|
207
|
+
isGroupStart(index) {
|
|
208
|
+
if (index === 0) return true;
|
|
209
|
+
const prev = this.messages[index - 1];
|
|
210
|
+
const cur = this.messages[index];
|
|
211
|
+
return !!prev.self !== !!cur.self || prev.author !== cur.author;
|
|
212
|
+
}
|
|
213
|
+
// ¿El mensaje termina un grupo? (el siguiente cambia de lado/autor o no hay siguiente).
|
|
214
|
+
isGroupEnd(index) {
|
|
215
|
+
if (index === this.messages.length - 1) return true;
|
|
216
|
+
const next = this.messages[index + 1];
|
|
217
|
+
const cur = this.messages[index];
|
|
218
|
+
return !!next.self !== !!cur.self || next.author !== cur.author;
|
|
219
|
+
}
|
|
220
|
+
// Avatar de un mensaje ajeno: imagen si parece URL, iniciales en caso contrario.
|
|
221
|
+
renderAvatar(msg, show) {
|
|
222
|
+
if (msg.self) return "";
|
|
223
|
+
if (!show) return html`<span class="avatar spacer"></span>`;
|
|
224
|
+
const av = msg.avatar;
|
|
225
|
+
const isUrl = !!av && /^(https?:|data:|\/|\.)/.test(av);
|
|
226
|
+
return html`<span class="avatar">
|
|
227
|
+
${isUrl ? html`<img src=${av} alt="" />` : html`<span>${(av || msg.author || "?").slice(0, 2).toUpperCase()}</span>`}
|
|
228
|
+
</span>`;
|
|
229
|
+
}
|
|
230
|
+
// Render de un mensaje (fila avatar + burbuja).
|
|
231
|
+
renderMessage(msg, index) {
|
|
232
|
+
const start = this.isGroupStart(index);
|
|
233
|
+
const end = this.isGroupEnd(index);
|
|
234
|
+
const cls = ["msg", msg.self ? "self" : "", start ? "group-start" : ""].filter(Boolean).join(" ");
|
|
235
|
+
const showAuthor = start && !msg.self && !!msg.author;
|
|
236
|
+
return html`<div class=${cls}>
|
|
237
|
+
${this.renderAvatar(msg, end)}
|
|
238
|
+
<div class="bubble">
|
|
239
|
+
${showAuthor ? html`<span class="author">${msg.author}</span>` : ""}
|
|
240
|
+
<span class="text">${msg.text}</span>
|
|
241
|
+
${msg.time ? html`<span class="time">${msg.time}</span>` : ""}
|
|
242
|
+
</div>
|
|
243
|
+
</div>`;
|
|
244
|
+
}
|
|
245
|
+
// Envía el contenido del compositor si no está vacío y limpia el campo.
|
|
246
|
+
send() {
|
|
247
|
+
const el = this.textareaEl;
|
|
248
|
+
const text = (el?.value ?? "").trim();
|
|
249
|
+
if (!text) return;
|
|
250
|
+
this.dispatchEvent(
|
|
251
|
+
new CustomEvent("ok-send", {
|
|
252
|
+
detail: { text },
|
|
253
|
+
bubbles: true,
|
|
254
|
+
composed: true
|
|
255
|
+
})
|
|
256
|
+
);
|
|
257
|
+
if (el) el.value = "";
|
|
258
|
+
}
|
|
259
|
+
// Enter envía; Shift+Enter inserta salto de línea (comportamiento por defecto del textarea).
|
|
260
|
+
onKeydown(e) {
|
|
261
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
262
|
+
e.preventDefault();
|
|
263
|
+
this.send();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Tras cada render, si han cambiado los mensajes hace auto-scroll al fondo.
|
|
267
|
+
updated(changed) {
|
|
268
|
+
if (changed.has("messages") && this.logEl) {
|
|
269
|
+
this.logEl.scrollTop = this.logEl.scrollHeight;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
render() {
|
|
273
|
+
return html`
|
|
274
|
+
${this.title ? html`<div class="header">${this.title}</div>` : ""}
|
|
275
|
+
<div class="log" role="log" aria-live="polite">
|
|
276
|
+
${this.messages.map((msg, i) => this.renderMessage(msg, i))}
|
|
277
|
+
</div>
|
|
278
|
+
${this.readonly ? "" : html`<div class="composer">
|
|
279
|
+
<ion-textarea
|
|
280
|
+
auto-grow
|
|
281
|
+
rows="1"
|
|
282
|
+
placeholder=${this.effectivePlaceholder}
|
|
283
|
+
@keydown=${(e) => this.onKeydown(e)}
|
|
284
|
+
></ion-textarea>
|
|
285
|
+
<ion-button
|
|
286
|
+
fill="solid"
|
|
287
|
+
aria-label=${this.t.send}
|
|
288
|
+
@click=${() => this.send()}
|
|
289
|
+
>
|
|
290
|
+
<ion-icon slot="icon-only" name="send"></ion-icon>
|
|
291
|
+
</ion-button>
|
|
292
|
+
</div>`}
|
|
293
|
+
`;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
__decorateClass([
|
|
297
|
+
property({ attribute: false })
|
|
298
|
+
], OkChat.prototype, "messages");
|
|
299
|
+
__decorateClass([
|
|
300
|
+
property()
|
|
301
|
+
], OkChat.prototype, "title");
|
|
302
|
+
__decorateClass([
|
|
303
|
+
property()
|
|
304
|
+
], OkChat.prototype, "placeholder");
|
|
305
|
+
__decorateClass([
|
|
306
|
+
property({ type: Boolean })
|
|
307
|
+
], OkChat.prototype, "readonly");
|
|
308
|
+
__decorateClass([
|
|
309
|
+
property({ attribute: false })
|
|
310
|
+
], OkChat.prototype, "labels");
|
|
311
|
+
__decorateClass([
|
|
312
|
+
query(".log")
|
|
313
|
+
], OkChat.prototype, "logEl");
|
|
314
|
+
__decorateClass([
|
|
315
|
+
query("ion-textarea")
|
|
316
|
+
], OkChat.prototype, "textareaEl");
|
|
317
|
+
define("ok-chat", OkChat);
|
|
318
|
+
export {
|
|
319
|
+
OkChat
|
|
320
|
+
};
|