kempo-ui 0.4.5 → 0.4.7
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/Markdown.js +1 -0
- package/dist/components/MarkdownEditor.js +173 -0
- package/dist/components/Resize.js +12 -2
- 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/docs/components/accordion.html +16 -0
- package/docs/components/aside.html +16 -0
- package/docs/components/calendar.html +16 -0
- package/docs/components/card.html +16 -0
- package/docs/components/chat.html +719 -0
- package/docs/components/code-editor.html +52 -0
- package/docs/components/color-picker.html +16 -0
- package/docs/components/combobox.html +16 -0
- package/docs/components/content-slider.html +16 -0
- package/docs/components/context.html +16 -0
- package/docs/components/dialog.html +16 -0
- package/docs/components/dropdown.html +16 -0
- package/docs/components/filter-list.html +16 -0
- package/docs/components/focus-capture.html +16 -0
- package/docs/components/html-editor.html +57 -0
- package/docs/components/hybrid-component.html +16 -0
- package/docs/components/icon.html +16 -0
- package/docs/components/import.html +16 -0
- package/docs/components/light-component.html +16 -0
- package/docs/components/markdown-editor.html +928 -0
- package/docs/components/markdown.html +650 -0
- package/docs/components/nav-spacer.html +16 -0
- package/docs/components/nav.html +16 -0
- package/docs/components/photo-viewer.html +16 -0
- package/docs/components/progress.html +16 -0
- package/docs/components/resize.html +19 -0
- package/docs/components/rich-textarea.html +650 -0
- package/docs/components/shadow-component.html +16 -0
- package/docs/components/show-more.html +16 -0
- package/docs/components/slider.html +16 -0
- package/docs/components/sortable.html +16 -0
- package/docs/components/speech-to-text.html +16 -0
- package/docs/components/spinner.html +16 -0
- package/docs/components/split.html +16 -0
- package/docs/components/table.html +16 -0
- package/docs/components/tableControls.html +16 -0
- package/docs/components/tableCustomFields.html +16 -0
- package/docs/components/tableFetchRecords.html +16 -0
- package/docs/components/tableFieldSortHide.html +16 -0
- package/docs/components/tablePagination.html +16 -0
- package/docs/components/tablePlaceholder.html +16 -0
- package/docs/components/tableRecordEditing.html +16 -0
- package/docs/components/tableRecordFiltering.html +16 -0
- package/docs/components/tableRecordHiding.html +16 -0
- package/docs/components/tableRecordSearching.html +16 -0
- package/docs/components/tableRecordSelection.html +16 -0
- package/docs/components/tableRowControls.html +16 -0
- package/docs/components/tableServerSync.html +16 -0
- package/docs/components/tableSorting.html +16 -0
- package/docs/components/tabs.html +16 -0
- package/docs/components/tags.html +16 -0
- package/docs/components/text-to-speech.html +16 -0
- package/docs/components/theme-select.html +16 -0
- package/docs/components/theme-switcher.html +16 -0
- package/docs/components/time.html +16 -0
- package/docs/components/timestamp.html +16 -0
- package/docs/components/toast.html +16 -0
- package/docs/components/toggle.html +16 -0
- package/docs/components/tree.html +16 -0
- package/docs/components/voice-selector.html +16 -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 +40 -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/Markdown.js +1 -0
- package/docs/src/components/MarkdownEditor.js +173 -0
- package/docs/src/components/Resize.js +12 -2
- 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/utils/context.html +16 -0
- package/docs/utils/cookie.html +16 -0
- package/docs/utils/debounce.html +16 -0
- package/docs/utils/drag.html +16 -0
- package/docs/utils/elevation.html +20 -10
- package/docs/utils/formatTimestamp.html +16 -0
- package/docs/utils/object.html +16 -0
- package/docs/utils/propConverters.html +16 -0
- package/docs/utils/sanitizeHtml.html +559 -0
- package/docs/utils/string.html +16 -0
- package/docs/utils/theme.html +16 -0
- package/docs/utils/toTitleCase.html +16 -0
- package/docs/utils/type.html +16 -0
- package/docs/utils/voice.html +16 -0
- package/docs/utils/wait.html +16 -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/markdown.page.html +161 -0
- package/docs-src/components/resize.page.html +3 -0
- package/docs-src/index.page.html +24 -0
- package/docs-src/nav.fragment.html +16 -0
- package/docs-src/utils/elevation.page.html +4 -10
- package/docs-src/utils/sanitizeHtml.page.html +73 -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 +6 -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/Markdown.js +125 -0
- package/src/components/MarkdownEditor.js +654 -0
- package/src/components/Resize.js +17 -1
- 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/tests/components/Chat.browser-test.js +540 -0
- package/tests/components/Markdown.browser-test.js +292 -0
- package/tests/utils/sanitizeHtml.browser-test.js +179 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { html, unsafeHTML } from '../lit-all.min.js';
|
|
2
|
+
import LightComponent from './LightComponent.js';
|
|
3
|
+
import renderMarkdown from '../utils/renderMarkdown.js';
|
|
4
|
+
import sanitizeHtml, { STRIP_COMPLETELY } from '../utils/sanitizeHtml.js';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
k-markdown
|
|
8
|
+
|
|
9
|
+
Reads markdown from its child text content (or the `value` attribute) and
|
|
10
|
+
renders the HTML equivalent in-place. Markdown is parsed with the vendored
|
|
11
|
+
`marked` (CommonMark + GFM) and the resulting HTML is run through
|
|
12
|
+
`sanitizeHtml` before being inserted, with the same allowed-tags /
|
|
13
|
+
disallowed-tags / scripts-enabled controls as MarkdownEditor's preview.
|
|
14
|
+
|
|
15
|
+
Renders to the light DOM so page-level typography and styles cascade into
|
|
16
|
+
headings, paragraphs, tables, etc. without extra wiring.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export default class Markdown extends LightComponent {
|
|
20
|
+
static properties = {
|
|
21
|
+
value: { type: String },
|
|
22
|
+
breaks: { type: Boolean, reflect: true },
|
|
23
|
+
allowedTags: { type: String, reflect: true, attribute: 'allowed-tags' },
|
|
24
|
+
disallowedTags: { type: String, reflect: true, attribute: 'disallowed-tags' },
|
|
25
|
+
scriptsEnabled: { type: Boolean, reflect: true, attribute: 'scripts-enabled' }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
#captured = false;
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
Lifecycle Callbacks
|
|
32
|
+
*/
|
|
33
|
+
constructor() {
|
|
34
|
+
super();
|
|
35
|
+
this.value = '';
|
|
36
|
+
this.breaks = false;
|
|
37
|
+
this.allowedTags = '';
|
|
38
|
+
this.disallowedTags = '';
|
|
39
|
+
this.scriptsEnabled = false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
connectedCallback() {
|
|
43
|
+
// Capture and clear the original markdown children BEFORE Lit appends
|
|
44
|
+
// its lightRoot div — once super runs, lightRoot lives among the
|
|
45
|
+
// siblings we'd otherwise scan. After capture, the markdown lives on
|
|
46
|
+
// the `value` property; the source nodes are dropped so the parsed
|
|
47
|
+
// HTML doesn't render alongside its raw source.
|
|
48
|
+
if(!this.#captured){
|
|
49
|
+
this.#captured = true;
|
|
50
|
+
const text = this.textContent || '';
|
|
51
|
+
const dedented = dedent(text);
|
|
52
|
+
while(this.firstChild) this.removeChild(this.firstChild);
|
|
53
|
+
if(!this.hasAttribute('value') && !this.value && dedented){
|
|
54
|
+
this.value = dedented;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
super.connectedCallback();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
Public Methods
|
|
62
|
+
*/
|
|
63
|
+
get renderedHtml() {
|
|
64
|
+
const opts = {};
|
|
65
|
+
const resolved = this.#resolvedAllowedTags;
|
|
66
|
+
if(resolved) opts.allowedTags = resolved;
|
|
67
|
+
if(this.scriptsEnabled){
|
|
68
|
+
const stripCompletely = new Set(STRIP_COMPLETELY);
|
|
69
|
+
stripCompletely.delete('SCRIPT');
|
|
70
|
+
opts.stripCompletely = stripCompletely;
|
|
71
|
+
}
|
|
72
|
+
return sanitizeHtml(renderMarkdown(this.value || '', { breaks: this.breaks }), opts);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/*
|
|
76
|
+
Utility
|
|
77
|
+
*/
|
|
78
|
+
get #resolvedAllowedTags() {
|
|
79
|
+
const allow = (this.allowedTags || '').trim();
|
|
80
|
+
const deny = (this.disallowedTags || '').trim();
|
|
81
|
+
if(allow && deny){
|
|
82
|
+
console.warn('[k-markdown] `allowed-tags` and `disallowed-tags` are mutually exclusive; using `allowed-tags`.');
|
|
83
|
+
}
|
|
84
|
+
if(allow){
|
|
85
|
+
if(allow === '*') return { has: () => true };
|
|
86
|
+
return new Set(allow.split(',').map(t => t.trim().toUpperCase()).filter(Boolean));
|
|
87
|
+
}
|
|
88
|
+
if(deny){
|
|
89
|
+
const denySet = new Set(deny.split(',').map(t => t.trim().toUpperCase()).filter(Boolean));
|
|
90
|
+
return { has: (tag) => !denySet.has(tag) };
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
Rendering
|
|
97
|
+
*/
|
|
98
|
+
renderLightDom() {
|
|
99
|
+
if(!this.value) return html``;
|
|
100
|
+
return html`${unsafeHTML(this.renderedHtml)}`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
Strip a common leading indent from every line so users can indent the
|
|
106
|
+
markdown source to match the surrounding HTML without breaking parsing.
|
|
107
|
+
Also trims fully-blank leading/trailing lines.
|
|
108
|
+
*/
|
|
109
|
+
const dedent = (text) => {
|
|
110
|
+
const lines = text.split('\n');
|
|
111
|
+
while(lines.length && lines[0].trim() === '') lines.shift();
|
|
112
|
+
while(lines.length && lines[lines.length - 1].trim() === '') lines.pop();
|
|
113
|
+
if(!lines.length) return '';
|
|
114
|
+
let minIndent = Infinity;
|
|
115
|
+
for(const line of lines){
|
|
116
|
+
if(line.trim().length === 0) continue;
|
|
117
|
+
const match = line.match(/^(\s*)/);
|
|
118
|
+
const indent = match ? match[1].length : 0;
|
|
119
|
+
if(indent < minIndent) minIndent = indent;
|
|
120
|
+
}
|
|
121
|
+
if(minIndent === Infinity) minIndent = 0;
|
|
122
|
+
return lines.map(l => l.slice(minIndent)).join('\n');
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
customElements.define('k-markdown', Markdown);
|