kempo-ui 0.4.4 → 0.4.6
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/components/Chat.js +201 -0
- package/dist/components/CodeEditor.js +21 -2
- package/dist/components/Dropdown.js +1 -1
- package/dist/components/HtmlEditor.js +42 -3
- package/dist/components/MarkdownEditor.js +173 -0
- package/dist/components/Resize.js +12 -2
- package/dist/components/TextToSpeech.js +4 -4
- package/dist/components/VoiceSelector.js +49 -0
- package/dist/components/markdownEditorControls/Bold.js +11 -0
- package/dist/components/markdownEditorControls/BulletList.js +11 -0
- package/dist/components/markdownEditorControls/Code.js +11 -0
- package/dist/components/markdownEditorControls/FormatBlock.js +30 -0
- package/dist/components/markdownEditorControls/Heading.js +11 -0
- package/dist/components/markdownEditorControls/Image.js +93 -0
- package/dist/components/markdownEditorControls/Italic.js +11 -0
- package/dist/components/markdownEditorControls/Link.js +11 -0
- package/dist/components/markdownEditorControls/MarkdownEditorControl.js +39 -0
- package/dist/components/markdownEditorControls/Menu.js +30 -0
- package/dist/components/markdownEditorControls/NumberedList.js +11 -0
- package/dist/components/markdownEditorControls/Quote.js +11 -0
- package/dist/components/markdownEditorControls/SpeechToText.js +16 -0
- package/dist/components/markdownEditorControls/Strikethrough.js +11 -0
- package/dist/components/markdownEditorControls/Table.js +80 -0
- package/dist/utils/marked.esm.js +1 -0
- package/dist/utils/renderMarkdown.js +1 -0
- package/dist/utils/sanitizeHtml.js +1 -0
- package/dist/utils/voice.js +1 -0
- package/docs/components/accordion.html +19 -0
- package/docs/components/aside.html +19 -0
- package/docs/components/calendar.html +19 -0
- package/docs/components/card.html +19 -0
- package/docs/components/chat.html +715 -0
- package/docs/components/code-editor.html +55 -0
- package/docs/components/color-picker.html +19 -0
- package/docs/components/combobox.html +19 -0
- package/docs/components/content-slider.html +19 -0
- package/docs/components/context.html +19 -0
- package/docs/components/dialog.html +19 -0
- package/docs/components/dropdown.html +19 -0
- package/docs/components/filter-list.html +19 -0
- package/docs/components/focus-capture.html +19 -0
- package/docs/components/html-editor.html +60 -0
- package/docs/components/hybrid-component.html +19 -0
- package/docs/components/icon.html +19 -0
- package/docs/components/import.html +19 -0
- package/docs/components/light-component.html +19 -0
- package/docs/components/markdown-editor.html +924 -0
- package/docs/components/nav-spacer.html +19 -0
- package/docs/components/nav.html +19 -0
- package/docs/components/photo-viewer.html +19 -0
- package/docs/components/progress.html +19 -0
- package/docs/components/resize.html +22 -0
- package/docs/components/rich-textarea.html +650 -0
- package/docs/components/shadow-component.html +19 -0
- package/docs/components/show-more.html +19 -0
- package/docs/components/slider.html +19 -0
- package/docs/components/sortable.html +19 -0
- package/docs/components/speech-to-text.html +19 -0
- package/docs/components/spinner.html +19 -0
- package/docs/components/split.html +19 -0
- package/docs/components/table.html +19 -0
- package/docs/components/tableControls.html +19 -0
- package/docs/components/tableCustomFields.html +19 -0
- package/docs/components/tableFetchRecords.html +19 -0
- package/docs/components/tableFieldSortHide.html +19 -0
- package/docs/components/tablePagination.html +19 -0
- package/docs/components/tablePlaceholder.html +19 -0
- package/docs/components/tableRecordEditing.html +19 -0
- package/docs/components/tableRecordFiltering.html +19 -0
- package/docs/components/tableRecordHiding.html +19 -0
- package/docs/components/tableRecordSearching.html +19 -0
- package/docs/components/tableRecordSelection.html +19 -0
- package/docs/components/tableRowControls.html +19 -0
- package/docs/components/tableServerSync.html +19 -0
- package/docs/components/tableSorting.html +19 -0
- package/docs/components/tabs.html +19 -0
- package/docs/components/tags.html +19 -0
- package/docs/components/text-to-speech.html +63 -1
- package/docs/components/theme-select.html +19 -0
- package/docs/components/theme-switcher.html +19 -0
- package/docs/components/time.html +19 -0
- package/docs/components/timestamp.html +19 -0
- package/docs/components/toast.html +19 -0
- package/docs/components/toggle.html +19 -0
- package/docs/components/tree.html +19 -0
- package/docs/components/voice-selector.html +610 -0
- package/docs/icons/done_all.svg +1 -0
- package/docs/icons/format_quote.svg +1 -0
- package/docs/icons/format_strikethrough.svg +1 -0
- package/docs/icons/send.svg +1 -0
- package/docs/icons/text_fields.svg +1 -0
- package/docs/index.html +49 -0
- package/docs/src/components/Chat.js +201 -0
- package/docs/src/components/CodeEditor.js +21 -2
- package/docs/src/components/Dropdown.js +1 -1
- package/docs/src/components/HtmlEditor.js +42 -3
- package/docs/src/components/MarkdownEditor.js +173 -0
- package/docs/src/components/Resize.js +12 -2
- package/docs/src/components/TextToSpeech.js +4 -4
- package/docs/src/components/VoiceSelector.js +49 -0
- package/docs/src/components/markdownEditorControls/Bold.js +11 -0
- package/docs/src/components/markdownEditorControls/BulletList.js +11 -0
- package/docs/src/components/markdownEditorControls/Code.js +11 -0
- package/docs/src/components/markdownEditorControls/FormatBlock.js +30 -0
- package/docs/src/components/markdownEditorControls/Heading.js +11 -0
- package/docs/src/components/markdownEditorControls/Image.js +93 -0
- package/docs/src/components/markdownEditorControls/Italic.js +11 -0
- package/docs/src/components/markdownEditorControls/Link.js +11 -0
- package/docs/src/components/markdownEditorControls/MarkdownEditorControl.js +39 -0
- package/docs/src/components/markdownEditorControls/Menu.js +30 -0
- package/docs/src/components/markdownEditorControls/NumberedList.js +11 -0
- package/docs/src/components/markdownEditorControls/Quote.js +11 -0
- package/docs/src/components/markdownEditorControls/SpeechToText.js +16 -0
- package/docs/src/components/markdownEditorControls/Strikethrough.js +11 -0
- package/docs/src/components/markdownEditorControls/Table.js +80 -0
- package/docs/src/utils/marked.esm.js +1 -0
- package/docs/src/utils/renderMarkdown.js +1 -0
- package/docs/src/utils/sanitizeHtml.js +1 -0
- package/docs/src/utils/voice.js +1 -0
- package/docs/utils/context.html +19 -0
- package/docs/utils/cookie.html +19 -0
- package/docs/utils/debounce.html +19 -0
- package/docs/utils/drag.html +19 -0
- package/docs/utils/elevation.html +23 -10
- package/docs/utils/formatTimestamp.html +19 -0
- package/docs/utils/object.html +19 -0
- package/docs/utils/propConverters.html +19 -0
- package/docs/utils/sanitizeHtml.html +555 -0
- package/docs/utils/string.html +19 -0
- package/docs/utils/theme.html +19 -0
- package/docs/utils/toTitleCase.html +19 -0
- package/docs/utils/type.html +19 -0
- package/docs/utils/voice.html +548 -0
- package/docs/utils/wait.html +19 -0
- package/docs-src/components/chat.page.html +230 -0
- package/docs-src/components/code-editor.page.html +36 -0
- package/docs-src/components/html-editor.page.html +41 -0
- package/docs-src/components/markdown-editor.page.html +439 -0
- package/docs-src/components/resize.page.html +3 -0
- package/docs-src/components/text-to-speech.page.html +44 -1
- package/docs-src/components/voice-selector.page.html +125 -0
- package/docs-src/index.page.html +30 -0
- package/docs-src/nav.fragment.html +19 -0
- package/docs-src/utils/elevation.page.html +4 -10
- package/docs-src/utils/sanitizeHtml.page.html +73 -0
- package/docs-src/utils/voice.page.html +66 -0
- package/icons/done_all.svg +1 -0
- package/icons/format_quote.svg +1 -0
- package/icons/format_strikethrough.svg +1 -0
- package/icons/send.svg +1 -0
- package/icons/text_fields.svg +1 -0
- package/llms.txt +7 -2
- package/package.json +3 -2
- package/src/components/Chat.js +435 -0
- package/src/components/CodeEditor.js +58 -2
- package/src/components/Dropdown.js +1 -1
- package/src/components/HtmlEditor.js +84 -4
- package/src/components/MarkdownEditor.js +654 -0
- package/src/components/Resize.js +17 -1
- package/src/components/TextToSpeech.js +13 -2
- package/src/components/VoiceSelector.js +271 -0
- package/src/components/markdownEditorControls/Bold.js +30 -0
- package/src/components/markdownEditorControls/BulletList.js +30 -0
- package/src/components/markdownEditorControls/Code.js +39 -0
- package/src/components/markdownEditorControls/FormatBlock.js +102 -0
- package/src/components/markdownEditorControls/Heading.js +45 -0
- package/src/components/markdownEditorControls/Image.js +250 -0
- package/src/components/markdownEditorControls/Italic.js +30 -0
- package/src/components/markdownEditorControls/Link.js +74 -0
- package/src/components/markdownEditorControls/MarkdownEditorControl.js +158 -0
- package/src/components/markdownEditorControls/Menu.js +86 -0
- package/src/components/markdownEditorControls/NumberedList.js +69 -0
- package/src/components/markdownEditorControls/Quote.js +30 -0
- package/src/components/markdownEditorControls/SpeechToText.js +65 -0
- package/src/components/markdownEditorControls/Strikethrough.js +35 -0
- package/src/components/markdownEditorControls/Table.js +164 -0
- package/src/utils/marked.esm.js +77 -0
- package/src/utils/renderMarkdown.js +29 -0
- package/src/utils/sanitizeHtml.js +137 -0
- package/src/utils/voice.js +103 -0
- package/tests/components/Chat.browser-test.js +540 -0
- package/tests/components/TextToSpeech.browser-test.js +150 -1
- package/tests/components/VoiceSelector.browser-test.js +374 -0
- package/tests/utils/sanitizeHtml.browser-test.js +179 -0
- package/tests/utils/voice.browser-test.js +128 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
<page pageName="Chat" title="Chat - Components - Kempo Docs - A Web Components Solution">
|
|
2
|
+
<content>
|
|
3
|
+
<k-accordion persistent-id="toc" class="b r mb">
|
|
4
|
+
<k-accordion-header for-panel="toc-panel">Table of Contents</k-accordion-header>
|
|
5
|
+
<k-accordion-panel name="toc-panel">
|
|
6
|
+
<div class="m pl">
|
|
7
|
+
<h6>Examples</h6>
|
|
8
|
+
<a href="#basicUsage">Basic Usage</a><br />
|
|
9
|
+
<a href="#enterBehavior">Enter Behavior</a><br />
|
|
10
|
+
<a href="#showStatus">Message Status</a><br />
|
|
11
|
+
<a href="#disabled">Disabled</a><br />
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
<h6 class="mt"><a href="#jsRef" class="no-link">JavaScript Reference</a></h6>
|
|
15
|
+
<a href="#constructor">Constructor</a><br />
|
|
16
|
+
<a href="#requirements">Requirements</a><br />
|
|
17
|
+
<a href="#properties">Properties</a><br />
|
|
18
|
+
<a href="#methods">Methods</a><br />
|
|
19
|
+
<a href="#cssVariables">CSS Variables</a><br />
|
|
20
|
+
<a href="#events">Events</a><br />
|
|
21
|
+
<a href="#security">Security Notes</a><br />
|
|
22
|
+
</div>
|
|
23
|
+
</k-accordion-panel>
|
|
24
|
+
</k-accordion>
|
|
25
|
+
|
|
26
|
+
<p>A chat-room widget: scrollable history of messages above, a markdown input + Send button below. The input is a <a href="./markdown-editor.html"><code><k-markdown-editor></code></a> — users type markdown (with a Preview tab to see the rendered output before sending), and the message is rendered to HTML via the vendored <a href="https://marked.js.org" target="_blank">marked</a> parser (CommonMark + GFM, including tables and task lists). The rendered HTML runs through <a href="../utils/sanitizeHtml.html"><code>sanitizeHtml</code></a> on its way into the message bubble so any inline HTML the user types is filtered against the allow-list — <code><script></code>, <code><iframe></code>, etc. are always stripped.</p>
|
|
27
|
+
|
|
28
|
+
<h3 id="basicUsage"><a href="#basicUsage" class="no-link">Basic Usage</a></h3>
|
|
29
|
+
<p>The component fires a <code>send</code> event when the user submits. Listen for it and call <code>chat.addMessage(...)</code> for incoming replies. Outgoing messages are added automatically.</p>
|
|
30
|
+
<div class="row -mx">
|
|
31
|
+
<div class="col m-span-12 px">
|
|
32
|
+
<k-card label="HTML">
|
|
33
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-chat</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"basicChat"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-chat</span>></span><br><span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="language-javascript"><br> <span class="hljs-keyword">const</span> chat = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'basicChat'</span>);<br> chat.<span class="hljs-title function_">addEventListener</span>(<span class="hljs-string">'send'</span>, <span class="hljs-function">(<span class="hljs-params">e</span>) =></span> {<br> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Sent:'</span>, e.<span class="hljs-property">detail</span>.<span class="hljs-property">markdown</span>);<br> <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {<br> chat.<span class="hljs-title function_">addMessage</span>({<br> <span class="hljs-attr">type</span>: <span class="hljs-string">'incoming'</span>,<br> <span class="hljs-attr">html</span>: <span class="hljs-string">'Got it!'</span>,<br> <span class="hljs-attr">sender</span>: <span class="hljs-string">'Bot'</span><br> });<br> }, <span class="hljs-number">500</span>);<br> });<br></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
34
|
+
</k-card>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="col m-span-12 px">
|
|
37
|
+
<k-card label="Output">
|
|
38
|
+
<k-chat id="basicChat"></k-chat>
|
|
39
|
+
<script type="module">
|
|
40
|
+
await customElements.whenDefined('k-chat');
|
|
41
|
+
const chat = document.getElementById('basicChat');
|
|
42
|
+
chat.addMessage({ type: 'incoming', html: 'Welcome — say hi!', sender: 'Bot' });
|
|
43
|
+
chat.addEventListener('send', (e) => {
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
chat.addMessage({
|
|
46
|
+
type: 'incoming',
|
|
47
|
+
html: '<i>Echo:</i> ' + e.detail.html,
|
|
48
|
+
sender: 'Bot'
|
|
49
|
+
});
|
|
50
|
+
}, 500);
|
|
51
|
+
});
|
|
52
|
+
</script>
|
|
53
|
+
</k-card>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
<h3 id="enterBehavior"><a href="#enterBehavior" class="no-link">Enter Behavior</a></h3>
|
|
58
|
+
<p>By default the chat matches Slack/Discord/Messages: <strong>Enter sends</strong>, Shift+Enter inserts a newline. Add the <code>enter-newline</code> attribute to flip it — Enter inserts a newline, Shift+Enter sends.</p>
|
|
59
|
+
<div class="row -mx">
|
|
60
|
+
<div class="col m-span-12 px">
|
|
61
|
+
<k-card label="HTML">
|
|
62
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-chat</span> <span class="hljs-attr">enter-newline</span>></span><span class="hljs-tag"></<span class="hljs-name">k-chat</span>></span></code></pre>
|
|
63
|
+
</k-card>
|
|
64
|
+
</div>
|
|
65
|
+
<div class="col m-span-12 px">
|
|
66
|
+
<k-card label="Output">
|
|
67
|
+
<k-chat id="newlineChat" enter-newline></k-chat>
|
|
68
|
+
<script type="module">
|
|
69
|
+
await customElements.whenDefined('k-chat');
|
|
70
|
+
const chat = document.getElementById('newlineChat');
|
|
71
|
+
chat.addMessage({ type: 'incoming', html: 'Enter inserts a newline. Shift+Enter sends.', sender: 'Bot' });
|
|
72
|
+
chat.addEventListener('send', () => {
|
|
73
|
+
setTimeout(() => chat.addMessage({ type: 'incoming', html: '👍', sender: 'Bot' }), 400);
|
|
74
|
+
});
|
|
75
|
+
</script>
|
|
76
|
+
</k-card>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<h3 id="showStatus"><a href="#showStatus" class="no-link">Message Status</a></h3>
|
|
81
|
+
<p>Add <code>show-status</code> and outgoing messages get an iMessage-style status indicator below the bubble. The four statuses are <code>sending</code>, <code>delivered</code>, <code>read</code>, and <code>failed</code>. When the user submits, the message is added with <code>status: 'sending'</code>; advance it via <code>chat.updateMessage(id, { status })</code> as the backend confirms.</p>
|
|
82
|
+
<p>The attribute takes one of two display modes:</p>
|
|
83
|
+
<ul>
|
|
84
|
+
<li><code>show-status</code> or <code>show-status="text"</code> — small grey text labels (<em>Sending…</em>, <em>Delivered</em>, <em>Read</em>, <em>Not Delivered</em>). Default mode.</li>
|
|
85
|
+
<li><code>show-status="icons"</code> — spinner / check / double-check / error icons only.</li>
|
|
86
|
+
</ul>
|
|
87
|
+
<p>Following iMessage convention, the indicator only renders on the <strong>most recent outgoing message</strong> — older delivered/read messages stay clean. <code>sending</code> and <code>failed</code> always show regardless of position so the user knows about in-flight or stuck messages immediately.</p>
|
|
88
|
+
<div class="row -mx">
|
|
89
|
+
<div class="col m-span-12 px">
|
|
90
|
+
<k-card label="HTML">
|
|
91
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-chat</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"ackChat"</span> <span class="hljs-attr">show-status</span>></span><span class="hljs-tag"></<span class="hljs-name">k-chat</span>></span><br><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="language-javascript"><br> <span class="hljs-keyword">await</span> customElements.<span class="hljs-title function_">whenDefined</span>(<span class="hljs-string">'k-chat'</span>);<br> <span class="hljs-keyword">const</span> chat = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'ackChat'</span>);<br> chat.<span class="hljs-title function_">addEventListener</span>(<span class="hljs-string">'send'</span>, <span class="hljs-title function_">async</span> (e) => {<br> <span class="hljs-comment">// Simulate a server round-trip</span><br> <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function"><span class="hljs-params">r</span> =></span> <span class="hljs-built_in">setTimeout</span>(r, <span class="hljs-number">800</span>));<br> chat.<span class="hljs-title function_">updateMessage</span>(e.<span class="hljs-property">detail</span>.<span class="hljs-property">id</span>, {<br> <span class="hljs-attr">status</span>: <span class="hljs-string">'delivered'</span><br> });<br> <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function"><span class="hljs-params">r</span> =></span> <span class="hljs-built_in">setTimeout</span>(r, <span class="hljs-number">1200</span>));<br> chat.<span class="hljs-title function_">updateMessage</span>(e.<span class="hljs-property">detail</span>.<span class="hljs-property">id</span>, {<br> <span class="hljs-attr">status</span>: <span class="hljs-string">'read'</span><br> });<br> });<br></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
92
|
+
</k-card>
|
|
93
|
+
</div>
|
|
94
|
+
<div class="col m-span-12 px">
|
|
95
|
+
<k-card label="Output">
|
|
96
|
+
<k-chat id="ackChat" show-status></k-chat>
|
|
97
|
+
<script type="module">
|
|
98
|
+
await customElements.whenDefined('k-chat');
|
|
99
|
+
const chat = document.getElementById('ackChat');
|
|
100
|
+
chat.addEventListener('send', async (e) => {
|
|
101
|
+
await new Promise(r => setTimeout(r, 800));
|
|
102
|
+
chat.updateMessage(e.detail.id, { status: 'delivered' });
|
|
103
|
+
await new Promise(r => setTimeout(r, 1200));
|
|
104
|
+
chat.updateMessage(e.detail.id, { status: 'read' });
|
|
105
|
+
});
|
|
106
|
+
</script>
|
|
107
|
+
</k-card>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
<h4>Icon Mode</h4>
|
|
112
|
+
<p>Pass <code>show-status="icons"</code> for compact icon-only badges (spinner / single check / double check / red error) instead of text labels — closer to WhatsApp / Telegram styling.</p>
|
|
113
|
+
<div class="row -mx">
|
|
114
|
+
<div class="col m-span-12 px">
|
|
115
|
+
<k-card label="HTML">
|
|
116
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-chat</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"iconChat"</span> <span class="hljs-attr">show-status</span>=<span class="hljs-string">"icons"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-chat</span>></span><br><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="language-javascript"><br> <span class="hljs-keyword">await</span> customElements.<span class="hljs-title function_">whenDefined</span>(<span class="hljs-string">'k-chat'</span>);<br> <span class="hljs-keyword">const</span> chat = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'iconChat'</span>);<br> chat.<span class="hljs-title function_">addEventListener</span>(<span class="hljs-string">'send'</span>, <span class="hljs-title function_">async</span> (e) => {<br> <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function"><span class="hljs-params">r</span> =></span> <span class="hljs-built_in">setTimeout</span>(r, <span class="hljs-number">800</span>));<br> chat.<span class="hljs-title function_">updateMessage</span>(e.<span class="hljs-property">detail</span>.<span class="hljs-property">id</span>, {<br> <span class="hljs-attr">status</span>: <span class="hljs-string">'delivered'</span><br> });<br> <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function"><span class="hljs-params">r</span> =></span> <span class="hljs-built_in">setTimeout</span>(r, <span class="hljs-number">1200</span>));<br> chat.<span class="hljs-title function_">updateMessage</span>(e.<span class="hljs-property">detail</span>.<span class="hljs-property">id</span>, {<br> <span class="hljs-attr">status</span>: <span class="hljs-string">'read'</span><br> });<br> });<br></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
117
|
+
</k-card>
|
|
118
|
+
</div>
|
|
119
|
+
<div class="col m-span-12 px">
|
|
120
|
+
<k-card label="Output">
|
|
121
|
+
<k-chat id="iconChat" show-status="icons"></k-chat>
|
|
122
|
+
<script type="module">
|
|
123
|
+
await customElements.whenDefined('k-chat');
|
|
124
|
+
const chat = document.getElementById('iconChat');
|
|
125
|
+
chat.addEventListener('send', async (e) => {
|
|
126
|
+
await new Promise(r => setTimeout(r, 800));
|
|
127
|
+
chat.updateMessage(e.detail.id, { status: 'delivered' });
|
|
128
|
+
await new Promise(r => setTimeout(r, 1200));
|
|
129
|
+
chat.updateMessage(e.detail.id, { status: 'read' });
|
|
130
|
+
});
|
|
131
|
+
</script>
|
|
132
|
+
</k-card>
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
<h3 id="disabled"><a href="#disabled" class="no-link">Disabled</a></h3>
|
|
137
|
+
<p>The <code>disabled</code> attribute prevents user interaction. Useful while waiting for connection or rate-limiting.</p>
|
|
138
|
+
<div class="row -mx">
|
|
139
|
+
<div class="col m-span-12 px">
|
|
140
|
+
<k-card label="HTML">
|
|
141
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-chat</span> <span class="hljs-attr">disabled</span>></span><span class="hljs-tag"></<span class="hljs-name">k-chat</span>></span></code></pre>
|
|
142
|
+
</k-card>
|
|
143
|
+
</div>
|
|
144
|
+
<div class="col m-span-12 px">
|
|
145
|
+
<k-card label="Output">
|
|
146
|
+
<k-chat disabled></k-chat>
|
|
147
|
+
</k-card>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
<h2 id="jsRef"><a href="#jsRef" class="no-link">JavaScript Reference</a></h2>
|
|
152
|
+
|
|
153
|
+
<h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
|
|
154
|
+
<h6>Extends <a href="./shadow-component.html">ShadowComponent</a></h6>
|
|
155
|
+
<h5><code>new Chat()</code></h5>
|
|
156
|
+
|
|
157
|
+
<h3 id="requirements"><a href="#requirements" class="no-link">Requirements</a></h3>
|
|
158
|
+
<ul>
|
|
159
|
+
<li><a href="./shadow-component.html">ShadowComponent</a></li>
|
|
160
|
+
<li><a href="./markdown-editor.html">MarkdownEditor</a> (used internally for the input)</li>
|
|
161
|
+
<li><a href="../utils/sanitizeHtml.html">sanitizeHtml</a> utility</li>
|
|
162
|
+
</ul>
|
|
163
|
+
|
|
164
|
+
<h3 id="properties"><a href="#properties" class="no-link">Properties</a></h3>
|
|
165
|
+
<h5><code>enterNewline<i>: Boolean</i></code></h5>
|
|
166
|
+
<p>Inverts the default Enter-key behavior. Default is <code>false</code> (Slack-style: Enter sends, Shift+Enter inserts a newline). When <code>true</code>: Enter inserts a newline and Shift+Enter sends. Syncs to <code>enter-newline</code> attribute.</p>
|
|
167
|
+
|
|
168
|
+
<h5><code>showStatus<i>: String</i></code></h5>
|
|
169
|
+
<p>Enables and configures the per-message status indicator. Possible values: <code>null</code>/empty (off, default), <code>"text"</code> (small grey labels — the default mode when the attribute is set without a value), or <code>"icons"</code> (spinner/check/double-check/error glyphs). The indicator only appears on the most recent outgoing message, except for <code>sending</code> and <code>failed</code> which always show. Outgoing messages submitted via the input start as <code>sending</code> — advance them via <code>updateMessage(id, { status })</code> as the backend confirms. Syncs to <code>show-status</code> attribute.</p>
|
|
170
|
+
|
|
171
|
+
<h5><code>placeholder<i>: String</i></code></h5>
|
|
172
|
+
<p>Placeholder text for the input. Default <code>"Type a message..."</code>. Syncs to <code>placeholder</code> attribute.</p>
|
|
173
|
+
|
|
174
|
+
<h5><code>disabled<i>: Boolean</i></code></h5>
|
|
175
|
+
<p>When <code>true</code>, the input and Send button are disabled. Syncs to <code>disabled</code> attribute.</p>
|
|
176
|
+
|
|
177
|
+
<h5><code>messages<i>: Array</i></code> (read-only state)</h5>
|
|
178
|
+
<p>The current array of messages. Each entry is <code>{ id, type, html, status, sender, timestamp }</code>. Don't mutate directly — use the public methods.</p>
|
|
179
|
+
|
|
180
|
+
<h3 id="methods"><a href="#methods" class="no-link">Methods</a></h3>
|
|
181
|
+
<h5><code>addMessage(msg)<i>: string</i></code></h5>
|
|
182
|
+
<p>Append a message and return its <code>id</code>. <code>msg</code> object accepts <code>{ id, type, html, status, sender, timestamp }</code>; missing fields are filled in (auto-generated id, type defaults to <code>"incoming"</code>, etc.). HTML is sanitized.</p>
|
|
183
|
+
|
|
184
|
+
<h5><code>updateMessage(id, updates)<i>: boolean</i></code></h5>
|
|
185
|
+
<p>Update an existing message's <code>html</code>, <code>status</code>, <code>sender</code>, or <code>timestamp</code>. Returns <code>true</code> if a message with that id was found.</p>
|
|
186
|
+
|
|
187
|
+
<h5><code>removeMessage(id)<i>: boolean</i></code></h5>
|
|
188
|
+
<p>Remove a message. Returns <code>true</code> if found.</p>
|
|
189
|
+
|
|
190
|
+
<h5><code>clear()<i>: void</i></code></h5>
|
|
191
|
+
<p>Remove every message.</p>
|
|
192
|
+
|
|
193
|
+
<h5><code>send()<i>: string | null</i></code></h5>
|
|
194
|
+
<p>Programmatically submit whatever is currently in the input. Returns the new outgoing message's <code>id</code>, or <code>null</code> if the input was empty.</p>
|
|
195
|
+
|
|
196
|
+
<h3 id="cssVariables"><a href="#cssVariables" class="no-link">CSS Variables</a></h3>
|
|
197
|
+
<table class="b">
|
|
198
|
+
<thead><tr><th>Variable</th><th>Default</th><th>Description</th></tr></thead>
|
|
199
|
+
<tbody>
|
|
200
|
+
<tr><td><code>--window_min_height</code></td><td><code>16rem</code></td><td>Minimum height of the message window (the chat won't collapse below this even when empty)</td></tr>
|
|
201
|
+
<tr><td><code>--window_max_height</code></td><td><code>32rem</code></td><td>Maximum height of the message window before it scrolls internally</td></tr>
|
|
202
|
+
<tr><td><code>--chat_padding</code></td><td><code>0.5rem</code></td><td>Padding inside both the message window and the input row</td></tr>
|
|
203
|
+
<tr><td><code>--chat_gap</code></td><td><code>0.5rem</code></td><td>Gap between messages and gap between the editor and the Send button</td></tr>
|
|
204
|
+
<tr><td><code>--height</code></td><td><code>13rem</code></td><td>Initial height of the embedded markdown editor; the user can drag the resize handle below it to grow or shrink past this</td></tr>
|
|
205
|
+
<tr><td><code>--message_max_width</code></td><td><code>75%</code></td><td>Max width of a single message bubble</td></tr>
|
|
206
|
+
<tr><td><code>--message_radius</code></td><td><code>1rem</code></td><td>Border radius of message bubbles</td></tr>
|
|
207
|
+
<tr><td><code>--bubble_padding</code></td><td><code>0.5rem 0.75rem</code></td><td>Padding inside bubbles</td></tr>
|
|
208
|
+
<tr><td><code>--bubble_bg__incoming</code></td><td><code>var(--c_bg__alt)</code></td><td>Background color of incoming bubbles</td></tr>
|
|
209
|
+
<tr><td><code>--bubble_bg__outgoing</code></td><td><code>var(--c_primary)</code></td><td>Background color of outgoing bubbles</td></tr>
|
|
210
|
+
<tr><td><code>--bubble_tc__outgoing</code></td><td><code>white</code></td><td>Text color of outgoing bubbles</td></tr>
|
|
211
|
+
</tbody>
|
|
212
|
+
</table>
|
|
213
|
+
|
|
214
|
+
<h3 id="events"><a href="#events" class="no-link">Events</a></h3>
|
|
215
|
+
<h5><code>send</code></h5>
|
|
216
|
+
<p>Fires when the user submits. <code>detail</code> contains <code>{ id, html, markdown }</code> — <code>html</code> is the rendered+sanitized output (the same string used in the bubble) and <code>markdown</code> is the raw source the user typed. The outgoing message is already in the conversation by the time the event fires — if you need to roll it back (e.g. on a network failure), call <code>updateMessage(id, { status: 'failed' })</code> or <code>removeMessage(id)</code>.</p>
|
|
217
|
+
|
|
218
|
+
<h3 id="security"><a href="#security" class="no-link">Security Notes</a></h3>
|
|
219
|
+
<div class="callout warning b r p mb">
|
|
220
|
+
<strong>The frontend sanitization in this component is not a substitute for server-side sanitization.</strong>
|
|
221
|
+
</div>
|
|
222
|
+
<p>Every message that enters the chat (whether from the user's editor, from <code>addMessage()</code>, or from <code>updateMessage()</code>) runs through <a href="../utils/sanitizeHtml.html"><code>sanitizeHtml</code></a> before it is added to the DOM. That strips <code><script></code>, <code><style></code>, <code><iframe></code>, event-handler attributes, and unsafe URL schemes — but it only protects content that flows through this component.</p>
|
|
223
|
+
<p>If you persist messages on a server and rebroadcast them to other users, the server <strong>must</strong> independently sanitize before storing and again before sending. A determined attacker can submit raw HTTP without ever loading your client code.</p>
|
|
224
|
+
</content>
|
|
225
|
+
<content location="scripts">
|
|
226
|
+
<script type="module" src="{{pathToRoot}}src/components/Chat.js"></script>
|
|
227
|
+
<script type="module" src="{{pathToRoot}}src/components/Accordion.js"></script>
|
|
228
|
+
<script type="module" src="{{pathToRoot}}src/components/Card.js"></script>
|
|
229
|
+
</content>
|
|
230
|
+
</page>
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
<a href="#controlsExample">Built-in Controls</a><br />
|
|
10
10
|
<a href="#customControls">Custom Controls</a><br />
|
|
11
11
|
<a href="#height">Setting Height</a><br />
|
|
12
|
+
<a href="#disabled">Disabled / Read-only</a><br />
|
|
12
13
|
<a href="#jsApi">JavaScript API</a><br />
|
|
13
14
|
|
|
14
15
|
<h6 class="mt"><a href="#jsRef" class="no-link">JavaScript Reference</a></h6>
|
|
@@ -100,6 +101,38 @@ console.log(x);"></k-code-editor>
|
|
|
100
101
|
</div>
|
|
101
102
|
</div>
|
|
102
103
|
|
|
104
|
+
<h3 id="disabled"><a href="#disabled" class="no-link">Disabled / Read-only</a></h3>
|
|
105
|
+
<p>The <code>disabled</code> attribute makes the editor non-interactive (Monaco is set to <code>readOnly</code>), mutes the toolbar, fades the host, and excludes the field from form submission. The <code>readonly</code> attribute lets the user select and copy text but not edit; the value is still submitted with the form.</p>
|
|
106
|
+
<div class="row -mx">
|
|
107
|
+
<div class="col m-span-12 px">
|
|
108
|
+
<k-card label="HTML">
|
|
109
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-code-editor</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"..."</span>></span><span class="hljs-tag"></<span class="hljs-name">k-code-editor</span>></span><br><span class="hljs-tag"><<span class="hljs-name">k-code-editor</span> <span class="hljs-attr">readonly</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"..."</span>></span><span class="hljs-tag"></<span class="hljs-name">k-code-editor</span>></span></code></pre>
|
|
110
|
+
</k-card>
|
|
111
|
+
</div>
|
|
112
|
+
<div class="col m-span-12 px">
|
|
113
|
+
<k-card label="Output">
|
|
114
|
+
<k-code-editor
|
|
115
|
+
disabled
|
|
116
|
+
language="javascript"
|
|
117
|
+
class="b r mb"
|
|
118
|
+
style="height: 160px"
|
|
119
|
+
value="// This editor is disabled — toolbar is muted, content is locked.
|
|
120
|
+
const x = 42;
|
|
121
|
+
console.log(x);"
|
|
122
|
+
></k-code-editor>
|
|
123
|
+
<k-code-editor
|
|
124
|
+
readonly
|
|
125
|
+
language="javascript"
|
|
126
|
+
class="b r"
|
|
127
|
+
style="height: 160px"
|
|
128
|
+
value="// This editor is read-only — select and copy, just not edit.
|
|
129
|
+
const x = 42;
|
|
130
|
+
console.log(x);"
|
|
131
|
+
></k-code-editor>
|
|
132
|
+
</k-card>
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
|
|
103
136
|
<h3 id="jsApi"><a href="#jsApi" class="no-link">JavaScript API</a></h3>
|
|
104
137
|
<p>Interact with the editor programmatically:</p>
|
|
105
138
|
<div class="row -mx">
|
|
@@ -127,6 +160,9 @@ console.log(x);"></k-code-editor>
|
|
|
127
160
|
<tr><td><code>controls</code></td><td><code>controls</code></td><td>String</td><td><code>''</code></td><td>Set to <code>'full'</code> for built-in toolbar; <code>'none'</code> or empty for no built-in controls</td></tr>
|
|
128
161
|
<tr><td><code>monacoSrc</code></td><td><code>monaco-src</code></td><td>String</td><td><code>''</code></td><td>Custom Monaco CDN base URL</td></tr>
|
|
129
162
|
<tr><td><code>editorTheme</code></td><td><code>editor-theme</code></td><td>String</td><td><code>'auto'</code></td><td>Theme override: <code>'auto'</code> (matches site theme), <code>'light'</code>, or <code>'dark'</code></td></tr>
|
|
163
|
+
<tr><td><code>disabled</code></td><td><code>disabled</code></td><td>Boolean</td><td><code>false</code></td><td>Editor is non-interactive (Monaco set to <code>readOnly</code>), toolbar is muted, host fades, and the field is excluded from form submission</td></tr>
|
|
164
|
+
<tr><td><code>readonly</code></td><td><code>readonly</code></td><td>Boolean</td><td><code>false</code></td><td>User can select and copy text but not edit (Monaco set to <code>readOnly</code>); value still submitted with the form</td></tr>
|
|
165
|
+
<tr><td><code>required</code></td><td><code>required</code></td><td>Boolean</td><td><code>false</code></td><td>When <code>true</code> and the editor is empty, the element reports a <code>valueMissing</code> validity error</td></tr>
|
|
130
166
|
</tbody>
|
|
131
167
|
</table>
|
|
132
168
|
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
<a href="#customNodes">Custom Nodes Example</a><br />
|
|
17
17
|
<a href="#preConfigured">Pre-Configured Editors</a><br />
|
|
18
18
|
<a href="#height">Setting Height</a><br />
|
|
19
|
+
<a href="#disabled">Disabled / Read-only</a><br />
|
|
19
20
|
<a href="#javascriptUsage">JavaScript API Example</a><br />
|
|
20
21
|
|
|
21
22
|
<h6 class="mt"><a
|
|
@@ -255,6 +256,37 @@
|
|
|
255
256
|
</div>
|
|
256
257
|
</div>
|
|
257
258
|
|
|
259
|
+
<h3 id="disabled"><a
|
|
260
|
+
href="#disabled"
|
|
261
|
+
class="no-link"
|
|
262
|
+
>Disabled / Read-only</a></h3>
|
|
263
|
+
<p>The <code>disabled</code> attribute makes the editor non-interactive (Lexical is set to non-editable in visual mode, Monaco is set to <code>readOnly</code> in code mode), mutes the toolbar, fades the host, and excludes the field from form submission. The <code>readonly</code> attribute lets the user select and copy text and switch modes, but they can't edit; the value is still submitted with the form.</p>
|
|
264
|
+
<div class="row -mx">
|
|
265
|
+
<div class="col m-span-12 px">
|
|
266
|
+
<k-card label="HTML">
|
|
267
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-html-editor</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"..."</span>></span><span class="hljs-tag"></<span class="hljs-name">k-html-editor</span>></span><br><span class="hljs-tag"><<span class="hljs-name">k-html-editor</span> <span class="hljs-attr">readonly</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"..."</span>></span><span class="hljs-tag"></<span class="hljs-name">k-html-editor</span>></span></code></pre>
|
|
268
|
+
</k-card>
|
|
269
|
+
</div>
|
|
270
|
+
<div class="col m-span-12 px">
|
|
271
|
+
<k-card label="Output">
|
|
272
|
+
<k-html-editor
|
|
273
|
+
disabled
|
|
274
|
+
controls="minimal"
|
|
275
|
+
class="b r mb"
|
|
276
|
+
style="height: 200px"
|
|
277
|
+
value="<p>This editor is <b>disabled</b> — the toolbar, content, and mode toggle are all inert.</p>"
|
|
278
|
+
></k-html-editor>
|
|
279
|
+
<k-html-editor
|
|
280
|
+
readonly
|
|
281
|
+
controls="minimal"
|
|
282
|
+
class="b r"
|
|
283
|
+
style="height: 200px"
|
|
284
|
+
value="<p>This editor is <i>read-only</i> — you can select and copy, just not edit.</p>"
|
|
285
|
+
></k-html-editor>
|
|
286
|
+
</k-card>
|
|
287
|
+
</div>
|
|
288
|
+
</div>
|
|
289
|
+
|
|
258
290
|
<h3 id="javascriptUsage"><a
|
|
259
291
|
href="#javascriptUsage"
|
|
260
292
|
class="no-link"
|
|
@@ -392,6 +424,15 @@
|
|
|
392
424
|
Configuration</a> for the full resolution order.
|
|
393
425
|
</p>
|
|
394
426
|
|
|
427
|
+
<h5><code>disabled<i>: Boolean</i></code></h5>
|
|
428
|
+
<p>When <code>true</code>, the editor is non-interactive (Lexical's <code>setEditable(false)</code> in visual mode, Monaco's <code>readOnly</code> in code mode), the toolbar is muted, the host fades to <code>opacity: 0.6</code>, and the field is excluded from form submission. Syncs to <code>disabled</code> attribute.</p>
|
|
429
|
+
|
|
430
|
+
<h5><code>readonly<i>: Boolean</i></code></h5>
|
|
431
|
+
<p>When <code>true</code>, the user can select and copy text but not edit. The value is still submitted with the form. Syncs to <code>readonly</code> attribute.</p>
|
|
432
|
+
|
|
433
|
+
<h5><code>required<i>: Boolean</i></code></h5>
|
|
434
|
+
<p>When <code>true</code> and the editor is empty (no non-whitespace text), the element reports a <code>valueMissing</code> validity error to its parent <code><form></code>. Syncs to <code>required</code> attribute.</p>
|
|
435
|
+
|
|
395
436
|
<h3 id="globalConfig"><a
|
|
396
437
|
href="#globalConfig"
|
|
397
438
|
class="no-link"
|