@liwe3/webcomponents 1.0.14 → 1.1.10

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 (85) hide show
  1. package/dist/AIMarkdownEditor.d.ts +35 -0
  2. package/dist/AIMarkdownEditor.d.ts.map +1 -0
  3. package/dist/AIMarkdownEditor.js +412 -0
  4. package/dist/AIMarkdownEditor.js.map +1 -0
  5. package/dist/AITextEditor.d.ts +183 -0
  6. package/dist/AITextEditor.d.ts.map +1 -0
  7. package/dist/AITextEditor.js +63 -27
  8. package/dist/AITextEditor.js.map +1 -1
  9. package/dist/ButtonToolbar.d.ts +35 -0
  10. package/dist/ButtonToolbar.d.ts.map +1 -0
  11. package/dist/ButtonToolbar.js +220 -0
  12. package/dist/ButtonToolbar.js.map +1 -0
  13. package/dist/CheckList.d.ts +31 -0
  14. package/dist/CheckList.d.ts.map +1 -0
  15. package/dist/CheckList.js +336 -0
  16. package/dist/CheckList.js.map +1 -0
  17. package/dist/ChunkUploader.d.ts +125 -0
  18. package/dist/ChunkUploader.d.ts.map +1 -0
  19. package/dist/ChunkUploader.js +756 -0
  20. package/dist/ChunkUploader.js.map +1 -0
  21. package/dist/ComicBalloon.d.ts +82 -0
  22. package/dist/ComicBalloon.d.ts.map +1 -0
  23. package/dist/ComicBalloon.js +346 -0
  24. package/dist/ComicBalloon.js.map +1 -0
  25. package/dist/ContainerBox.d.ts +112 -0
  26. package/dist/ContainerBox.d.ts.map +1 -0
  27. package/dist/ContainerBox.js +359 -0
  28. package/dist/ContainerBox.js.map +1 -0
  29. package/dist/DateSelector.d.ts +103 -0
  30. package/dist/DateSelector.d.ts.map +1 -0
  31. package/dist/Dialog.d.ts +102 -0
  32. package/dist/Dialog.d.ts.map +1 -0
  33. package/dist/Dialog.js +299 -0
  34. package/dist/Dialog.js.map +1 -0
  35. package/dist/Drawer.d.ts +63 -0
  36. package/dist/Drawer.d.ts.map +1 -0
  37. package/dist/Drawer.js +340 -0
  38. package/dist/Drawer.js.map +1 -0
  39. package/dist/ImageView.d.ts +42 -0
  40. package/dist/ImageView.d.ts.map +1 -0
  41. package/dist/ImageView.js +209 -0
  42. package/dist/ImageView.js.map +1 -0
  43. package/dist/MarkdownPreview.d.ts +25 -0
  44. package/dist/MarkdownPreview.d.ts.map +1 -0
  45. package/dist/MarkdownPreview.js +147 -0
  46. package/dist/MarkdownPreview.js.map +1 -0
  47. package/dist/PopoverMenu.d.ts +103 -0
  48. package/dist/PopoverMenu.d.ts.map +1 -0
  49. package/dist/ResizableCropper.d.ts +158 -0
  50. package/dist/ResizableCropper.d.ts.map +1 -0
  51. package/dist/ResizableCropper.js +562 -0
  52. package/dist/ResizableCropper.js.map +1 -0
  53. package/dist/SmartSelect.d.ts +100 -0
  54. package/dist/SmartSelect.d.ts.map +1 -0
  55. package/dist/SmartSelect.js +45 -2
  56. package/dist/SmartSelect.js.map +1 -1
  57. package/dist/Toast.d.ts +127 -0
  58. package/dist/Toast.d.ts.map +1 -0
  59. package/dist/Toast.js +79 -49
  60. package/dist/Toast.js.map +1 -1
  61. package/dist/TreeView.d.ts +84 -0
  62. package/dist/TreeView.d.ts.map +1 -0
  63. package/dist/TreeView.js +478 -0
  64. package/dist/TreeView.js.map +1 -0
  65. package/dist/index.d.ts +23 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.js +51 -14
  68. package/dist/index.js.map +1 -1
  69. package/package.json +60 -5
  70. package/src/AIMarkdownEditor.ts +568 -0
  71. package/src/AITextEditor.ts +97 -2
  72. package/src/ButtonToolbar.ts +302 -0
  73. package/src/CheckList.ts +438 -0
  74. package/src/ChunkUploader.ts +1135 -0
  75. package/src/ComicBalloon.ts +709 -0
  76. package/src/ContainerBox.ts +570 -0
  77. package/src/Dialog.ts +510 -0
  78. package/src/Drawer.ts +435 -0
  79. package/src/ImageView.ts +265 -0
  80. package/src/MarkdownPreview.ts +213 -0
  81. package/src/ResizableCropper.ts +1099 -0
  82. package/src/SmartSelect.ts +48 -2
  83. package/src/Toast.ts +96 -32
  84. package/src/TreeView.ts +673 -0
  85. package/src/index.ts +129 -27
