Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@editora/checklist

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@editora/checklist - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+1
dist/index.cjs.js
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const N="__editoraCommandEditorRoot",w=e=>{if(!e)return null;const t=e.querySelector('[contenteditable="true"]');return t instanceof HTMLElement?t:null},A=()=>{if(typeof window>"u")return null;const e=window[N];if(!(e instanceof HTMLElement))return null;window[N]=null;const t=e.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")||(e.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")?e:null);if(t){const r=w(t);if(r)return r;if(t.getAttribute("contenteditable")==="true")return t}if(e.getAttribute("contenteditable")==="true")return e;const n=e.closest('[contenteditable="true"]');return n instanceof HTMLElement?n:null},_=()=>{const e=A();if(e&&document.contains(e))return e;const t=window.getSelection();if(t&&t.rangeCount>0){let r=t.getRangeAt(0).startContainer;for(;r&&r!==document.body;){if(r.nodeType===Node.ELEMENT_NODE){const o=r;if(o.getAttribute("contenteditable")==="true")return o}r=r.parentNode}}const n=document.activeElement;if(n){if(n.getAttribute("contenteditable")==="true")return n;const r=n.closest('[contenteditable="true"]');if(r)return r}return document.querySelector('[contenteditable="true"]')},S=e=>e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null,H=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const n=t.getRangeAt(0);return e.contains(n.commonAncestorContainer)?n:null},y=e=>{e.dispatchEvent(new Event("input",{bubbles:!0}))},M=(e,t)=>{if(t===e.innerHTML)return;const n=window.execEditorCommand||window.executeEditorCommand;if(typeof n=="function")try{n("recordDomTransaction",e,t,e.innerHTML)}catch{}},k=(e,t)=>{if(!e.isConnected){t.focus({preventScroll:!0});return}const n=window.getSelection();if(!n)return;const r=document.createRange();r.selectNodeContents(e),r.collapse(!1),n.removeAllRanges();try{n.addRange(r)}catch{t.focus({preventScroll:!0});return}t.focus({preventScroll:!0})},v=e=>{let t=e.querySelector(":scope > p");if(!t){t=document.createElement("p");const n=[];e.childNodes.forEach(r=>{r.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(r.tagName)||n.push(r)}),n.forEach(r=>t.appendChild(r)),e.insertBefore(t,e.firstChild)}return t.innerHTML.trim()||(t.innerHTML="<br>"),t},C=e=>{const t=document.createElement("li");t.setAttribute("data-type","checklist-item"),t.setAttribute("data-checked","false");const n=document.createElement("p");return n.innerHTML=e.trim()||"<br>",t.appendChild(n),t},T=e=>Array.from(e.children).filter(t=>t instanceof HTMLLIElement),I=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","LI"]),b=e=>I.has(e.tagName)&&e.getAttribute("contenteditable")!=="true",R=(e,t)=>{const n=[],r=new Set,o=i=>{!i||r.has(i)||t.contains(i)&&b(i)&&(i.closest("ul, ol")||(r.add(i),n.push(i)))},u=i=>{let a=i;for(;a&&a!==document.body;){if(a.nodeType===Node.ELEMENT_NODE){const h=a;if(b(h))return h;if(h.getAttribute("contenteditable")==="true")break}a=a.parentNode}return null};if(e.collapsed)return o(u(e.startContainer)),n;const d=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:i=>{const a=i;if(!b(a)||a.closest("ul, ol"))return NodeFilter.FILTER_SKIP;if(typeof e.intersectsNode=="function")return e.intersectsNode(a)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP;const h=document.createRange();return h.selectNodeContents(a),e.compareBoundaryPoints(Range.END_TO_START,h)>0&&e.compareBoundaryPoints(Range.START_TO_END,h)<0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let l=d.nextNode();for(;l;)o(l),l=d.nextNode();if(n.length===0&&o(u(e.commonAncestorContainer)),n.length<=1)return n;const m=n.filter(i=>!n.some(a=>a!==i&&i.contains(a)));return m.length>0?m:n},O=e=>{const t=[],n=document.createElement("div"),r=()=>{const o=n.innerHTML.trim();if(!o)return;const u=document.createElement("p");u.innerHTML=o,t.push(u),n.innerHTML=""};if(e.childNodes.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(o.tagName)){r();return}if(o.nodeType===Node.ELEMENT_NODE&&o.tagName==="P"){r();const u=o.innerHTML.trim(),d=document.createElement("p");d.innerHTML=u||"<br>",t.push(d);return}o.nodeType===Node.TEXT_NODE&&!(o.textContent||"").trim()||n.appendChild(o.cloneNode(!0))}),r(),t.length===0){const o=document.createElement("p");o.innerHTML="<br>",t.push(o)}return t},P=()=>({name:"checklist",init:()=>{if(typeof document>"u"||typeof window>"u"||window.__checklistPluginClickInitialized)return;window.__checklistPluginClickInitialized=!0;const e=t=>{const r=t.target.closest('li[data-type="checklist-item"]');if(!r)return;const o=r.getBoundingClientRect();if(!(t.clientX-o.left<32))return;t.preventDefault(),t.stopPropagation();const l=r.closest("[contenteditable], .rte-content, .editora-content");if(l?.getAttribute("contenteditable")==="false"||!!l?.closest('[data-readonly="true"], .editora-editor[readonly], editora-editor[readonly]'))return;const i=l?.innerHTML||"",a=r.getAttribute("data-checked")==="true";r.setAttribute("data-checked",(!a).toString()),l&&(M(l,i),y(l))};document.addEventListener("click",e)},nodes:{checklist:{content:"checklistItem+",group:"block",parseDOM:[{tag:'ul[data-type="checklist"]'}],toDOM:()=>["ul",{"data-type":"checklist"},0]},checklistItem:{content:"paragraph",attrs:{checked:{default:!1}},parseDOM:[{tag:'li[data-type="checklist-item"]',getAttrs:e=>({checked:e.getAttribute("data-checked")==="true"})}],toDOM:e=>["li",{"data-type":"checklist-item","data-checked":e?.attrs?.checked?"true":"false"},0]}},toolbar:[{label:"Checklist",command:"toggleChecklist",icon:'<svg width="24px" height="24px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.75 4.48h-.71L2 3.43l.71-.7.69.68L4.81 2l.71.71-1.77 1.77zM6.99 3h8v1h-8V3zm0 3h8v1h-8V6zm8 3h-8v1h8V9zm-8 3h8v1h-8v-1zM3.04 7.48h.71l1.77-1.77-.71-.7L3.4 6.42l-.69-.69-.71.71 1.04 1.04zm.71 3.01h-.71L2 9.45l.71-.71.69.69 1.41-1.42.71.71-1.77 1.77zm-.71 3.01h.71l1.77-1.77-.71-.71-1.41 1.42-.69-.69-.71.7 1.04 1.05z"></path></g></svg>',shortcut:"Mod-Shift-9"}],commands:{toggleChecklist:()=>{try{const e=_();if(!e)return!1;const t=e.innerHTML,n=()=>(M(e,t),y(e),!0),r=H(e);if(!r)return!1;const o=S(r.startContainer);if(!o)return!1;const u=o.closest('ul[data-type="checklist"]');if(u&&e.contains(u)){const c=T(u);if(c.length===0)return!1;const p=document.createDocumentFragment();let s=null;return c.forEach((f,g)=>{const E=O(f);E.forEach(L=>{p.appendChild(L),!s&&(f.contains(r.startContainer)||g===0)&&(s=L)}),!s&&g===0&&E[0]&&(s=E[0])}),u.replaceWith(p),s&&k(s,e),n()}const d=o.closest("ul, ol");if(d&&e.contains(d)){let c;if(d.tagName.toLowerCase()==="ul")c=d;else{for(c=document.createElement("ul");d.firstChild;)c.appendChild(d.firstChild);d.replaceWith(c)}c.setAttribute("data-type","checklist");let p=T(c);p.length===0&&(c.appendChild(C("")),p=T(c));let s=null;p.forEach(g=>{g.setAttribute("data-type","checklist-item"),g.hasAttribute("data-checked")||g.setAttribute("data-checked","false");const E=v(g);g.contains(r.startContainer)&&(s=E)});const f=c.querySelector(':scope > li[data-type="checklist-item"] > p');return k(s||f||c,e),n()}const l=R(r,e);if(l.length>1){const c=document.createElement("ul");c.setAttribute("data-type","checklist"),l.forEach(f=>{c.appendChild(C(f.innerHTML))}),l[0].replaceWith(c),l.slice(1).forEach(f=>{f.isConnected&&f.remove()});const s=c.querySelector(':scope > li[data-type="checklist-item"] > p');return s&&k(s,e),n()}const m=l[0]||o.closest("p, h1, h2, h3, h4, h5, h6, blockquote, pre");if(m&&m!==e){const c=document.createElement("ul");c.setAttribute("data-type","checklist");const p=C(m.innerHTML);c.appendChild(p),m.replaceWith(c);const s=p.querySelector(":scope > p");return s&&k(s,e),n()}const i=document.createElement("ul");i.setAttribute("data-type","checklist");const a=C("");i.appendChild(a),r.deleteContents(),r.insertNode(i);const h=a.querySelector(":scope > p");return h&&k(h,e),n()}catch(e){return console.error("Failed to toggle checklist:",e),!1}}},keymap:{"Mod-Shift-9":"toggleChecklist"}});exports.ChecklistPlugin=P;
const N = "__editoraCommandEditorRoot", w = (t) => {
if (!t) return null;
const e = t.querySelector('[contenteditable="true"]');
return e instanceof HTMLElement ? e : null;
}, A = () => {
if (typeof window > "u") return null;
const t = window[N];
if (!(t instanceof HTMLElement)) return null;
window[N] = null;
const e = t.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || (t.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") ? t : null);
if (e) {
const r = w(e);
if (r) return r;
if (e.getAttribute("contenteditable") === "true") return e;
}
if (t.getAttribute("contenteditable") === "true")
return t;
const n = t.closest('[contenteditable="true"]');
return n instanceof HTMLElement ? n : null;
}, _ = () => {
const t = A();
if (t && document.contains(t))
return t;
const e = window.getSelection();
if (e && e.rangeCount > 0) {
let r = e.getRangeAt(0).startContainer;
for (; r && r !== document.body; ) {
if (r.nodeType === Node.ELEMENT_NODE) {
const o = r;
if (o.getAttribute("contenteditable") === "true")
return o;
}
r = r.parentNode;
}
}
const n = document.activeElement;
if (n) {
if (n.getAttribute("contenteditable") === "true")
return n;
const r = n.closest('[contenteditable="true"]');
if (r) return r;
}
return document.querySelector('[contenteditable="true"]');
}, H = (t) => t ? t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement : null, S = (t) => {
const e = window.getSelection();
if (!e || e.rangeCount === 0) return null;
const n = e.getRangeAt(0);
return t.contains(n.commonAncestorContainer) ? n : null;
}, y = (t) => {
t.dispatchEvent(new Event("input", { bubbles: !0 }));
}, M = (t, e) => {
if (e === t.innerHTML) return;
const n = window.execEditorCommand || window.executeEditorCommand;
if (typeof n == "function")
try {
n("recordDomTransaction", t, e, t.innerHTML);
} catch {
}
}, k = (t, e) => {
if (!t.isConnected) {
e.focus({ preventScroll: !0 });
return;
}
const n = window.getSelection();
if (!n) return;
const r = document.createRange();
r.selectNodeContents(t), r.collapse(!1), n.removeAllRanges();
try {
n.addRange(r);
} catch {
e.focus({ preventScroll: !0 });
return;
}
e.focus({ preventScroll: !0 });
}, I = (t) => {
let e = t.querySelector(":scope > p");
if (!e) {
e = document.createElement("p");
const n = [];
t.childNodes.forEach((r) => {
r.nodeType === Node.ELEMENT_NODE && ["UL", "OL"].includes(r.tagName) || n.push(r);
}), n.forEach((r) => e.appendChild(r)), t.insertBefore(e, t.firstChild);
}
return e.innerHTML.trim() || (e.innerHTML = "<br>"), e;
}, C = (t) => {
const e = document.createElement("li");
e.setAttribute("data-type", "checklist-item"), e.setAttribute("data-checked", "false");
const n = document.createElement("p");
return n.innerHTML = t.trim() || "<br>", e.appendChild(n), e;
}, T = (t) => Array.from(t.children).filter(
(e) => e instanceof HTMLLIElement
), R = /* @__PURE__ */ new Set([
"P",
"DIV",
"H1",
"H2",
"H3",
"H4",
"H5",
"H6",
"BLOCKQUOTE",
"PRE",
"LI"
]), b = (t) => R.has(t.tagName) && t.getAttribute("contenteditable") !== "true", v = (t, e) => {
const n = [], r = /* @__PURE__ */ new Set(), o = (i) => {
!i || r.has(i) || e.contains(i) && b(i) && (i.closest("ul, ol") || (r.add(i), n.push(i)));
}, u = (i) => {
let a = i;
for (; a && a !== document.body; ) {
if (a.nodeType === Node.ELEMENT_NODE) {
const h = a;
if (b(h)) return h;
if (h.getAttribute("contenteditable") === "true") break;
}
a = a.parentNode;
}
return null;
};
if (t.collapsed)
return o(u(t.startContainer)), n;
const d = document.createTreeWalker(
e,
NodeFilter.SHOW_ELEMENT,
{
acceptNode: (i) => {
const a = i;
if (!b(a) || a.closest("ul, ol")) return NodeFilter.FILTER_SKIP;
if (typeof t.intersectsNode == "function")
return t.intersectsNode(a) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
const h = document.createRange();
return h.selectNodeContents(a), t.compareBoundaryPoints(Range.END_TO_START, h) > 0 && t.compareBoundaryPoints(Range.START_TO_END, h) < 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
}
}
);
let l = d.nextNode();
for (; l; )
o(l), l = d.nextNode();
if (n.length === 0 && o(u(t.commonAncestorContainer)), n.length <= 1)
return n;
const m = n.filter((i) => !n.some((a) => a !== i && i.contains(a)));
return m.length > 0 ? m : n;
}, O = (t) => {
const e = [], n = document.createElement("div"), r = () => {
const o = n.innerHTML.trim();
if (!o) return;
const u = document.createElement("p");
u.innerHTML = o, e.push(u), n.innerHTML = "";
};
if (t.childNodes.forEach((o) => {
if (o.nodeType === Node.ELEMENT_NODE && ["UL", "OL"].includes(o.tagName)) {
r();
return;
}
if (o.nodeType === Node.ELEMENT_NODE && o.tagName === "P") {
r();
const u = o.innerHTML.trim(), d = document.createElement("p");
d.innerHTML = u || "<br>", e.push(d);
return;
}
o.nodeType === Node.TEXT_NODE && !(o.textContent || "").trim() || n.appendChild(o.cloneNode(!0));
}), r(), e.length === 0) {
const o = document.createElement("p");
o.innerHTML = "<br>", e.push(o);
}
return e;
}, D = () => ({
name: "checklist",
// Initialize click handler when plugin is loaded
init: () => {
if (typeof document > "u" || typeof window > "u" || window.__checklistPluginClickInitialized) return;
window.__checklistPluginClickInitialized = !0;
const t = (e) => {
const r = e.target.closest('li[data-type="checklist-item"]');
if (!r) return;
const o = r.getBoundingClientRect();
if (!(e.clientX - o.left < 32)) return;
e.preventDefault(), e.stopPropagation();
const l = r.closest("[contenteditable], .rte-content, .editora-content");
if (l?.getAttribute("contenteditable") === "false" || !!l?.closest('[data-readonly="true"], .editora-editor[readonly], editora-editor[readonly]')) return;
const i = l?.innerHTML || "", a = r.getAttribute("data-checked") === "true";
r.setAttribute("data-checked", (!a).toString()), l && (M(l, i), y(l));
};
document.addEventListener("click", t);
},
// Schema definition for checklist nodes
nodes: {
checklist: {
content: "checklistItem+",
group: "block",
parseDOM: [{ tag: 'ul[data-type="checklist"]' }],
toDOM: () => ["ul", { "data-type": "checklist" }, 0]
},
checklistItem: {
content: "paragraph",
attrs: {
checked: { default: !1 }
},
parseDOM: [
{
tag: 'li[data-type="checklist-item"]',
getAttrs: (t) => ({
checked: t.getAttribute("data-checked") === "true"
})
}
],
toDOM: (t) => [
"li",
{
"data-type": "checklist-item",
"data-checked": t?.attrs?.checked ? "true" : "false"
},
0
]
}
},
toolbar: [
{
label: "Checklist",
command: "toggleChecklist",
icon: '<svg width="24px" height="24px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.75 4.48h-.71L2 3.43l.71-.7.69.68L4.81 2l.71.71-1.77 1.77zM6.99 3h8v1h-8V3zm0 3h8v1h-8V6zm8 3h-8v1h8V9zm-8 3h8v1h-8v-1zM3.04 7.48h.71l1.77-1.77-.71-.7L3.4 6.42l-.69-.69-.71.71 1.04 1.04zm.71 3.01h-.71L2 9.45l.71-.71.69.69 1.41-1.42.71.71-1.77 1.77zm-.71 3.01h.71l1.77-1.77-.71-.71-1.41 1.42-.69-.69-.71.7 1.04 1.05z"></path></g></svg>',
shortcut: "Mod-Shift-9"
}
],
commands: {
toggleChecklist: () => {
try {
const t = _();
if (!t) return !1;
const e = t.innerHTML, n = () => (M(t, e), y(t), !0), r = S(t);
if (!r) return !1;
const o = H(r.startContainer);
if (!o) return !1;
const u = o.closest('ul[data-type="checklist"]');
if (u && t.contains(u)) {
const c = T(u);
if (c.length === 0) return !1;
const p = document.createDocumentFragment();
let s = null;
return c.forEach((f, g) => {
const E = O(f);
E.forEach((L) => {
p.appendChild(L), !s && (f.contains(r.startContainer) || g === 0) && (s = L);
}), !s && g === 0 && E[0] && (s = E[0]);
}), u.replaceWith(p), s && k(s, t), n();
}
const d = o.closest("ul, ol");
if (d && t.contains(d)) {
let c;
if (d.tagName.toLowerCase() === "ul")
c = d;
else {
for (c = document.createElement("ul"); d.firstChild; )
c.appendChild(d.firstChild);
d.replaceWith(c);
}
c.setAttribute("data-type", "checklist");
let p = T(c);
p.length === 0 && (c.appendChild(C("")), p = T(c));
let s = null;
p.forEach((g) => {
g.setAttribute("data-type", "checklist-item"), g.hasAttribute("data-checked") || g.setAttribute("data-checked", "false");
const E = I(g);
g.contains(r.startContainer) && (s = E);
});
const f = c.querySelector(':scope > li[data-type="checklist-item"] > p');
return k(s || f || c, t), n();
}
const l = v(r, t);
if (l.length > 1) {
const c = document.createElement("ul");
c.setAttribute("data-type", "checklist"), l.forEach((f) => {
c.appendChild(C(f.innerHTML));
}), l[0].replaceWith(c), l.slice(1).forEach((f) => {
f.isConnected && f.remove();
});
const s = c.querySelector(':scope > li[data-type="checklist-item"] > p');
return s && k(s, t), n();
}
const m = l[0] || o.closest("p, h1, h2, h3, h4, h5, h6, blockquote, pre");
if (m && m !== t) {
const c = document.createElement("ul");
c.setAttribute("data-type", "checklist");
const p = C(m.innerHTML);
c.appendChild(p), m.replaceWith(c);
const s = p.querySelector(":scope > p");
return s && k(s, t), n();
}
const i = document.createElement("ul");
i.setAttribute("data-type", "checklist");
const a = C("");
i.appendChild(a), r.deleteContents(), r.insertNode(i);
const h = a.querySelector(":scope > p");
return h && k(h, t), n();
} catch (t) {
return console.error("Failed to toggle checklist:", t), !1;
}
}
},
keymap: {
"Mod-Shift-9": "toggleChecklist"
}
});
export {
D as ChecklistPlugin
};
+4
-3
{
"name": "@editora/checklist",
"version": "1.0.1",
"version": "1.0.2",
"description": "Checklist plugin for Rich Text Editor",

@@ -15,3 +15,4 @@ "authors": [

"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
"require": "./dist/index.cjs.js",
"default": "./dist/index.esm.js"
}

@@ -24,3 +25,3 @@ },

"dependencies": {
"@editora/core": "^1.0.5"
"@editora/core": "^1.0.6"
},

@@ -27,0 +28,0 @@ "devDependencies": {

const b = () => {
const e = window.getSelection();
if (e && e.rangeCount > 0) {
let n = e.getRangeAt(0).startContainer;
for (; n && n !== document.body; ) {
if (n.nodeType === Node.ELEMENT_NODE) {
const r = n;
if (r.getAttribute("contenteditable") === "true")
return r;
}
n = n.parentNode;
}
}
const t = document.activeElement;
if (t) {
if (t.getAttribute("contenteditable") === "true")
return t;
const n = t.closest('[contenteditable="true"]');
if (n) return n;
}
return document.querySelector('[contenteditable="true"]');
}, L = (e) => e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null, y = (e) => {
const t = window.getSelection();
if (!t || t.rangeCount === 0) return null;
const n = t.getRangeAt(0);
return e.contains(n.commonAncestorContainer) ? n : null;
}, p = (e) => {
e.dispatchEvent(new Event("input", { bubbles: !0 }));
}, m = (e, t) => {
if (!e.isConnected) {
t.focus({ preventScroll: !0 });
return;
}
const n = window.getSelection();
if (!n) return;
const r = document.createRange();
r.selectNodeContents(e), r.collapse(!1), n.removeAllRanges();
try {
n.addRange(r);
} catch {
t.focus({ preventScroll: !0 });
return;
}
t.focus({ preventScroll: !0 });
}, N = (e) => {
let t = e.querySelector(":scope > p");
if (!t) {
t = document.createElement("p");
const n = [];
e.childNodes.forEach((r) => {
r.nodeType === Node.ELEMENT_NODE && ["UL", "OL"].includes(r.tagName) || n.push(r);
}), n.forEach((r) => t.appendChild(r)), e.insertBefore(t, e.firstChild);
}
return t.innerHTML.trim() || (t.innerHTML = "<br>"), t;
}, k = (e) => {
const t = document.createElement("li");
t.setAttribute("data-type", "checklist-item"), t.setAttribute("data-checked", "false");
const n = document.createElement("p");
return n.innerHTML = e.trim() || "<br>", t.appendChild(n), t;
}, E = (e) => Array.from(e.children).filter(
(t) => t instanceof HTMLLIElement
), M = (e) => {
const t = [], n = document.createElement("div"), r = () => {
const c = n.innerHTML.trim();
if (!c) return;
const o = document.createElement("p");
o.innerHTML = c, t.push(o), n.innerHTML = "";
};
if (e.childNodes.forEach((c) => {
if (c.nodeType === Node.ELEMENT_NODE && ["UL", "OL"].includes(c.tagName)) {
r();
return;
}
if (c.nodeType === Node.ELEMENT_NODE && c.tagName === "P") {
r();
const o = c.innerHTML.trim(), d = document.createElement("p");
d.innerHTML = o || "<br>", t.push(d);
return;
}
c.nodeType === Node.TEXT_NODE && !(c.textContent || "").trim() || n.appendChild(c.cloneNode(!0));
}), r(), t.length === 0) {
const c = document.createElement("p");
c.innerHTML = "<br>", t.push(c);
}
return t;
}, T = () => ({
name: "checklist",
// Initialize click handler when plugin is loaded
init: () => {
if (typeof document > "u" || typeof window > "u" || window.__checklistPluginClickInitialized) return;
window.__checklistPluginClickInitialized = !0;
const e = (t) => {
const r = t.target.closest('li[data-type="checklist-item"]');
if (!r) return;
const c = r.getBoundingClientRect();
if (!(t.clientX - c.left < 32)) return;
t.preventDefault(), t.stopPropagation();
const f = r.getAttribute("data-checked") === "true";
r.setAttribute("data-checked", (!f).toString());
const u = r.closest('[contenteditable="true"], .rte-content, .editora-content');
u && p(u);
};
document.addEventListener("click", e);
},
// Schema definition for checklist nodes
nodes: {
checklist: {
content: "checklistItem+",
group: "block",
parseDOM: [{ tag: 'ul[data-type="checklist"]' }],
toDOM: () => ["ul", { "data-type": "checklist" }, 0]
},
checklistItem: {
content: "paragraph",
attrs: {
checked: { default: !1 }
},
parseDOM: [
{
tag: 'li[data-type="checklist-item"]',
getAttrs: (e) => ({
checked: e.getAttribute("data-checked") === "true"
})
}
],
toDOM: (e) => [
"li",
{
"data-type": "checklist-item",
"data-checked": e?.attrs?.checked ? "true" : "false"
},
0
]
}
},
toolbar: [
{
label: "Checklist",
command: "toggleChecklist",
icon: '<svg width="24px" height="24px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.75 4.48h-.71L2 3.43l.71-.7.69.68L4.81 2l.71.71-1.77 1.77zM6.99 3h8v1h-8V3zm0 3h8v1h-8V6zm8 3h-8v1h8V9zm-8 3h8v1h-8v-1zM3.04 7.48h.71l1.77-1.77-.71-.7L3.4 6.42l-.69-.69-.71.71 1.04 1.04zm.71 3.01h-.71L2 9.45l.71-.71.69.69 1.41-1.42.71.71-1.77 1.77zm-.71 3.01h.71l1.77-1.77-.71-.71-1.41 1.42-.69-.69-.71.7 1.04 1.05z"></path></g></svg>',
shortcut: "Mod-Shift-9"
}
],
commands: {
toggleChecklist: () => {
try {
const e = b();
if (!e) return !1;
const t = y(e);
if (!t) return !1;
const n = L(t.startContainer);
if (!n) return !1;
const r = n.closest('ul[data-type="checklist"]');
if (r && e.contains(r)) {
const i = E(r);
if (i.length === 0) return !1;
const l = document.createDocumentFragment();
let a = null;
return i.forEach((g, s) => {
const h = M(g);
h.forEach((C) => {
l.appendChild(C), !a && (g.contains(t.startContainer) || s === 0) && (a = C);
}), !a && s === 0 && h[0] && (a = h[0]);
}), r.replaceWith(l), a && m(a, e), p(e), !0;
}
const c = n.closest("ul, ol");
if (c && e.contains(c)) {
let i;
if (c.tagName.toLowerCase() === "ul")
i = c;
else {
for (i = document.createElement("ul"); c.firstChild; )
i.appendChild(c.firstChild);
c.replaceWith(i);
}
i.setAttribute("data-type", "checklist");
let l = E(i);
l.length === 0 && (i.appendChild(k("")), l = E(i));
let a = null;
l.forEach((s) => {
s.setAttribute("data-type", "checklist-item"), s.hasAttribute("data-checked") || s.setAttribute("data-checked", "false");
const h = N(s);
s.contains(t.startContainer) && (a = h);
});
const g = i.querySelector(':scope > li[data-type="checklist-item"] > p');
return m(a || g || i, e), p(e), !0;
}
const o = n.closest("p, h1, h2, h3, h4, h5, h6, blockquote, pre");
if (o && o !== e) {
const i = document.createElement("ul");
i.setAttribute("data-type", "checklist");
const l = k(o.innerHTML);
i.appendChild(l), o.replaceWith(i);
const a = l.querySelector(":scope > p");
return a && m(a, e), p(e), !0;
}
const d = document.createElement("ul");
d.setAttribute("data-type", "checklist");
const f = k("");
d.appendChild(f), t.deleteContents(), t.insertNode(d);
const u = f.querySelector(":scope > p");
return u && m(u, e), p(e), !0;
} catch (e) {
return console.error("Failed to toggle checklist:", e), !1;
}
}
},
keymap: {
"Mod-Shift-9": "toggleChecklist"
}
});
export {
T as ChecklistPlugin
};
(function(u,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(u=typeof globalThis<"u"?globalThis:u||self,h(u.ChecklistPlugin={}))})(this,(function(u){"use strict";const h=()=>{const e=window.getSelection();if(e&&e.rangeCount>0){let n=e.getRangeAt(0).startContainer;for(;n&&n!==document.body;){if(n.nodeType===Node.ELEMENT_NODE){const r=n;if(r.getAttribute("contenteditable")==="true")return r}n=n.parentNode}}const t=document.activeElement;if(t){if(t.getAttribute("contenteditable")==="true")return t;const n=t.closest('[contenteditable="true"]');if(n)return n}return document.querySelector('[contenteditable="true"]')},L=e=>e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null,T=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const n=t.getRangeAt(0);return e.contains(n.commonAncestorContainer)?n:null},p=e=>{e.dispatchEvent(new Event("input",{bubbles:!0}))},m=(e,t)=>{if(!e.isConnected){t.focus({preventScroll:!0});return}const n=window.getSelection();if(!n)return;const r=document.createRange();r.selectNodeContents(e),r.collapse(!1),n.removeAllRanges();try{n.addRange(r)}catch{t.focus({preventScroll:!0});return}t.focus({preventScroll:!0})},M=e=>{let t=e.querySelector(":scope > p");if(!t){t=document.createElement("p");const n=[];e.childNodes.forEach(r=>{r.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(r.tagName)||n.push(r)}),n.forEach(r=>t.appendChild(r)),e.insertBefore(t,e.firstChild)}return t.innerHTML.trim()||(t.innerHTML="<br>"),t},C=e=>{const t=document.createElement("li");t.setAttribute("data-type","checklist-item"),t.setAttribute("data-checked","false");const n=document.createElement("p");return n.innerHTML=e.trim()||"<br>",t.appendChild(n),t},b=e=>Array.from(e.children).filter(t=>t instanceof HTMLLIElement),N=e=>{const t=[],n=document.createElement("div"),r=()=>{const c=n.innerHTML.trim();if(!c)return;const a=document.createElement("p");a.innerHTML=c,t.push(a),n.innerHTML=""};if(e.childNodes.forEach(c=>{if(c.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(c.tagName)){r();return}if(c.nodeType===Node.ELEMENT_NODE&&c.tagName==="P"){r();const a=c.innerHTML.trim(),d=document.createElement("p");d.innerHTML=a||"<br>",t.push(d);return}c.nodeType===Node.TEXT_NODE&&!(c.textContent||"").trim()||n.appendChild(c.cloneNode(!0))}),r(),t.length===0){const c=document.createElement("p");c.innerHTML="<br>",t.push(c)}return t},v=()=>({name:"checklist",init:()=>{if(typeof document>"u"||typeof window>"u"||window.__checklistPluginClickInitialized)return;window.__checklistPluginClickInitialized=!0;const e=t=>{const r=t.target.closest('li[data-type="checklist-item"]');if(!r)return;const c=r.getBoundingClientRect();if(!(t.clientX-c.left<32))return;t.preventDefault(),t.stopPropagation();const k=r.getAttribute("data-checked")==="true";r.setAttribute("data-checked",(!k).toString());const f=r.closest('[contenteditable="true"], .rte-content, .editora-content');f&&p(f)};document.addEventListener("click",e)},nodes:{checklist:{content:"checklistItem+",group:"block",parseDOM:[{tag:'ul[data-type="checklist"]'}],toDOM:()=>["ul",{"data-type":"checklist"},0]},checklistItem:{content:"paragraph",attrs:{checked:{default:!1}},parseDOM:[{tag:'li[data-type="checklist-item"]',getAttrs:e=>({checked:e.getAttribute("data-checked")==="true"})}],toDOM:e=>["li",{"data-type":"checklist-item","data-checked":e?.attrs?.checked?"true":"false"},0]}},toolbar:[{label:"Checklist",command:"toggleChecklist",icon:'<svg width="24px" height="24px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.75 4.48h-.71L2 3.43l.71-.7.69.68L4.81 2l.71.71-1.77 1.77zM6.99 3h8v1h-8V3zm0 3h8v1h-8V6zm8 3h-8v1h8V9zm-8 3h8v1h-8v-1zM3.04 7.48h.71l1.77-1.77-.71-.7L3.4 6.42l-.69-.69-.71.71 1.04 1.04zm.71 3.01h-.71L2 9.45l.71-.71.69.69 1.41-1.42.71.71-1.77 1.77zm-.71 3.01h.71l1.77-1.77-.71-.71-1.41 1.42-.69-.69-.71.7 1.04 1.05z"></path></g></svg>',shortcut:"Mod-Shift-9"}],commands:{toggleChecklist:()=>{try{const e=h();if(!e)return!1;const t=T(e);if(!t)return!1;const n=L(t.startContainer);if(!n)return!1;const r=n.closest('ul[data-type="checklist"]');if(r&&e.contains(r)){const i=b(r);if(i.length===0)return!1;const l=document.createDocumentFragment();let o=null;return i.forEach((E,s)=>{const g=N(E);g.forEach(y=>{l.appendChild(y),!o&&(E.contains(t.startContainer)||s===0)&&(o=y)}),!o&&s===0&&g[0]&&(o=g[0])}),r.replaceWith(l),o&&m(o,e),p(e),!0}const c=n.closest("ul, ol");if(c&&e.contains(c)){let i;if(c.tagName.toLowerCase()==="ul")i=c;else{for(i=document.createElement("ul");c.firstChild;)i.appendChild(c.firstChild);c.replaceWith(i)}i.setAttribute("data-type","checklist");let l=b(i);l.length===0&&(i.appendChild(C("")),l=b(i));let o=null;l.forEach(s=>{s.setAttribute("data-type","checklist-item"),s.hasAttribute("data-checked")||s.setAttribute("data-checked","false");const g=M(s);s.contains(t.startContainer)&&(o=g)});const E=i.querySelector(':scope > li[data-type="checklist-item"] > p');return m(o||E||i,e),p(e),!0}const a=n.closest("p, h1, h2, h3, h4, h5, h6, blockquote, pre");if(a&&a!==e){const i=document.createElement("ul");i.setAttribute("data-type","checklist");const l=C(a.innerHTML);i.appendChild(l),a.replaceWith(i);const o=l.querySelector(":scope > p");return o&&m(o,e),p(e),!0}const d=document.createElement("ul");d.setAttribute("data-type","checklist");const k=C("");d.appendChild(k),t.deleteContents(),t.insertNode(d);const f=k.querySelector(":scope > p");return f&&m(f,e),p(e),!0}catch(e){return console.error("Failed to toggle checklist:",e),!1}}},keymap:{"Mod-Shift-9":"toggleChecklist"}});u.ChecklistPlugin=v,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));