marz-ui 1.0.0 → 1.0.2
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/index.js +573 -8
- package/package.json +8 -2
package/dist/index.js
CHANGED
|
@@ -1,10 +1,575 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import "./styles/style.css";
|
|
2
|
+
import { MarzButton as x } from "./components/button/index.js";
|
|
3
|
+
import { MarzInput as w } from "./components/input/index.js";
|
|
4
|
+
import { MarzSidepanel as f } from "./components/sidepanel/index.js";
|
|
5
|
+
class c extends HTMLElement {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(), this.currentPage = 1, this.totalPages = 1, this.attachShadow({ mode: "open" }), this.container = document.createElement("div"), this.container.className = "pagination-container", this.shadowRoot.appendChild(this.getStyles()), this.shadowRoot.appendChild(this.container), this.render();
|
|
8
|
+
}
|
|
9
|
+
static get observedAttributes() {
|
|
10
|
+
return ["current-page", "total-pages"];
|
|
11
|
+
}
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.currentPage = parseInt(this.getAttribute("current-page") || "1"), this.totalPages = parseInt(this.getAttribute("total-pages") || "1"), this.render();
|
|
14
|
+
}
|
|
15
|
+
attributeChangedCallback(t, e, a) {
|
|
16
|
+
if (e !== a) {
|
|
17
|
+
switch (t) {
|
|
18
|
+
case "current-page":
|
|
19
|
+
this.currentPage = parseInt(a) || 1;
|
|
20
|
+
break;
|
|
21
|
+
case "total-pages":
|
|
22
|
+
this.totalPages = parseInt(a) || 1;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
this.render();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getStyles() {
|
|
29
|
+
const t = document.createElement("style");
|
|
30
|
+
return t.textContent = `
|
|
31
|
+
.pagination-container {
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
gap: 8px;
|
|
36
|
+
padding: 16px 0;
|
|
37
|
+
font-family: 'Inter', sans-serif;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.pagination-button {
|
|
41
|
+
min-width: 40px;
|
|
42
|
+
height: 40px;
|
|
43
|
+
padding: 8px 12px;
|
|
44
|
+
border: 1px solid var(--bg-element-2);
|
|
45
|
+
background-color: var(--bg);
|
|
46
|
+
color: var(--text);
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
border-radius: 4px;
|
|
49
|
+
font-size: 14px;
|
|
50
|
+
font-weight: 500;
|
|
51
|
+
transition: all 0.2s ease;
|
|
52
|
+
display: flex;
|
|
53
|
+
align-items: center;
|
|
54
|
+
justify-content: center;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.pagination-button:hover:not(:disabled) {
|
|
58
|
+
background-color: var(--bg-element);
|
|
59
|
+
border-color: var(--primary);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.pagination-button:disabled {
|
|
63
|
+
opacity: 0.4;
|
|
64
|
+
cursor: not-allowed;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.pagination-button.active {
|
|
68
|
+
background-color: var(--primary);
|
|
69
|
+
color: var(--primary-btn-text);
|
|
70
|
+
border-color: var(--primary);
|
|
71
|
+
font-weight: 600;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.pagination-ellipsis {
|
|
75
|
+
padding: 8px 4px;
|
|
76
|
+
color: var(--text);
|
|
77
|
+
opacity: 0.6;
|
|
78
|
+
}
|
|
79
|
+
`, t;
|
|
80
|
+
}
|
|
81
|
+
changePage(t) {
|
|
82
|
+
t < 1 || t > this.totalPages || t === this.currentPage || (this.currentPage = t, this.setAttribute("current-page", String(t)), this.dispatchEvent(new CustomEvent("page-change", {
|
|
83
|
+
detail: { page: t },
|
|
84
|
+
bubbles: !0,
|
|
85
|
+
composed: !0
|
|
86
|
+
})), this.render());
|
|
87
|
+
}
|
|
88
|
+
render() {
|
|
89
|
+
this.container.innerHTML = "";
|
|
90
|
+
const t = document.createElement("button");
|
|
91
|
+
t.className = "pagination-button", t.textContent = "←", t.disabled = this.currentPage === 1, t.onclick = () => this.changePage(this.currentPage - 1), this.container.appendChild(t), this.getPageButtons().forEach((r) => {
|
|
92
|
+
if (r === "ellipsis") {
|
|
93
|
+
const i = document.createElement("span");
|
|
94
|
+
i.className = "pagination-ellipsis", i.textContent = "...", this.container.appendChild(i);
|
|
95
|
+
} else {
|
|
96
|
+
const i = document.createElement("button");
|
|
97
|
+
i.className = "pagination-button", r === this.currentPage && i.classList.add("active"), i.textContent = String(r), i.onclick = () => this.changePage(r), this.container.appendChild(i);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const a = document.createElement("button");
|
|
101
|
+
a.className = "pagination-button", a.textContent = "→", a.disabled = this.currentPage === this.totalPages, a.onclick = () => this.changePage(this.currentPage + 1), this.container.appendChild(a);
|
|
102
|
+
}
|
|
103
|
+
getPageButtons() {
|
|
104
|
+
const e = [];
|
|
105
|
+
for (let a = 1; a <= this.totalPages; a++)
|
|
106
|
+
a === 1 || a === this.totalPages || a >= this.currentPage - 2 && a <= this.currentPage + 2 ? e.push(a) : e[e.length - 1] !== "ellipsis" && e.push("ellipsis");
|
|
107
|
+
return e;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
customElements.get("marz-pagination") || customElements.define("marz-pagination", c);
|
|
111
|
+
class d extends HTMLElement {
|
|
112
|
+
constructor() {
|
|
113
|
+
super(), this.attachShadow({ mode: "open" }), this.container = document.createElement("article"), this.container.className = "article-card", this.shadowRoot.appendChild(this.getStyles()), this.shadowRoot.appendChild(this.container), this.render();
|
|
114
|
+
}
|
|
115
|
+
static get observedAttributes() {
|
|
116
|
+
return ["title", "excerpt", "author", "date", "tags", "href"];
|
|
117
|
+
}
|
|
118
|
+
connectedCallback() {
|
|
119
|
+
this.render();
|
|
120
|
+
}
|
|
121
|
+
attributeChangedCallback() {
|
|
122
|
+
this.render();
|
|
123
|
+
}
|
|
124
|
+
getStyles() {
|
|
125
|
+
const t = document.createElement("style");
|
|
126
|
+
return t.textContent = `
|
|
127
|
+
.article-card {
|
|
128
|
+
display: flex;
|
|
129
|
+
flex-direction: column;
|
|
130
|
+
padding: 24px;
|
|
131
|
+
border: 1px solid var(--bg-element-2);
|
|
132
|
+
border-radius: 8px;
|
|
133
|
+
background-color: var(--bg);
|
|
134
|
+
transition: all 0.2s ease;
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
font-family: 'Inter', sans-serif;
|
|
137
|
+
text-decoration: none;
|
|
138
|
+
color: inherit;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.article-card:hover {
|
|
142
|
+
border-color: var(--primary);
|
|
143
|
+
background-color: var(--bg-element);
|
|
144
|
+
transform: translateY(-2px);
|
|
145
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.article-title {
|
|
149
|
+
font-size: 24px;
|
|
150
|
+
font-weight: 700;
|
|
151
|
+
color: var(--heading);
|
|
152
|
+
margin: 0 0 12px 0;
|
|
153
|
+
line-height: 1.3;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.article-excerpt {
|
|
157
|
+
font-size: 16px;
|
|
158
|
+
color: var(--text);
|
|
159
|
+
margin: 0 0 16px 0;
|
|
160
|
+
line-height: 1.6;
|
|
161
|
+
opacity: 0.9;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.article-meta {
|
|
165
|
+
display: flex;
|
|
166
|
+
flex-wrap: wrap;
|
|
167
|
+
gap: 16px;
|
|
168
|
+
align-items: center;
|
|
169
|
+
font-size: 14px;
|
|
170
|
+
color: var(--text);
|
|
171
|
+
opacity: 0.7;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.article-author {
|
|
175
|
+
font-weight: 600;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.article-date {
|
|
179
|
+
font-weight: 400;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.article-tags {
|
|
183
|
+
display: flex;
|
|
184
|
+
flex-wrap: wrap;
|
|
185
|
+
gap: 8px;
|
|
186
|
+
margin-left: auto;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.article-tag {
|
|
190
|
+
padding: 4px 12px;
|
|
191
|
+
background-color: var(--bg-element-2);
|
|
192
|
+
border-radius: 12px;
|
|
193
|
+
font-size: 12px;
|
|
194
|
+
font-weight: 500;
|
|
195
|
+
color: var(--text);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
@media only screen and (max-width: 48em) {
|
|
199
|
+
.article-card {
|
|
200
|
+
padding: 16px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.article-title {
|
|
204
|
+
font-size: 20px;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.article-excerpt {
|
|
208
|
+
font-size: 14px;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.article-meta {
|
|
212
|
+
flex-direction: column;
|
|
213
|
+
align-items: flex-start;
|
|
214
|
+
gap: 8px;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.article-tags {
|
|
218
|
+
margin-left: 0;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
`, t;
|
|
222
|
+
}
|
|
223
|
+
render() {
|
|
224
|
+
var l;
|
|
225
|
+
const t = this.getAttribute("title") || "Untitled", e = this.getAttribute("excerpt") || "", a = this.getAttribute("author") || "", r = this.getAttribute("date") || "", i = ((l = this.getAttribute("tags")) == null ? void 0 : l.split(",").map((o) => o.trim()).filter((o) => o)) || [], n = this.getAttribute("href") || "#";
|
|
226
|
+
this.container.innerHTML = `
|
|
227
|
+
<h3 class="article-title">${this.escapeHtml(t)}</h3>
|
|
228
|
+
${e ? `<p class="article-excerpt">${this.escapeHtml(e)}</p>` : ""}
|
|
229
|
+
<div class="article-meta">
|
|
230
|
+
${a ? `<span class="article-author">${this.escapeHtml(a)}</span>` : ""}
|
|
231
|
+
${r ? `<span class="article-date">${this.formatDate(r)}</span>` : ""}
|
|
232
|
+
${i.length > 0 ? `
|
|
233
|
+
<div class="article-tags">
|
|
234
|
+
${i.map((o) => `<span class="article-tag">${this.escapeHtml(o)}</span>`).join("")}
|
|
235
|
+
</div>
|
|
236
|
+
` : ""}
|
|
237
|
+
</div>
|
|
238
|
+
`, this.container.onclick = () => {
|
|
239
|
+
n && n !== "#" && (window.location.href = n);
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
formatDate(t) {
|
|
243
|
+
try {
|
|
244
|
+
return new Date(t).toLocaleDateString("en-US", {
|
|
245
|
+
year: "numeric",
|
|
246
|
+
month: "long",
|
|
247
|
+
day: "numeric"
|
|
248
|
+
});
|
|
249
|
+
} catch {
|
|
250
|
+
return t;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
escapeHtml(t) {
|
|
254
|
+
const e = document.createElement("div");
|
|
255
|
+
return e.textContent = t, e.innerHTML;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
customElements.get("marz-article-card") || customElements.define("marz-article-card", d);
|
|
259
|
+
class p extends HTMLElement {
|
|
260
|
+
constructor() {
|
|
261
|
+
super(), this.showPreview = !1, this.attachShadow({ mode: "open" }), this.container = document.createElement("div"), this.container.className = "markdown-editor-container", this.toolbar = this.createToolbar(), this.textarea = this.createTextarea(), this.preview = this.createPreview(), this.shadowRoot.appendChild(this.getStyles()), this.shadowRoot.appendChild(this.container), this.container.appendChild(this.toolbar), this.container.appendChild(this.textarea), this.container.appendChild(this.preview), this.setupEventListeners();
|
|
262
|
+
}
|
|
263
|
+
static get observedAttributes() {
|
|
264
|
+
return ["value", "placeholder", "show-preview"];
|
|
265
|
+
}
|
|
266
|
+
connectedCallback() {
|
|
267
|
+
const t = this.getAttribute("value") || "", e = this.getAttribute("placeholder") || "Write your markdown here...";
|
|
268
|
+
this.showPreview = this.getAttribute("show-preview") === "true", this.textarea.value = t, this.textarea.placeholder = e, this.updatePreview(), this.togglePreview();
|
|
269
|
+
}
|
|
270
|
+
attributeChangedCallback(t, e, a) {
|
|
271
|
+
if (e !== a)
|
|
272
|
+
switch (t) {
|
|
273
|
+
case "value":
|
|
274
|
+
this.textarea.value !== a && (this.textarea.value = a || "", this.updatePreview());
|
|
275
|
+
break;
|
|
276
|
+
case "placeholder":
|
|
277
|
+
this.textarea.placeholder = a || "Write your markdown here...";
|
|
278
|
+
break;
|
|
279
|
+
case "show-preview":
|
|
280
|
+
this.showPreview = a === "true", this.togglePreview();
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
getStyles() {
|
|
285
|
+
const t = document.createElement("style");
|
|
286
|
+
return t.textContent = `
|
|
287
|
+
.markdown-editor-container {
|
|
288
|
+
display: flex;
|
|
289
|
+
flex-direction: column;
|
|
290
|
+
border: 1px solid var(--bg-element-2);
|
|
291
|
+
border-radius: 8px;
|
|
292
|
+
background-color: var(--bg);
|
|
293
|
+
font-family: 'Inter', sans-serif;
|
|
294
|
+
overflow: hidden;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.markdown-toolbar {
|
|
298
|
+
display: flex;
|
|
299
|
+
flex-wrap: wrap;
|
|
300
|
+
gap: 4px;
|
|
301
|
+
padding: 8px;
|
|
302
|
+
background-color: var(--bg-element);
|
|
303
|
+
border-bottom: 1px solid var(--bg-element-2);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.toolbar-button {
|
|
307
|
+
min-width: 36px;
|
|
308
|
+
height: 36px;
|
|
309
|
+
padding: 8px;
|
|
310
|
+
border: none;
|
|
311
|
+
background-color: transparent;
|
|
312
|
+
color: var(--text);
|
|
313
|
+
cursor: pointer;
|
|
314
|
+
border-radius: 4px;
|
|
315
|
+
font-size: 14px;
|
|
316
|
+
font-weight: 500;
|
|
317
|
+
transition: all 0.2s ease;
|
|
318
|
+
display: flex;
|
|
319
|
+
align-items: center;
|
|
320
|
+
justify-content: center;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.toolbar-button:hover {
|
|
324
|
+
background-color: var(--bg-element-2);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.toolbar-button:active {
|
|
328
|
+
background-color: var(--bg-element);
|
|
329
|
+
transform: scale(0.95);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.toolbar-separator {
|
|
333
|
+
width: 1px;
|
|
334
|
+
height: 24px;
|
|
335
|
+
background-color: var(--bg-element-2);
|
|
336
|
+
margin: 6px 4px;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.markdown-textarea {
|
|
340
|
+
width: 100%;
|
|
341
|
+
min-height: 400px;
|
|
342
|
+
padding: 16px;
|
|
343
|
+
border: none;
|
|
344
|
+
background-color: var(--bg);
|
|
345
|
+
color: var(--text);
|
|
346
|
+
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
|
|
347
|
+
font-size: 14px;
|
|
348
|
+
line-height: 1.6;
|
|
349
|
+
resize: vertical;
|
|
350
|
+
outline: none;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.markdown-textarea::placeholder {
|
|
354
|
+
color: var(--text);
|
|
355
|
+
opacity: 0.5;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.markdown-preview {
|
|
359
|
+
display: none;
|
|
360
|
+
padding: 16px;
|
|
361
|
+
border-top: 1px solid var(--bg-element-2);
|
|
362
|
+
background-color: var(--bg);
|
|
363
|
+
color: var(--text);
|
|
364
|
+
overflow-y: auto;
|
|
365
|
+
max-height: 400px;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.markdown-preview.visible {
|
|
369
|
+
display: block;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
.markdown-preview h1,
|
|
373
|
+
.markdown-preview h2,
|
|
374
|
+
.markdown-preview h3,
|
|
375
|
+
.markdown-preview h4,
|
|
376
|
+
.markdown-preview h5,
|
|
377
|
+
.markdown-preview h6 {
|
|
378
|
+
color: var(--heading);
|
|
379
|
+
margin-top: 24px;
|
|
380
|
+
margin-bottom: 12px;
|
|
381
|
+
font-weight: 700;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.markdown-preview h1 { font-size: 32px; }
|
|
385
|
+
.markdown-preview h2 { font-size: 28px; }
|
|
386
|
+
.markdown-preview h3 { font-size: 24px; }
|
|
387
|
+
.markdown-preview h4 { font-size: 20px; }
|
|
388
|
+
.markdown-preview h5 { font-size: 18px; }
|
|
389
|
+
.markdown-preview h6 { font-size: 16px; }
|
|
390
|
+
|
|
391
|
+
.markdown-preview p {
|
|
392
|
+
margin-bottom: 16px;
|
|
393
|
+
line-height: 1.6;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.markdown-preview ul,
|
|
397
|
+
.markdown-preview ol {
|
|
398
|
+
margin-bottom: 16px;
|
|
399
|
+
padding-left: 24px;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.markdown-preview li {
|
|
403
|
+
margin-bottom: 8px;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
.markdown-preview code {
|
|
407
|
+
padding: 2px 6px;
|
|
408
|
+
background-color: var(--bg-element-2);
|
|
409
|
+
border-radius: 4px;
|
|
410
|
+
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
|
|
411
|
+
font-size: 13px;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
.markdown-preview pre {
|
|
415
|
+
padding: 16px;
|
|
416
|
+
background-color: var(--bg-element-2);
|
|
417
|
+
border-radius: 8px;
|
|
418
|
+
overflow-x: auto;
|
|
419
|
+
margin-bottom: 16px;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
.markdown-preview pre code {
|
|
423
|
+
padding: 0;
|
|
424
|
+
background: none;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.markdown-preview blockquote {
|
|
428
|
+
margin: 16px 0;
|
|
429
|
+
padding-left: 16px;
|
|
430
|
+
border-left: 4px solid var(--primary);
|
|
431
|
+
color: var(--text);
|
|
432
|
+
opacity: 0.9;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
.markdown-preview a {
|
|
436
|
+
color: var(--link);
|
|
437
|
+
text-decoration: none;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
.markdown-preview a:hover {
|
|
441
|
+
text-decoration: underline;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
.markdown-preview img {
|
|
445
|
+
max-width: 100%;
|
|
446
|
+
height: auto;
|
|
447
|
+
border-radius: 8px;
|
|
448
|
+
margin: 16px 0;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.markdown-preview hr {
|
|
452
|
+
border: none;
|
|
453
|
+
border-top: 2px solid var(--bg-element-2);
|
|
454
|
+
margin: 24px 0;
|
|
455
|
+
}
|
|
456
|
+
`, t;
|
|
457
|
+
}
|
|
458
|
+
createToolbar() {
|
|
459
|
+
const t = document.createElement("div");
|
|
460
|
+
return t.className = "markdown-toolbar", [
|
|
461
|
+
{ label: "B", title: "Bold", action: () => this.wrapSelection("**", "**") },
|
|
462
|
+
{ label: "I", title: "Italic", action: () => this.wrapSelection("*", "*") },
|
|
463
|
+
{ label: "S", title: "Strikethrough", action: () => this.wrapSelection("~~", "~~") },
|
|
464
|
+
{ separator: !0 },
|
|
465
|
+
{ label: "H1", title: "Heading 1", action: () => this.insertAtLineStart("# ") },
|
|
466
|
+
{ label: "H2", title: "Heading 2", action: () => this.insertAtLineStart("## ") },
|
|
467
|
+
{ label: "H3", title: "Heading 3", action: () => this.insertAtLineStart("### ") },
|
|
468
|
+
{ separator: !0 },
|
|
469
|
+
{ label: "UL", title: "Unordered List", action: () => this.insertAtLineStart("- ") },
|
|
470
|
+
{ label: "OL", title: "Ordered List", action: () => this.insertAtLineStart("1. ") },
|
|
471
|
+
{ label: "Q", title: "Quote", action: () => this.insertAtLineStart("> ") },
|
|
472
|
+
{ separator: !0 },
|
|
473
|
+
{ label: "Link", title: "Insert Link", action: () => this.insertLink() },
|
|
474
|
+
{ label: "Code", title: "Code Block", action: () => this.insertCodeBlock() },
|
|
475
|
+
{ label: "HR", title: "Horizontal Rule", action: () => this.insertText(`
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
`) },
|
|
480
|
+
{ separator: !0 },
|
|
481
|
+
{ label: this.showPreview ? "👁️ Hide" : "👁️ Show", title: "Toggle Preview", action: () => this.togglePreviewMode() }
|
|
482
|
+
].forEach((a) => {
|
|
483
|
+
if (a.separator) {
|
|
484
|
+
const r = document.createElement("div");
|
|
485
|
+
r.className = "toolbar-separator", t.appendChild(r);
|
|
486
|
+
} else {
|
|
487
|
+
const r = document.createElement("button");
|
|
488
|
+
r.className = "toolbar-button", r.textContent = a.label, r.title = a.title, r.onclick = a.action, t.appendChild(r);
|
|
489
|
+
}
|
|
490
|
+
}), t;
|
|
491
|
+
}
|
|
492
|
+
createTextarea() {
|
|
493
|
+
const t = document.createElement("textarea");
|
|
494
|
+
return t.className = "markdown-textarea", t;
|
|
495
|
+
}
|
|
496
|
+
createPreview() {
|
|
497
|
+
const t = document.createElement("div");
|
|
498
|
+
return t.className = "markdown-preview", t;
|
|
499
|
+
}
|
|
500
|
+
setupEventListeners() {
|
|
501
|
+
this.textarea.addEventListener("input", () => {
|
|
502
|
+
this.setAttribute("value", this.textarea.value), this.updatePreview(), this.dispatchChangeEvent();
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
wrapSelection(t, e) {
|
|
506
|
+
const a = this.textarea.selectionStart, r = this.textarea.selectionEnd, i = this.textarea.value.substring(a, r), n = t + i + e;
|
|
507
|
+
this.textarea.setRangeText(n, a, r, "end"), this.textarea.focus(), this.updateValue();
|
|
508
|
+
}
|
|
509
|
+
insertAtLineStart(t) {
|
|
510
|
+
const e = this.textarea.selectionStart, r = this.textarea.value.lastIndexOf(`
|
|
511
|
+
`, e - 1) + 1;
|
|
512
|
+
this.textarea.setRangeText(t, r, r, "end"), this.textarea.focus(), this.updateValue();
|
|
513
|
+
}
|
|
514
|
+
insertText(t) {
|
|
515
|
+
const e = this.textarea.selectionStart;
|
|
516
|
+
this.textarea.setRangeText(t, e, e, "end"), this.textarea.focus(), this.updateValue();
|
|
517
|
+
}
|
|
518
|
+
insertLink() {
|
|
519
|
+
const t = prompt("Enter URL:");
|
|
520
|
+
if (t) {
|
|
521
|
+
const e = this.textarea.selectionStart, a = this.textarea.selectionEnd, n = `[${this.textarea.value.substring(e, a) || "link text"}](${t})`;
|
|
522
|
+
this.textarea.setRangeText(n, e, a, "end"), this.textarea.focus(), this.updateValue();
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
insertCodeBlock() {
|
|
526
|
+
const e = "```" + (prompt("Programming language (optional):") || "") + "\n\n```";
|
|
527
|
+
this.insertText(e);
|
|
528
|
+
}
|
|
529
|
+
togglePreviewMode() {
|
|
530
|
+
this.showPreview = !this.showPreview, this.setAttribute("show-preview", String(this.showPreview)), this.togglePreview(), this.updateToolbar();
|
|
531
|
+
}
|
|
532
|
+
togglePreview() {
|
|
533
|
+
this.showPreview ? this.preview.classList.add("visible") : this.preview.classList.remove("visible");
|
|
534
|
+
}
|
|
535
|
+
updateToolbar() {
|
|
536
|
+
const t = Array.from(this.toolbar.querySelectorAll(".toolbar-button")), e = t[t.length - 1];
|
|
537
|
+
e && (e.textContent = this.showPreview ? "👁️ Hide" : "👁️ Show");
|
|
538
|
+
}
|
|
539
|
+
updateValue() {
|
|
540
|
+
this.setAttribute("value", this.textarea.value), this.updatePreview(), this.dispatchChangeEvent();
|
|
541
|
+
}
|
|
542
|
+
updatePreview() {
|
|
543
|
+
this.showPreview && (this.preview.innerHTML = this.renderMarkdown(this.textarea.value));
|
|
544
|
+
}
|
|
545
|
+
renderMarkdown(t) {
|
|
546
|
+
let e = t;
|
|
547
|
+
return e = e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"), e = e.replace(/^### (.*$)/gim, "<h3>$1</h3>"), e = e.replace(/^## (.*$)/gim, "<h2>$1</h2>"), e = e.replace(/^# (.*$)/gim, "<h1>$1</h1>"), e = e.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>"), e = e.replace(/\*(.*?)\*/g, "<em>$1</em>"), e = e.replace(/~~(.*?)~~/g, "<del>$1</del>"), e = e.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>'), e = e.replace(/```(\w+)?\n([\s\S]*?)```/g, "<pre><code>$2</code></pre>"), e = e.replace(/`([^`]+)`/g, "<code>$1</code>"), e = e.replace(/^\- (.*$)/gim, "<li>$1</li>"), e = e.replace(/(<li>.*<\/li>)/s, "<ul>$1</ul>"), e = e.replace(/^> (.*$)/gim, "<blockquote>$1</blockquote>"), e = e.replace(/^---$/gim, "<hr>"), e = e.replace(/\n\n/g, "</p><p>"), e = "<p>" + e + "</p>", e;
|
|
548
|
+
}
|
|
549
|
+
dispatchChangeEvent() {
|
|
550
|
+
this.dispatchEvent(new CustomEvent("change", {
|
|
551
|
+
detail: { value: this.textarea.value },
|
|
552
|
+
bubbles: !0,
|
|
553
|
+
composed: !0
|
|
554
|
+
}));
|
|
555
|
+
}
|
|
556
|
+
// Public method to get the markdown value
|
|
557
|
+
getValue() {
|
|
558
|
+
return this.textarea.value;
|
|
559
|
+
}
|
|
560
|
+
// Public method to set the markdown value
|
|
561
|
+
setValue(t) {
|
|
562
|
+
this.textarea.value = t, this.setAttribute("value", t), this.updatePreview();
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
customElements.get("marz-markdown-editor") || customElements.define("marz-markdown-editor", p);
|
|
566
|
+
const g = "1.0.0";
|
|
5
567
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
568
|
+
d as MarzArticleCard,
|
|
569
|
+
x as MarzButton,
|
|
570
|
+
w as MarzInput,
|
|
571
|
+
p as MarzMarkdownEditor,
|
|
572
|
+
c as MarzPagination,
|
|
573
|
+
f as MarzSidepanel,
|
|
574
|
+
g as VERSION
|
|
10
575
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marz-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Marz UI - Framework-agnostic UI components and design system",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
13
|
},
|
|
14
|
-
"./styles": "./dist/styles/
|
|
14
|
+
"./styles": "./dist/styles/style.css",
|
|
15
|
+
"./dist/styles/style.css": "./dist/styles/style.css",
|
|
15
16
|
"./styles/tokens": "./dist/styles/tokens.css",
|
|
16
17
|
"./styles/components": "./dist/styles/components.css",
|
|
17
18
|
"./button": {
|
|
@@ -30,6 +31,11 @@
|
|
|
30
31
|
"files": [
|
|
31
32
|
"dist"
|
|
32
33
|
],
|
|
34
|
+
"sideEffects": [
|
|
35
|
+
"*.css",
|
|
36
|
+
"dist/**/*.css",
|
|
37
|
+
"dist/index.js"
|
|
38
|
+
],
|
|
33
39
|
"scripts": {
|
|
34
40
|
"dev": "vite",
|
|
35
41
|
"build": "tsc && vite build",
|