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.
Files changed (176) hide show
  1. package/dist/components/Chat.js +201 -0
  2. package/dist/components/CodeEditor.js +21 -2
  3. package/dist/components/Dropdown.js +1 -1
  4. package/dist/components/HtmlEditor.js +42 -3
  5. package/dist/components/Markdown.js +1 -0
  6. package/dist/components/MarkdownEditor.js +173 -0
  7. package/dist/components/Resize.js +12 -2
  8. package/dist/components/markdownEditorControls/Bold.js +11 -0
  9. package/dist/components/markdownEditorControls/BulletList.js +11 -0
  10. package/dist/components/markdownEditorControls/Code.js +11 -0
  11. package/dist/components/markdownEditorControls/FormatBlock.js +30 -0
  12. package/dist/components/markdownEditorControls/Heading.js +11 -0
  13. package/dist/components/markdownEditorControls/Image.js +93 -0
  14. package/dist/components/markdownEditorControls/Italic.js +11 -0
  15. package/dist/components/markdownEditorControls/Link.js +11 -0
  16. package/dist/components/markdownEditorControls/MarkdownEditorControl.js +39 -0
  17. package/dist/components/markdownEditorControls/Menu.js +30 -0
  18. package/dist/components/markdownEditorControls/NumberedList.js +11 -0
  19. package/dist/components/markdownEditorControls/Quote.js +11 -0
  20. package/dist/components/markdownEditorControls/SpeechToText.js +16 -0
  21. package/dist/components/markdownEditorControls/Strikethrough.js +11 -0
  22. package/dist/components/markdownEditorControls/Table.js +80 -0
  23. package/dist/utils/marked.esm.js +1 -0
  24. package/dist/utils/renderMarkdown.js +1 -0
  25. package/dist/utils/sanitizeHtml.js +1 -0
  26. package/docs/components/accordion.html +16 -0
  27. package/docs/components/aside.html +16 -0
  28. package/docs/components/calendar.html +16 -0
  29. package/docs/components/card.html +16 -0
  30. package/docs/components/chat.html +719 -0
  31. package/docs/components/code-editor.html +52 -0
  32. package/docs/components/color-picker.html +16 -0
  33. package/docs/components/combobox.html +16 -0
  34. package/docs/components/content-slider.html +16 -0
  35. package/docs/components/context.html +16 -0
  36. package/docs/components/dialog.html +16 -0
  37. package/docs/components/dropdown.html +16 -0
  38. package/docs/components/filter-list.html +16 -0
  39. package/docs/components/focus-capture.html +16 -0
  40. package/docs/components/html-editor.html +57 -0
  41. package/docs/components/hybrid-component.html +16 -0
  42. package/docs/components/icon.html +16 -0
  43. package/docs/components/import.html +16 -0
  44. package/docs/components/light-component.html +16 -0
  45. package/docs/components/markdown-editor.html +928 -0
  46. package/docs/components/markdown.html +650 -0
  47. package/docs/components/nav-spacer.html +16 -0
  48. package/docs/components/nav.html +16 -0
  49. package/docs/components/photo-viewer.html +16 -0
  50. package/docs/components/progress.html +16 -0
  51. package/docs/components/resize.html +19 -0
  52. package/docs/components/rich-textarea.html +650 -0
  53. package/docs/components/shadow-component.html +16 -0
  54. package/docs/components/show-more.html +16 -0
  55. package/docs/components/slider.html +16 -0
  56. package/docs/components/sortable.html +16 -0
  57. package/docs/components/speech-to-text.html +16 -0
  58. package/docs/components/spinner.html +16 -0
  59. package/docs/components/split.html +16 -0
  60. package/docs/components/table.html +16 -0
  61. package/docs/components/tableControls.html +16 -0
  62. package/docs/components/tableCustomFields.html +16 -0
  63. package/docs/components/tableFetchRecords.html +16 -0
  64. package/docs/components/tableFieldSortHide.html +16 -0
  65. package/docs/components/tablePagination.html +16 -0
  66. package/docs/components/tablePlaceholder.html +16 -0
  67. package/docs/components/tableRecordEditing.html +16 -0
  68. package/docs/components/tableRecordFiltering.html +16 -0
  69. package/docs/components/tableRecordHiding.html +16 -0
  70. package/docs/components/tableRecordSearching.html +16 -0
  71. package/docs/components/tableRecordSelection.html +16 -0
  72. package/docs/components/tableRowControls.html +16 -0
  73. package/docs/components/tableServerSync.html +16 -0
  74. package/docs/components/tableSorting.html +16 -0
  75. package/docs/components/tabs.html +16 -0
  76. package/docs/components/tags.html +16 -0
  77. package/docs/components/text-to-speech.html +16 -0
  78. package/docs/components/theme-select.html +16 -0
  79. package/docs/components/theme-switcher.html +16 -0
  80. package/docs/components/time.html +16 -0
  81. package/docs/components/timestamp.html +16 -0
  82. package/docs/components/toast.html +16 -0
  83. package/docs/components/toggle.html +16 -0
  84. package/docs/components/tree.html +16 -0
  85. package/docs/components/voice-selector.html +16 -0
  86. package/docs/icons/done_all.svg +1 -0
  87. package/docs/icons/format_quote.svg +1 -0
  88. package/docs/icons/format_strikethrough.svg +1 -0
  89. package/docs/icons/send.svg +1 -0
  90. package/docs/icons/text_fields.svg +1 -0
  91. package/docs/index.html +40 -0
  92. package/docs/src/components/Chat.js +201 -0
  93. package/docs/src/components/CodeEditor.js +21 -2
  94. package/docs/src/components/Dropdown.js +1 -1
  95. package/docs/src/components/HtmlEditor.js +42 -3
  96. package/docs/src/components/Markdown.js +1 -0
  97. package/docs/src/components/MarkdownEditor.js +173 -0
  98. package/docs/src/components/Resize.js +12 -2
  99. package/docs/src/components/markdownEditorControls/Bold.js +11 -0
  100. package/docs/src/components/markdownEditorControls/BulletList.js +11 -0
  101. package/docs/src/components/markdownEditorControls/Code.js +11 -0
  102. package/docs/src/components/markdownEditorControls/FormatBlock.js +30 -0
  103. package/docs/src/components/markdownEditorControls/Heading.js +11 -0
  104. package/docs/src/components/markdownEditorControls/Image.js +93 -0
  105. package/docs/src/components/markdownEditorControls/Italic.js +11 -0
  106. package/docs/src/components/markdownEditorControls/Link.js +11 -0
  107. package/docs/src/components/markdownEditorControls/MarkdownEditorControl.js +39 -0
  108. package/docs/src/components/markdownEditorControls/Menu.js +30 -0
  109. package/docs/src/components/markdownEditorControls/NumberedList.js +11 -0
  110. package/docs/src/components/markdownEditorControls/Quote.js +11 -0
  111. package/docs/src/components/markdownEditorControls/SpeechToText.js +16 -0
  112. package/docs/src/components/markdownEditorControls/Strikethrough.js +11 -0
  113. package/docs/src/components/markdownEditorControls/Table.js +80 -0
  114. package/docs/src/utils/marked.esm.js +1 -0
  115. package/docs/src/utils/renderMarkdown.js +1 -0
  116. package/docs/src/utils/sanitizeHtml.js +1 -0
  117. package/docs/utils/context.html +16 -0
  118. package/docs/utils/cookie.html +16 -0
  119. package/docs/utils/debounce.html +16 -0
  120. package/docs/utils/drag.html +16 -0
  121. package/docs/utils/elevation.html +20 -10
  122. package/docs/utils/formatTimestamp.html +16 -0
  123. package/docs/utils/object.html +16 -0
  124. package/docs/utils/propConverters.html +16 -0
  125. package/docs/utils/sanitizeHtml.html +559 -0
  126. package/docs/utils/string.html +16 -0
  127. package/docs/utils/theme.html +16 -0
  128. package/docs/utils/toTitleCase.html +16 -0
  129. package/docs/utils/type.html +16 -0
  130. package/docs/utils/voice.html +16 -0
  131. package/docs/utils/wait.html +16 -0
  132. package/docs-src/components/chat.page.html +230 -0
  133. package/docs-src/components/code-editor.page.html +36 -0
  134. package/docs-src/components/html-editor.page.html +41 -0
  135. package/docs-src/components/markdown-editor.page.html +439 -0
  136. package/docs-src/components/markdown.page.html +161 -0
  137. package/docs-src/components/resize.page.html +3 -0
  138. package/docs-src/index.page.html +24 -0
  139. package/docs-src/nav.fragment.html +16 -0
  140. package/docs-src/utils/elevation.page.html +4 -10
  141. package/docs-src/utils/sanitizeHtml.page.html +73 -0
  142. package/icons/done_all.svg +1 -0
  143. package/icons/format_quote.svg +1 -0
  144. package/icons/format_strikethrough.svg +1 -0
  145. package/icons/send.svg +1 -0
  146. package/icons/text_fields.svg +1 -0
  147. package/llms.txt +6 -2
  148. package/package.json +3 -2
  149. package/src/components/Chat.js +435 -0
  150. package/src/components/CodeEditor.js +58 -2
  151. package/src/components/Dropdown.js +1 -1
  152. package/src/components/HtmlEditor.js +84 -4
  153. package/src/components/Markdown.js +125 -0
  154. package/src/components/MarkdownEditor.js +654 -0
  155. package/src/components/Resize.js +17 -1
  156. package/src/components/markdownEditorControls/Bold.js +30 -0
  157. package/src/components/markdownEditorControls/BulletList.js +30 -0
  158. package/src/components/markdownEditorControls/Code.js +39 -0
  159. package/src/components/markdownEditorControls/FormatBlock.js +102 -0
  160. package/src/components/markdownEditorControls/Heading.js +45 -0
  161. package/src/components/markdownEditorControls/Image.js +250 -0
  162. package/src/components/markdownEditorControls/Italic.js +30 -0
  163. package/src/components/markdownEditorControls/Link.js +74 -0
  164. package/src/components/markdownEditorControls/MarkdownEditorControl.js +158 -0
  165. package/src/components/markdownEditorControls/Menu.js +86 -0
  166. package/src/components/markdownEditorControls/NumberedList.js +69 -0
  167. package/src/components/markdownEditorControls/Quote.js +30 -0
  168. package/src/components/markdownEditorControls/SpeechToText.js +65 -0
  169. package/src/components/markdownEditorControls/Strikethrough.js +35 -0
  170. package/src/components/markdownEditorControls/Table.js +164 -0
  171. package/src/utils/marked.esm.js +77 -0
  172. package/src/utils/renderMarkdown.js +29 -0
  173. package/src/utils/sanitizeHtml.js +137 -0
  174. package/tests/components/Chat.browser-test.js +540 -0
  175. package/tests/components/Markdown.browser-test.js +292 -0
  176. 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);