@powerduck/md-editor 0.8.1 → 0.8.3
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/README.md +15 -0
- package/dist/Editor.d.ts +3 -4
- package/dist/index.cjs +15 -12
- package/dist/index.mjs +51 -18
- package/dist/plugins/tasklist.d.ts +6 -2
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -80,7 +80,14 @@ class Zt {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
show() {
|
|
83
|
-
|
|
83
|
+
if (this.trigger) {
|
|
84
|
+
if (!this.dropdown) {
|
|
85
|
+
this.dropdown = document.createElement("div"), this.dropdown.className = "md-editor-mention-dropdown", this.dropdown.setAttribute("role", "listbox");
|
|
86
|
+
const e = this.view.dom.closest(".md-editor-root"), t = (e == null ? void 0 : e.getAttribute("data-theme")) ?? "light";
|
|
87
|
+
this.dropdown.setAttribute("data-theme", t), document.body.appendChild(this.dropdown);
|
|
88
|
+
}
|
|
89
|
+
this.renderDropdown(), this.positionDropdown();
|
|
90
|
+
}
|
|
84
91
|
}
|
|
85
92
|
renderDropdown() {
|
|
86
93
|
this.dropdown && (this.dropdown.innerHTML = "", this.items.forEach((e, t) => {
|
|
@@ -203,7 +210,14 @@ class Xt {
|
|
|
203
210
|
}
|
|
204
211
|
}
|
|
205
212
|
show() {
|
|
206
|
-
|
|
213
|
+
if (this.trigger) {
|
|
214
|
+
if (!this.dropdown) {
|
|
215
|
+
this.dropdown = document.createElement("div"), this.dropdown.className = "md-editor-doclink-dropdown", this.dropdown.setAttribute("role", "listbox");
|
|
216
|
+
const e = this.view.dom.closest(".md-editor-root"), t = (e == null ? void 0 : e.getAttribute("data-theme")) ?? "light";
|
|
217
|
+
this.dropdown.setAttribute("data-theme", t), document.body.appendChild(this.dropdown);
|
|
218
|
+
}
|
|
219
|
+
this.renderDropdown(), this.positionDropdown();
|
|
220
|
+
}
|
|
207
221
|
}
|
|
208
222
|
renderDropdown() {
|
|
209
223
|
this.dropdown && (this.dropdown.innerHTML = "", this.items.forEach((e, t) => {
|
|
@@ -490,18 +504,21 @@ class jt {
|
|
|
490
504
|
}
|
|
491
505
|
/** Insert @ at cursor and trigger the mention dropdown. */
|
|
492
506
|
insertMention() {
|
|
493
|
-
this.
|
|
507
|
+
this.mention || console.warn(
|
|
508
|
+
"[md-editor] Mention dropdown is disabled. Pass `mention: { onMentionSearch }` in the editor options to enable it."
|
|
509
|
+
), this.insertAtCursor("@");
|
|
494
510
|
}
|
|
495
511
|
/** Insert trigger char at cursor and trigger the doc-link search dropdown. */
|
|
496
512
|
insertDocLink() {
|
|
497
|
-
this.
|
|
513
|
+
this.docLink || console.warn(
|
|
514
|
+
"[md-editor] Document link dropdown is disabled. Pass `docLink: { onDocSearch }` in the editor options to enable it."
|
|
515
|
+
), this.insertAtCursor("/");
|
|
498
516
|
}
|
|
499
517
|
/**
|
|
500
518
|
* Toggle task list (checkbox) markers on the current line or selected
|
|
501
|
-
* lines.
|
|
502
|
-
* If
|
|
503
|
-
*
|
|
504
|
-
* vice versa when all selected lines are task items.
|
|
519
|
+
* lines. Project convention: `- [ ]` = checked (green), `- [x]` = unchecked.
|
|
520
|
+
* If all selected lines are task items: all-checked → uncheck all;
|
|
521
|
+
* otherwise → check all. Plain lines or `- ` lists get `- [ ] ` prepended.
|
|
505
522
|
*/
|
|
506
523
|
toggleTaskList() {
|
|
507
524
|
const { from: e, to: t } = this.view.state.selection.main, i = this.view.state.doc.lineAt(e), r = this.view.state.doc.lineAt(t), a = [];
|
|
@@ -510,8 +527,8 @@ class jt {
|
|
|
510
527
|
const s = a.every(
|
|
511
528
|
(d) => /^- \[[ xX]\]\s/.test(d) || /^- \[[ xX]\]$/.test(d)
|
|
512
529
|
), o = a.every(
|
|
513
|
-
(d) => /^- \[
|
|
514
|
-
), l = a.map((d) => s ? o ? d.replace(/^- \[
|
|
530
|
+
(d) => /^- \[ \]\s/.test(d) || /^- \[ \]$/.test(d)
|
|
531
|
+
), l = a.map((d) => s ? o ? d.replace(/^- \[ \](\s?)/, "- [x]$1") : d.replace(/^- \[[xX]\](\s?)/, "- [ ]$1") : /^-(\s|$)/.test(d) ? d.replace(/^-(\s?)/, "- [ ]$1") : `- [ ] ${d}`).join(`
|
|
515
532
|
`);
|
|
516
533
|
this.view.dispatch({
|
|
517
534
|
changes: { from: i.from, to: r.to, insert: l },
|
|
@@ -7885,7 +7902,7 @@ function $i(n) {
|
|
|
7885
7902
|
w && w.type === "text" && (w.content = w.content.replace(/^\[[ xX]\]\s/, ""));
|
|
7886
7903
|
}
|
|
7887
7904
|
o.attrSet("class", "task-list-item");
|
|
7888
|
-
const y = `<input type="checkbox" disabled${
|
|
7905
|
+
const y = `<input type="checkbox" disabled${g ? " checked" : ""} /> `;
|
|
7889
7906
|
return (e ? e(t, i, r, a, s) : s.renderToken(t, i, r)) + y;
|
|
7890
7907
|
}
|
|
7891
7908
|
}
|
|
@@ -7923,7 +7940,7 @@ class Ui {
|
|
|
7923
7940
|
for (const t of e) {
|
|
7924
7941
|
const i = document.createElement("button");
|
|
7925
7942
|
if (i.type = "button", i.className = "md-editor-toolbar-btn", t.toggle && i.classList.add("is-toggle"), t.active && i.classList.add("is-active"), i.title = t.title, i.setAttribute("aria-label", t.title), i.setAttribute("data-action", t.name), i.innerHTML = t.icon, i.addEventListener("mousedown", (r) => {
|
|
7926
|
-
r.preventDefault(), t.handler(i);
|
|
7943
|
+
r.preventDefault(), r.stopPropagation(), t.handler(i);
|
|
7927
7944
|
}), this.buttons.set(t.name, i), this.el.appendChild(i), t.groupEnd) {
|
|
7928
7945
|
const r = document.createElement("span");
|
|
7929
7946
|
r.className = "md-editor-toolbar-sep", this.el.appendChild(r);
|
|
@@ -8137,7 +8154,8 @@ const L = (n) => `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xm
|
|
|
8137
8154
|
class ie {
|
|
8138
8155
|
constructor(e, t) {
|
|
8139
8156
|
this.inputs = /* @__PURE__ */ new Map(), this.destroyed = !1, this.anchor = e, this.config = t, this.el = document.createElement("div"), this.el.className = "md-editor-popup", this.el.setAttribute("role", "dialog"), this.el.setAttribute("aria-label", t.title), t.theme && this.el.setAttribute("data-theme", t.theme), this.build(), this.onOutsideClick = (i) => {
|
|
8140
|
-
|
|
8157
|
+
const r = i.target;
|
|
8158
|
+
!this.el.contains(r) && !this.anchor.contains(r) && this.hide();
|
|
8141
8159
|
}, this.onKeyDown = (i) => {
|
|
8142
8160
|
i.key === "Escape" && this.hide();
|
|
8143
8161
|
};
|
|
@@ -8516,12 +8534,27 @@ ${r}
|
|
|
8516
8534
|
onSubmit: () => {
|
|
8517
8535
|
}
|
|
8518
8536
|
}), i = t.el.querySelector(".md-editor-popup-body");
|
|
8519
|
-
|
|
8520
|
-
|
|
8521
|
-
|
|
8522
|
-
|
|
8537
|
+
if (i) {
|
|
8538
|
+
const s = [
|
|
8539
|
+
{ label: "Task list", hint: "- [ ] checked / - [x] unchecked" },
|
|
8540
|
+
{ label: "@mention", hint: "Type @ then pick a user from the dropdown" },
|
|
8541
|
+
{ label: "Document link", hint: "Type / then pick a document" },
|
|
8542
|
+
{ label: "Math formula", hint: "$E=mc^2$ inline / $$ block $$" },
|
|
8543
|
+
{ label: "Mindmap", hint: "```mindmap fenced block with # headings" },
|
|
8544
|
+
{ label: "Callout", hint: ":::warning Title ...content... :::" }
|
|
8545
|
+
];
|
|
8546
|
+
i.innerHTML = '<div class="md-editor-help-list">' + this.shortcuts.map(
|
|
8547
|
+
(o) => `<div class="md-editor-help-row">
|
|
8548
|
+
<span class="md-editor-help-desc">${o.description}</span>
|
|
8549
|
+
<span class="md-editor-help-keys">${Xi(o.key)}</span>
|
|
8550
|
+
</div>`
|
|
8551
|
+
).join("") + '</div><div class="md-editor-help-section-title">Syntax</div><div class="md-editor-help-list">' + s.map(
|
|
8552
|
+
(o) => `<div class="md-editor-help-row">
|
|
8553
|
+
<span class="md-editor-help-desc">${o.label}</span>
|
|
8554
|
+
<span class="md-editor-help-syntax">${o.hint}</span>
|
|
8523
8555
|
</div>`
|
|
8524
|
-
|
|
8556
|
+
).join("") + "</div>";
|
|
8557
|
+
}
|
|
8525
8558
|
const r = t.el.querySelector(".md-editor-popup-footer");
|
|
8526
8559
|
r && r.remove(), this.activePopup = t, this.activePopup.show();
|
|
8527
8560
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { MarkdownIt } from "markdown-it";
|
|
2
2
|
/**
|
|
3
3
|
* Lightweight task list (checkbox) support for markdown-it.
|
|
4
|
-
* Converts `- [ ]` and `- [x]` list items into checkboxes
|
|
5
|
-
*
|
|
4
|
+
* Converts `- [ ]` and `- [x]` list items into checkboxes.
|
|
5
|
+
* Semantics (per project convention):
|
|
6
|
+
* `- [ ]` → checked (green checkmark)
|
|
7
|
+
* `- [x]` → unchecked (empty box)
|
|
8
|
+
* This is the inverse of GitHub Flavored Markdown; the project treats an
|
|
9
|
+
* empty box as "selected/done" and a marked box as "not yet selected".
|
|
6
10
|
*/
|
|
7
11
|
export declare function useTaskList(md: MarkdownIt): void;
|