@@ -0,0 +1,213 @@
1
+ /**
2
+ * MarkdownPreview Web Component
3
+ * Renders markdown content using a dynamically loaded library
4
+ */
5
+
6
+ export class MarkdownPreviewElement extends HTMLElement {
7
+ declare shadowRoot: ShadowRoot;
8
+ private _libUrl: string = 'https://cdn.jsdelivr.net/npm/marked@4.3.0/marked.min.js';
9
+ private _value: string = '';
10
+ private _isLibLoaded: boolean = false;
11
+ private _isLoadingLib: boolean = false;
12
+ private container!: HTMLElement;
13
+
14
+ static get observedAttributes() {
15
+ return ['lib-url', 'value'];
16
+ }
17
+
18
+ constructor() {
19
+ super();
20
+ this.attachShadow({ mode: 'open' });
21
+ this.render();
22
+ }
23
+
24
+ connectedCallback() {
25
+ this.loadLibrary();
26
+ }
27
+
28
+ attributeChangedCallback(name: string, oldValue: string, newValue: string) {
29
+ if (oldValue === newValue) return;
30
+
31
+ if (name === 'lib-url') {
32
+ this._libUrl = newValue;
33
+ this._isLibLoaded = false; // Reset loaded state if URL changes
34
+ this.loadLibrary();
35
+ } else if (name === 'value') {
36
+ // Only update internal value if it differs, to avoid loops if we were to reflect
37
+ if (this._value !== newValue) {
38
+ this.value = newValue;
39
+ }
40
+ }
41
+ }
42
+
43
+ get libUrl(): string {
44
+ return this._libUrl;
45
+ }
46
+
47
+ set libUrl(value: string) {
48
+ this.setAttribute('lib-url', value);
49
+ }
50
+
51
+ get value(): string {
52
+ return this._value;
53
+ }
54
+
55
+ set value(content: string) {
56
+ this._value = content;
57
+ this.updateContent();
58
+ // We do NOT reflect to attribute to avoid performance issues with large content
59
+ }
60
+
61
+ private render() {
62
+ this.shadowRoot.innerHTML = `
63
+ <style>
64
+ :host {
65
+ display: block;
66
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
67
+ line-height: 1.6;
68
+ color: #333;
69
+ }
70
+ .markdown-body {
71
+ box-sizing: border-box;
72
+ min-width: 200px;
73
+ max-width: 980px;
74
+ margin: 0 auto;
75
+ padding: 15px;
76
+ }
77
+ img {
78
+ max-width: 100%;
79
+ }
80
+ pre {
81
+ background-color: #f6f8fa;
82
+ border-radius: 6px;
83
+ padding: 16px;
84
+ overflow: auto;
85
+ }
86
+ code {
87
+ font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
88
+ font-size: 85%;
89
+ background-color: rgba(175, 184, 193, 0.2);
90
+ padding: 0.2em 0.4em;
91
+ border-radius: 6px;
92
+ }
93
+ pre code {
94
+ background-color: transparent;
95
+ padding: 0;
96
+ }
97
+ blockquote {
98
+ border-left: 0.25em solid #d0d7de;
99
+ color: #656d76;
100
+ padding: 0 1em;
101
+ margin: 0;
102
+ }
103
+ table {
104
+ border-spacing: 0;
105
+ border-collapse: collapse;
106
+ display: block;
107
+ width: max-content;
108
+ max-width: 100%;
109
+ overflow: auto;
110
+ }
111
+ table th,
112
+ table td {
113
+ padding: 6px 13px;
114
+ border: 1px solid #d0d7de;
115
+ }
116
+ table tr {
117
+ background-color: #ffffff;
118
+ border-top: 1px solid #d8dee4;
119
+ }
120
+ table tr:nth-child(2n) {
121
+ background-color: #f6f8fa;
122
+ }
123
+ </style>
124
+ <div class="markdown-body" id="content"></div>
125
+ `;
126
+ this.container = this.shadowRoot.getElementById('content') as HTMLElement;
127
+ }
128
+
129
+ private async loadLibrary() {
130
+ if (this._isLibLoaded || this._isLoadingLib) return;
131
+
132
+ // Check if marked is already available globally
133
+ if (typeof (window as any).marked === 'function' || (typeof (window as any).marked === 'object' && typeof (window as any).marked.parse === 'function')) {
134
+ this._isLibLoaded = true;
135
+ this.updateContent();
136
+ return;
137
+ }
138
+
139
+ this._isLoadingLib = true;
140
+
141
+ try {
142
+ const script = document.createElement('script');
143
+ script.src = this._libUrl;
144
+ script.onload = () => {
145
+ // Double check if marked is available
146
+ if (!(window as any).marked) {
147
+ console.error('MarkdownPreview: Library loaded but window.marked is undefined');
148
+ this.container.innerHTML = `<div style="color: red;">Error: Markdown library loaded but not found. Try a different URL.</div>`;
149
+ this._isLoadingLib = false;
150
+ return;
151
+ }
152
+ this._isLibLoaded = true;
153
+ this._isLoadingLib = false;
154
+ this.updateContent();
155
+ this.dispatchEvent(new CustomEvent('library-loaded'));
156
+ };
157
+ script.onerror = () => {
158
+ this._isLoadingLib = false;
159
+ console.error(`Failed to load markdown library from ${this._libUrl}`);
160
+ this.container.innerHTML = `<div style="color: red;">Error loading markdown library</div>`;
161
+ };
162
+ document.head.appendChild(script);
163
+ } catch (e) {
164
+ this._isLoadingLib = false;
165
+ console.error(e);
166
+ }
167
+ }
168
+
169
+ private updateContent() {
170
+ if (!this._isLibLoaded) {
171
+ if (!this._isLoadingLib) {
172
+ this.loadLibrary();
173
+ }
174
+ return;
175
+ }
176
+
177
+ const marked = (window as any).marked;
178
+ if (!marked) {
179
+ console.error('Marked library loaded but not found in window');
180
+ return;
181
+ }
182
+
183
+ try {
184
+ // Handle both function style (older marked) and object style (newer marked)
185
+ const parse = typeof marked === 'function' ? marked : marked.parse;
186
+ if (typeof parse === 'function') {
187
+ const html = parse(this._value);
188
+ // If it returns a promise (async), handle it
189
+ if (html instanceof Promise) {
190
+ html.then((res: string) => {
191
+ this.container.innerHTML = res;
192
+ });
193
+ } else {
194
+ this.container.innerHTML = html;
195
+ }
196
+ } else {
197
+ console.error('Marked parse function not found');
198
+ this.container.innerHTML = `<div style="color: red;">Error: marked.parse not found</div>`;
199
+ }
200
+ } catch (e) {
201
+ console.error('Error parsing markdown:', e);
202
+ this.container.innerHTML = `<div style="color: red;">Error parsing markdown</div>`;
203
+ }
204
+ }
205
+ }
206
+
207
+ export const defineMarkdownPreview = (tagName: string = 'liwe3-markdown-preview') => {
208
+ if (typeof window !== 'undefined' && !customElements.get(tagName)) {
209
+ customElements.define(tagName, MarkdownPreviewElement);
210
+ }
211
+ };
212
+
213
+ defineMarkdownPreview();