anentrypoint-design 0.0.27 → 0.0.29
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/dist/247420.app.js +3 -3
- package/dist/247420.css +294 -2
- package/dist/247420.js +37 -131
- package/package.json +3 -2
- package/src/bootstrap.js +38 -0
- package/src/components/chat.js +199 -0
- package/src/components/content.js +171 -0
- package/src/components/shell.js +113 -0
- package/src/components.js +20 -392
- package/src/debug.js +34 -0
- package/src/highlight.js +60 -0
- package/src/index.js +22 -5
- package/src/markdown.js +61 -0
- package/src/web-components/ds-chat.js +75 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as webjsx from '../../vendor/webjsx/index.js';
|
|
2
|
+
import { Chat, ChatComposer } from '../components/chat.js';
|
|
3
|
+
import { register } from '../debug.js';
|
|
4
|
+
|
|
5
|
+
let _stats = { mounts: 0, sends: 0 };
|
|
6
|
+
|
|
7
|
+
class DsChat extends HTMLElement {
|
|
8
|
+
static get observedAttributes() { return ['title', 'sub', 'placeholder']; }
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this._messages = [];
|
|
13
|
+
this._draft = '';
|
|
14
|
+
this._title = 'chat';
|
|
15
|
+
this._sub = '';
|
|
16
|
+
this._placeholder = 'message…';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
set messages(v) { this._messages = Array.isArray(v) ? v : []; this._render(); }
|
|
20
|
+
get messages() { return this._messages; }
|
|
21
|
+
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
if (this.hasAttribute('messages')) {
|
|
24
|
+
try { this._messages = JSON.parse(this.getAttribute('messages')); } catch {}
|
|
25
|
+
}
|
|
26
|
+
this._title = this.getAttribute('title') || this._title;
|
|
27
|
+
this._sub = this.getAttribute('sub') || '';
|
|
28
|
+
this._placeholder = this.getAttribute('placeholder') || this._placeholder;
|
|
29
|
+
_stats.mounts += 1;
|
|
30
|
+
this._render();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
attributeChangedCallback(name, _old, val) {
|
|
34
|
+
if (name === 'title') this._title = val || 'chat';
|
|
35
|
+
if (name === 'sub') this._sub = val || '';
|
|
36
|
+
if (name === 'placeholder') this._placeholder = val || 'message…';
|
|
37
|
+
this._render();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pushMessage(msg) {
|
|
41
|
+
this._messages = [...this._messages, msg];
|
|
42
|
+
this._render();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_render() {
|
|
46
|
+
const onSend = (text) => {
|
|
47
|
+
_stats.sends += 1;
|
|
48
|
+
this.dispatchEvent(new CustomEvent('send', { detail: { text }, bubbles: true, composed: true }));
|
|
49
|
+
};
|
|
50
|
+
const onInput = (v) => { this._draft = v; this._render(); };
|
|
51
|
+
const view = Chat({
|
|
52
|
+
title: this._title,
|
|
53
|
+
sub: this._sub,
|
|
54
|
+
messages: this._messages,
|
|
55
|
+
composer: ChatComposer({
|
|
56
|
+
value: this._draft,
|
|
57
|
+
placeholder: this._placeholder,
|
|
58
|
+
onInput,
|
|
59
|
+
onSend
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
webjsx.applyDiff(this, view);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let _registered = false;
|
|
67
|
+
export function registerChatElement() {
|
|
68
|
+
if (_registered) return;
|
|
69
|
+
if (!customElements.get('ds-chat')) customElements.define('ds-chat', DsChat);
|
|
70
|
+
_registered = true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
register('ds-chat', () => ({ registered: _registered, ..._stats, instances: document.querySelectorAll('ds-chat').length }));
|
|
74
|
+
|
|
75
|
+
export { DsChat };
|