@editora/plugins 1.0.20 → 1.0.22
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 +259 -645
- package/dist/a11y-checker.cjs.js +1 -1
- package/dist/a11y-checker.esm.js +18 -18
- package/dist/anchor.cjs.js +6 -6
- package/dist/anchor.esm.js +57 -57
- package/dist/blockquote.cjs.js +1 -1
- package/dist/blockquote.esm.js +31 -31
- package/dist/capitalization.cjs.js +1 -1
- package/dist/capitalization.esm.js +25 -25
- package/dist/checklist.cjs.js +1 -1
- package/dist/checklist.esm.js +30 -30
- package/dist/collaboration.cjs.js +8 -8
- package/dist/collaboration.esm.js +1279 -1169
- package/dist/comments.cjs.js +1 -1
- package/dist/comments.esm.js +1 -1
- package/dist/direction.cjs.js +1 -1
- package/dist/direction.esm.js +26 -26
- package/dist/font-family.cjs.js +1 -1
- package/dist/font-family.esm.js +26 -26
- package/dist/preview.cjs.js +1 -1
- package/dist/preview.esm.js +3 -3
- package/dist/spell-check.cjs.js +2 -2
- package/dist/spell-check.esm.js +19 -19
- package/dist/template.cjs.js +5 -5
- package/dist/template.esm.js +23 -23
- package/package.json +6 -5
package/dist/blockquote.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const d = '.rte-content, .editora-content, [contenteditable="true"]',
|
|
1
|
+
const d = '.rte-content, .editora-content, [contenteditable="true"]', y = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", T = [
|
|
2
2
|
"p",
|
|
3
3
|
"div",
|
|
4
4
|
"h1",
|
|
@@ -13,10 +13,10 @@ const d = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data
|
|
|
13
13
|
"pre",
|
|
14
14
|
"table"
|
|
15
15
|
].join(",");
|
|
16
|
-
function
|
|
16
|
+
function p(e) {
|
|
17
17
|
return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function S(e) {
|
|
20
20
|
const t = e?.contentElement;
|
|
21
21
|
if (t instanceof HTMLElement) return t;
|
|
22
22
|
const n = e?.editorElement;
|
|
@@ -27,9 +27,9 @@ function y(e) {
|
|
|
27
27
|
}
|
|
28
28
|
const o = window.getSelection();
|
|
29
29
|
if (o && o.rangeCount > 0) {
|
|
30
|
-
const c =
|
|
30
|
+
const c = p(o.getRangeAt(0).startContainer), i = c?.closest(d);
|
|
31
31
|
if (i instanceof HTMLElement) return i;
|
|
32
|
-
const f = c?.closest(
|
|
32
|
+
const f = c?.closest(y)?.querySelector(d);
|
|
33
33
|
if (f instanceof HTMLElement) return f;
|
|
34
34
|
}
|
|
35
35
|
const s = document.activeElement?.closest(d);
|
|
@@ -42,7 +42,7 @@ function B(e) {
|
|
|
42
42
|
return !e.contains(n.startContainer) || !e.contains(n.endContainer) ? null : n;
|
|
43
43
|
}
|
|
44
44
|
function C(e, t) {
|
|
45
|
-
let n =
|
|
45
|
+
let n = p(t);
|
|
46
46
|
if (!n || n === e || !e.contains(n)) return null;
|
|
47
47
|
for (; n.parentElement && n.parentElement !== e; )
|
|
48
48
|
n = n.parentElement;
|
|
@@ -51,7 +51,7 @@ function C(e, t) {
|
|
|
51
51
|
const o = n.closest(T);
|
|
52
52
|
return o instanceof HTMLElement && o.parentElement === e ? o : n;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function L(e, t) {
|
|
55
55
|
if (typeof e.intersectsNode == "function")
|
|
56
56
|
try {
|
|
57
57
|
return e.intersectsNode(t);
|
|
@@ -61,53 +61,53 @@ function S(e, t) {
|
|
|
61
61
|
const n = document.createRange();
|
|
62
62
|
return n.selectNode(t), e.compareBoundaryPoints(Range.END_TO_START, n) < 0 && e.compareBoundaryPoints(Range.START_TO_END, n) > 0;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function v(e, t) {
|
|
65
65
|
const n = C(e, t.startContainer), o = C(e, t.endContainer);
|
|
66
66
|
if (!n) return [];
|
|
67
67
|
if (!o || n === o) return [n];
|
|
68
68
|
const s = Array.from(e.children).filter(
|
|
69
69
|
(c) => c instanceof HTMLElement
|
|
70
|
-
).filter((c) =>
|
|
70
|
+
).filter((c) => L(t, c));
|
|
71
71
|
return s.length > 0 ? s : [n];
|
|
72
72
|
}
|
|
73
73
|
function k(e, t) {
|
|
74
|
-
const o =
|
|
74
|
+
const o = p(t)?.closest("blockquote");
|
|
75
75
|
return o instanceof HTMLQuoteElement && e.contains(o) ? o : null;
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function b(e) {
|
|
78
78
|
return e.tagName !== "P" || e.attributes.length > 0 || (e.textContent || "").trim() !== "" ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, ul, ol");
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function M(e) {
|
|
81
81
|
Array.from(e.children).forEach((t) => {
|
|
82
|
-
|
|
82
|
+
b(t) && t.remove();
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
85
|
+
function E(e) {
|
|
86
|
+
M(e);
|
|
87
87
|
const t = e.parentNode;
|
|
88
88
|
if (!t) return;
|
|
89
89
|
Array.from(e.childNodes).forEach((o) => {
|
|
90
90
|
t.insertBefore(o, e);
|
|
91
91
|
}), t.removeChild(e);
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function w(e) {
|
|
94
94
|
return e.nodeType === Node.TEXT_NODE && (e.textContent || "").trim() === "";
|
|
95
95
|
}
|
|
96
96
|
function N(e) {
|
|
97
|
-
const t = Array.from(e.childNodes).filter((o) => !
|
|
97
|
+
const t = Array.from(e.childNodes).filter((o) => !w(o));
|
|
98
98
|
if (t.length !== 1) return null;
|
|
99
99
|
const n = t[0];
|
|
100
100
|
return n instanceof HTMLQuoteElement ? n : null;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function x(e) {
|
|
103
103
|
const t = document.createElement("blockquote");
|
|
104
|
-
return Array.from(e.childNodes).filter((o) => !
|
|
104
|
+
return Array.from(e.childNodes).filter((o) => !w(o)).forEach((o) => {
|
|
105
105
|
t.appendChild(o);
|
|
106
106
|
}), t.childNodes.length || (t.innerHTML = "<br>"), e.appendChild(t), t;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function q(e, t) {
|
|
109
109
|
const n = Array.from(e.querySelectorAll("li")).filter(
|
|
110
|
-
(r) => r instanceof HTMLLIElement &&
|
|
110
|
+
(r) => r instanceof HTMLLIElement && L(t, r)
|
|
111
111
|
), o = new Set(n);
|
|
112
112
|
return n.filter((r) => {
|
|
113
113
|
let s = r.parentElement?.closest("li");
|
|
@@ -124,10 +124,10 @@ function m(e) {
|
|
|
124
124
|
const n = document.createRange(), o = e instanceof HTMLElement && e.querySelector("p,li,h1,h2,h3,h4,h5,h6") || e;
|
|
125
125
|
n.selectNodeContents(o), n.collapse(!0), t.removeAllRanges(), t.addRange(n);
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function O(e) {
|
|
128
128
|
e.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function R(e, t, n) {
|
|
131
131
|
const o = window.execEditorCommand;
|
|
132
132
|
if (typeof o == "function") {
|
|
133
133
|
o("recordDomTransaction", e, t, n);
|
|
@@ -137,30 +137,30 @@ function O(e, t, n) {
|
|
|
137
137
|
typeof r == "function" && r("recordDomTransaction", { editor: e, beforeHTML: t, afterHTML: n });
|
|
138
138
|
}
|
|
139
139
|
function A(e) {
|
|
140
|
-
const t =
|
|
140
|
+
const t = S(e);
|
|
141
141
|
if (!t) return !1;
|
|
142
142
|
const n = B(t);
|
|
143
143
|
if (!n) return !1;
|
|
144
|
-
const o = t.innerHTML, r = k(t, n.startContainer), s = k(t, n.endContainer), c =
|
|
144
|
+
const o = t.innerHTML, r = k(t, n.startContainer), s = k(t, n.endContainer), c = q(t, n), i = v(t, n), h = i.length > 0 && i.every((l) => l.tagName === "BLOCKQUOTE");
|
|
145
145
|
if (r && r === s) {
|
|
146
146
|
const l = r.firstChild || r;
|
|
147
|
-
|
|
147
|
+
E(r), m(l);
|
|
148
148
|
} else if (c.length > 0) {
|
|
149
149
|
const l = c.map(N);
|
|
150
150
|
if (l.every(Boolean)) {
|
|
151
151
|
const u = l[0]?.firstChild || c[0];
|
|
152
152
|
l.forEach((a) => {
|
|
153
|
-
a &&
|
|
153
|
+
a && E(a);
|
|
154
154
|
}), m(u);
|
|
155
155
|
} else {
|
|
156
156
|
const u = c[0];
|
|
157
157
|
c.forEach((a) => {
|
|
158
|
-
N(a) ||
|
|
158
|
+
N(a) || x(a);
|
|
159
159
|
}), m(u);
|
|
160
160
|
}
|
|
161
161
|
} else if (h) {
|
|
162
162
|
const l = i[0].firstChild || i[0];
|
|
163
|
-
i.forEach(
|
|
163
|
+
i.forEach(E), m(l);
|
|
164
164
|
} else {
|
|
165
165
|
const l = i.filter((a) => a.tagName !== "BLOCKQUOTE");
|
|
166
166
|
if (l.length === 0) return !1;
|
|
@@ -170,7 +170,7 @@ function A(e) {
|
|
|
170
170
|
}), m(g);
|
|
171
171
|
}
|
|
172
172
|
const f = t.innerHTML;
|
|
173
|
-
return o === f ? !1 : (
|
|
173
|
+
return o === f ? !1 : (R(t, o, f), O(t), !0);
|
|
174
174
|
}
|
|
175
175
|
const H = () => ({
|
|
176
176
|
name: "blockquote",
|
|
@@ -188,7 +188,7 @@ const H = () => ({
|
|
|
188
188
|
{
|
|
189
189
|
label: "Quote",
|
|
190
190
|
command: "toggleBlockquote",
|
|
191
|
-
icon: '<svg fill="#000000" height="24px" width="24px" version="1.1"
|
|
191
|
+
icon: '<svg fill="#000000" height="24px" width="24px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" xml:space="preserve"><g stroke-width="0"></g><g stroke-linecap="round" stroke-linejoin="round"></g><g> <g> <path d="M13,11c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5s-2.2-5-5-5c-0.3,0-0.7,0-1,0.1 C9.3,11.8,11,11,13,11z"></path> <path d="M23,13c-0.3,0-0.7,0-1,0.1c1.3-1.3,3-2.1,5-2.1c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5 S25.8,13,23,13z"></path> </g> </g></svg>',
|
|
192
192
|
shortcut: "Mod-Shift-9"
|
|
193
193
|
}
|
|
194
194
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f='.rte-content, .editora-content, [contenteditable="true"]',w="[data-editora-editor], .rte-editor, .editora-editor, editora-editor",h=t=>t?t.nodeType===Node.ELEMENT_NODE?t:t.parentElement:null,v=t=>{const e=t?.contentElement;if(e instanceof HTMLElement)return e;const n=t?.editorElement;if(n instanceof HTMLElement){const s=n.querySelector(f);if(s instanceof HTMLElement)return s;if(n.getAttribute("contenteditable")==="true")return n}const r=window.__editoraCommandEditorRoot;if(r instanceof HTMLElement){const s=r.querySelector(f);if(s instanceof HTMLElement)return s;if(r.getAttribute("contenteditable")==="true")return r}const c=window.getSelection();if(c&&c.rangeCount>0){const s=h(c.getRangeAt(0).startContainer),i=s?.closest(f);if(i instanceof HTMLElement)return i;const a=s?.closest(w)?.querySelector(f);if(a instanceof HTMLElement)return a}const l=document.activeElement,u=l instanceof HTMLElement?l.closest(f):null;return u instanceof HTMLElement?u:document.querySelector(f)},
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f='.rte-content, .editora-content, [contenteditable="true"]',w="[data-editora-editor], .rte-editor, .editora-editor, editora-editor",h=t=>t?t.nodeType===Node.ELEMENT_NODE?t:t.parentElement:null,v=t=>{const e=t?.contentElement;if(e instanceof HTMLElement)return e;const n=t?.editorElement;if(n instanceof HTMLElement){const s=n.querySelector(f);if(s instanceof HTMLElement)return s;if(n.getAttribute("contenteditable")==="true")return n}const r=window.__editoraCommandEditorRoot;if(r instanceof HTMLElement){const s=r.querySelector(f);if(s instanceof HTMLElement)return s;if(r.getAttribute("contenteditable")==="true")return r}const c=window.getSelection();if(c&&c.rangeCount>0){const s=h(c.getRangeAt(0).startContainer),i=s?.closest(f);if(i instanceof HTMLElement)return i;const a=s?.closest(w)?.querySelector(f);if(a instanceof HTMLElement)return a}const l=document.activeElement,u=l instanceof HTMLElement?l.closest(f):null;return u instanceof HTMLElement?u:document.querySelector(f)},S=t=>{const e=window.getSelection();if(!e||e.rangeCount===0||e.isCollapsed)return null;const n=e.getRangeAt(0);return!t.contains(n.startContainer)||!t.contains(n.endContainer)?null:n},R=(t,e)=>{if(!e.data)return!1;if(typeof t.intersectsNode=="function")try{return t.intersectsNode(e)}catch{return!1}const n=document.createRange();return n.selectNodeContents(e),t.compareBoundaryPoints(Range.END_TO_START,n)<0&&t.compareBoundaryPoints(Range.START_TO_END,n)>0},L=(t,e)=>{const n=[],r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);let c=r.nextNode();for(;c;){const l=c;if(R(e,l)){const u=l===e.startContainer?e.startOffset:0,s=l===e.endContainer?e.endOffset:l.data.length;u<s&&n.push({node:l,start:u,end:s,text:l.data.slice(u,s)})}c=r.nextNode()}return n},x=t=>new RegExp("\\p{L}","u").test(t),y=t=>/[\p{M}'’-]/u.test(t),M=()=>{let t=!1;return e=>{let n="";return Array.from(e.text).forEach(r=>{if(x(r)){n+=t?r.toLocaleLowerCase():r.toLocaleUpperCase(),t=!0;return}n+=r,y(r)||(t=!1)}),n}},_=t=>{if(t.length===0)return;const e=t[0],n=t[t.length-1],r=window.getSelection();if(!r)return;const c=document.createRange();c.setStart(e.node,e.start),c.setEnd(n.node,n.end),r.removeAllRanges(),r.addRange(c)},H=(t,e,n)=>{if(e!==n){if(typeof window.execEditorCommand=="function"){window.execEditorCommand("recordDomTransaction",t,e,n);return}if(typeof window.executeEditorCommand=="function")try{window.executeEditorCommand("recordDomTransaction",{editor:t,beforeHTML:e,afterHTML:n})}catch{}}},N=()=>{const t=(i,o)=>{try{const a=v(o);if(!a)return!1;const m=S(a);if(!m)return!1;const p=L(a,m);if(p.length===0)return!1;const C=a.innerHTML;p.forEach((d,T)=>{const E=i(d,T);d.node.replaceData(d.start,d.end-d.start,E),d.end=d.start+E.length});const g=a.innerHTML;return C===g?!1:(H(a,C,g),a.dispatchEvent(new window.Event("input",{bubbles:!0})),_(p),!0)}catch(a){return console.error("Failed to transform capitalization:",a),!1}},e=(i,o)=>t(a=>a.text.toLocaleUpperCase(),o),n=(i,o)=>t(a=>a.text.toLocaleLowerCase(),o),r=(i,o)=>t(M(),o),c=(i,o)=>{if(!i)return!1;switch(i){case"uppercase":return e(void 0,o);case"lowercase":return n(void 0,o);case"titlecase":return r(void 0,o);default:return!1}},l=(i,o)=>typeof i=="string"?{value:i,context:o}:typeof o=="string"?{value:o}:{value:void 0,context:o},u=(i,o)=>{if(o&&typeof o=="object"&&!o.doc)return o},s=i=>(o,a)=>i(void 0,u(o,a));return{name:"capitalization",toolbar:[{label:"Capitalization",command:"setCapitalization",type:"inline-menu",options:[{label:"lowercase",value:"lowercase"},{label:"UPPERCASE",value:"uppercase"},{label:"Title Case",value:"titlecase"}],icon:'<svg fill="#000000" width="24" height="24" viewBox="0 0 32.00 32.00" xmlns="http://www.w3.org/2000/svg"><g stroke-width="0"></g><g stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.192"></g><g><title>letter--Aa</title><path d="M23,13H18v2h5v2H19a2,2,0,0,0-2,2v2a2,2,0,0,0,2,2h6V15A2,2,0,0,0,23,13Zm0,8H19V19h4Z"></path><path d="M13,9H9a2,2,0,0,0-2,2V23H9V18h4v5h2V11A2,2,0,0,0,13,9ZM9,16V11h4v5Z"></path><rect data-name="<Transparent Rectangle>" fill="none" width="32" height="32"></rect></g></svg>'}],commands:{setCapitalization:(i,o)=>{const{value:a,context:m}=l(i,o);return c(a,m)},toUpperCase:s(e),toLowerCase:s(n),toTitleCase:s(r)},keymap:{"Mod-Shift-u":"toUpperCase","Mod-Shift-k":"toLowerCase","Mod-Shift-t":"toTitleCase"}}};exports.CapitalizationPlugin=N;
|
|
@@ -20,14 +20,14 @@ const f = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data
|
|
|
20
20
|
const a = s?.closest(w)?.querySelector(f);
|
|
21
21
|
if (a instanceof HTMLElement) return a;
|
|
22
22
|
}
|
|
23
|
-
const l = document.activeElement,
|
|
24
|
-
return
|
|
23
|
+
const l = document.activeElement, u = l instanceof HTMLElement ? l.closest(f) : null;
|
|
24
|
+
return u instanceof HTMLElement ? u : document.querySelector(f);
|
|
25
25
|
}, R = (t) => {
|
|
26
26
|
const e = window.getSelection();
|
|
27
27
|
if (!e || e.rangeCount === 0 || e.isCollapsed) return null;
|
|
28
28
|
const n = e.getRangeAt(0);
|
|
29
29
|
return !t.contains(n.startContainer) || !t.contains(n.endContainer) ? null : n;
|
|
30
|
-
},
|
|
30
|
+
}, L = (t, e) => {
|
|
31
31
|
if (!e.data) return !1;
|
|
32
32
|
if (typeof t.intersectsNode == "function")
|
|
33
33
|
try {
|
|
@@ -37,24 +37,24 @@ const f = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data
|
|
|
37
37
|
}
|
|
38
38
|
const n = document.createRange();
|
|
39
39
|
return n.selectNodeContents(e), t.compareBoundaryPoints(Range.END_TO_START, n) < 0 && t.compareBoundaryPoints(Range.START_TO_END, n) > 0;
|
|
40
|
-
},
|
|
40
|
+
}, S = (t, e) => {
|
|
41
41
|
const n = [], r = document.createTreeWalker(t, NodeFilter.SHOW_TEXT);
|
|
42
42
|
let c = r.nextNode();
|
|
43
43
|
for (; c; ) {
|
|
44
44
|
const l = c;
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
47
|
-
|
|
45
|
+
if (L(e, l)) {
|
|
46
|
+
const u = l === e.startContainer ? e.startOffset : 0, s = l === e.endContainer ? e.endOffset : l.data.length;
|
|
47
|
+
u < s && n.push({
|
|
48
48
|
node: l,
|
|
49
|
-
start:
|
|
49
|
+
start: u,
|
|
50
50
|
end: s,
|
|
51
|
-
text: l.data.slice(
|
|
51
|
+
text: l.data.slice(u, s)
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
c = r.nextNode();
|
|
55
55
|
}
|
|
56
56
|
return n;
|
|
57
|
-
}, x = (t) => new RegExp("\\p{L}", "u").test(t),
|
|
57
|
+
}, x = (t) => new RegExp("\\p{L}", "u").test(t), y = (t) => /[\p{M}'’-]/u.test(t), M = () => {
|
|
58
58
|
let t = !1;
|
|
59
59
|
return (e) => {
|
|
60
60
|
let n = "";
|
|
@@ -63,16 +63,16 @@ const f = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data
|
|
|
63
63
|
n += t ? r.toLocaleLowerCase() : r.toLocaleUpperCase(), t = !0;
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
n += r,
|
|
66
|
+
n += r, y(r) || (t = !1);
|
|
67
67
|
}), n;
|
|
68
68
|
};
|
|
69
|
-
},
|
|
69
|
+
}, H = (t) => {
|
|
70
70
|
if (t.length === 0) return;
|
|
71
71
|
const e = t[0], n = t[t.length - 1], r = window.getSelection();
|
|
72
72
|
if (!r) return;
|
|
73
73
|
const c = document.createRange();
|
|
74
74
|
c.setStart(e.node, e.start), c.setEnd(n.node, n.end), r.removeAllRanges(), r.addRange(c);
|
|
75
|
-
},
|
|
75
|
+
}, N = (t, e, n) => {
|
|
76
76
|
if (e !== n) {
|
|
77
77
|
if (typeof window.execEditorCommand == "function") {
|
|
78
78
|
window.execEditorCommand("recordDomTransaction", t, e, n);
|
|
@@ -84,26 +84,26 @@ const f = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data
|
|
|
84
84
|
} catch {
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
},
|
|
87
|
+
}, _ = () => {
|
|
88
88
|
const t = (i, o) => {
|
|
89
89
|
try {
|
|
90
90
|
const a = v(o);
|
|
91
91
|
if (!a) return !1;
|
|
92
92
|
const m = R(a);
|
|
93
93
|
if (!m) return !1;
|
|
94
|
-
const p =
|
|
94
|
+
const p = S(a, m);
|
|
95
95
|
if (p.length === 0) return !1;
|
|
96
96
|
const C = a.innerHTML;
|
|
97
|
-
p.forEach((
|
|
98
|
-
const
|
|
99
|
-
|
|
97
|
+
p.forEach((d, T) => {
|
|
98
|
+
const g = i(d, T);
|
|
99
|
+
d.node.replaceData(d.start, d.end - d.start, g), d.end = d.start + g.length;
|
|
100
100
|
});
|
|
101
|
-
const
|
|
102
|
-
return C ===
|
|
101
|
+
const E = a.innerHTML;
|
|
102
|
+
return C === E ? !1 : (N(a, C, E), a.dispatchEvent(new window.Event("input", { bubbles: !0 })), H(p), !0);
|
|
103
103
|
} catch (a) {
|
|
104
104
|
return console.error("Failed to transform capitalization:", a), !1;
|
|
105
105
|
}
|
|
106
|
-
}, e = (i, o) => t((a) => a.text.toLocaleUpperCase(), o), n = (i, o) => t((a) => a.text.toLocaleLowerCase(), o), r = (i, o) => t(
|
|
106
|
+
}, e = (i, o) => t((a) => a.text.toLocaleUpperCase(), o), n = (i, o) => t((a) => a.text.toLocaleLowerCase(), o), r = (i, o) => t(M(), o), c = (i, o) => {
|
|
107
107
|
if (!i) return !1;
|
|
108
108
|
switch (i) {
|
|
109
109
|
case "uppercase":
|
|
@@ -118,10 +118,10 @@ const f = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data
|
|
|
118
118
|
}, l = (i, o) => typeof i == "string" ? { value: i, context: o } : typeof o == "string" ? { value: o } : {
|
|
119
119
|
value: void 0,
|
|
120
120
|
context: o
|
|
121
|
-
},
|
|
121
|
+
}, u = (i, o) => {
|
|
122
122
|
if (o && typeof o == "object" && !o.doc)
|
|
123
123
|
return o;
|
|
124
|
-
}, s = (i) => (o, a) => i(void 0,
|
|
124
|
+
}, s = (i) => (o, a) => i(void 0, u(o, a));
|
|
125
125
|
return {
|
|
126
126
|
name: "capitalization",
|
|
127
127
|
toolbar: [
|
|
@@ -139,7 +139,7 @@ const f = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data
|
|
|
139
139
|
// block - that style tag applies document-wide once inserted via
|
|
140
140
|
// raw innerHTML into light-DOM toolbar content, so it can collide
|
|
141
141
|
// with any other icon reusing the same auto-generated class name.
|
|
142
|
-
icon: '<svg fill="#000000" width="24" height="24" viewBox="0 0 32.00 32.00"
|
|
142
|
+
icon: '<svg fill="#000000" width="24" height="24" viewBox="0 0 32.00 32.00" xmlns="http://www.w3.org/2000/svg"><g stroke-width="0"></g><g stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.192"></g><g><title>letter--Aa</title><path d="M23,13H18v2h5v2H19a2,2,0,0,0-2,2v2a2,2,0,0,0,2,2h6V15A2,2,0,0,0,23,13Zm0,8H19V19h4Z"></path><path d="M13,9H9a2,2,0,0,0-2,2V23H9V18h4v5h2V11A2,2,0,0,0,13,9ZM9,16V11h4v5Z"></path><rect data-name="<Transparent Rectangle>" fill="none" width="32" height="32"></rect></g></svg>'
|
|
143
143
|
}
|
|
144
144
|
],
|
|
145
145
|
commands: {
|
|
@@ -159,5 +159,5 @@ const f = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data
|
|
|
159
159
|
};
|
|
160
160
|
};
|
|
161
161
|
export {
|
|
162
|
-
|
|
162
|
+
_ as CapitalizationPlugin
|
|
163
163
|
};
|
package/dist/checklist.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M="__editoraCommandEditorRoot",R=e=>{if(!e)return null;const t=e.querySelector('[contenteditable="true"]');return t instanceof HTMLElement?t:null},H=()=>{if(typeof window>"u")return null;const e=window[M];if(!(e instanceof HTMLElement))return null;window[M]=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 n=R(t);if(n)return n;if(t.getAttribute("contenteditable")==="true")return t}if(e.getAttribute("contenteditable")==="true")return e;const r=e.closest('[contenteditable="true"]');return r instanceof HTMLElement?r:null},_=()=>{const e=H();if(e&&document.contains(e))return e;const t=window.getSelection();if(t&&t.rangeCount>0){let n=t.getRangeAt(0).startContainer;for(;n&&n!==document.body;){if(n.nodeType===Node.ELEMENT_NODE){const o=n;if(o.getAttribute("contenteditable")==="true")return o}n=n.parentNode}}const r=document.activeElement;if(r){if(r.getAttribute("contenteditable")==="true")return r;const n=r.closest('[contenteditable="true"]');if(n)return n}return document.querySelector('[contenteditable="true"]')},A=e=>e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null,O=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const r=t.getRangeAt(0);return e.contains(r.commonAncestorContainer)?r:null},y=e=>{e.dispatchEvent(new Event("input",{bubbles:!0}))},L=(e,t)=>{if(t===e.innerHTML)return;const r=window.execEditorCommand||window.executeEditorCommand;if(typeof r=="function")try{r("recordDomTransaction",e,t,e.innerHTML)}catch{}},C=(e,t)=>{if(!e.isConnected){t.focus({preventScroll:!0});return}const r=window.getSelection();if(!r)return;const n=document.createRange();n.selectNodeContents(e),n.collapse(!1),r.removeAllRanges();try{r.addRange(n)}catch{t.focus({preventScroll:!0});return}t.focus({preventScroll:!0})},b=e=>{let t=e.querySelector(":scope > p");if(!t){t=document.createElement("p");const r=[];e.childNodes.forEach(n=>{n.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(n.tagName)||r.push(n)}),r.forEach(n=>t.appendChild(n)),e.insertBefore(t,e.firstChild)}return t.innerHTML.trim()||(t.innerHTML="<br>"),t},I=e=>(e.textContent||"").replace(/\u200B/g,"").trim()?!1:!e.querySelector("img, video, table, iframe, hr, pre, ul, ol"),v=()=>{const e=document.createElement("p");return e.innerHTML="<br>",e},S=(e,t)=>{if(!e.isConnected){t.focus({preventScroll:!0});return}const r=window.getSelection();if(!r)return;const n=document.createRange();n.selectNodeContents(e),n.collapse(!0),r.removeAllRanges();try{r.addRange(n)}catch{t.focus({preventScroll:!0});return}t.focus({preventScroll:!0})},P=(e,t)=>{e.appendChild(t),e.innerHTML.trim()||(e.innerHTML="<br>")},D=(e,t,r)=>{const n=v();t.parentNode?.insertBefore(n,t.nextSibling),r.remove(),T(t).length===0&&t.remove(),S(n,e)},x=(e,t,r)=>{const n=b(t),o=r.cloneRange();o.deleteContents();const a=document.createRange();a.setStart(o.startContainer,o.startOffset),a.setEndAfter(n.lastChild||n);const s=document.createDocumentFragment();try{s.appendChild(a.extractContents())}catch{}n.innerHTML.trim()||(n.innerHTML="<br>");const c=document.createElement("li");c.setAttribute("data-type","checklist-item"),c.setAttribute("data-checked","false");const u=document.createElement("p");P(u,s),c.appendChild(u),t.parentNode?.insertBefore(c,t.nextSibling),S(u,e)},k=e=>{const t=document.createElement("li");t.setAttribute("data-type","checklist-item"),t.setAttribute("data-checked","false");const r=document.createElement("p");return r.innerHTML=e.trim()||"<br>",t.appendChild(r),t},T=e=>Array.from(e.children).filter(t=>t instanceof HTMLLIElement),B=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","LI"]),N=e=>B.has(e.tagName)&&e.getAttribute("contenteditable")!=="true",F=(e,t)=>{const r=[],n=new Set,o=i=>{!i||n.has(i)||t.contains(i)&&N(i)&&(i.closest("ul, ol")||(n.add(i),r.push(i)))},a=i=>{let d=i;for(;d&&d!==document.body;){if(d.nodeType===Node.ELEMENT_NODE){const p=d;if(N(p))return p;if(p.getAttribute("contenteditable")==="true")break}d=d.parentNode}return null};if(e.collapsed)return o(a(e.startContainer)),r;const s=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:i=>{const d=i;if(!N(d)||d.closest("ul, ol"))return NodeFilter.FILTER_SKIP;if(typeof e.intersectsNode=="function")return e.intersectsNode(d)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP;const p=document.createRange();return p.selectNodeContents(d),e.compareBoundaryPoints(Range.END_TO_START,p)>0&&e.compareBoundaryPoints(Range.START_TO_END,p)<0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let c=s.nextNode();for(;c;)o(c),c=s.nextNode();if(r.length===0&&o(a(e.commonAncestorContainer)),r.length<=1)return r;const u=r.filter(i=>!r.some(d=>d!==i&&i.contains(d)));return u.length>0?u:r},K=new Set(["P","DIV","UL","OL","LI","BLOCKQUOTE","H1","H2","H3","H4","H5","H6","TABLE","PRE","FIGURE","SECTION","ARTICLE","HEADER","FOOTER","HR"]),z=(e,t)=>{const r=t.startContainer,n=t.startOffset,o=t.endContainer,a=t.endOffset;let s=null,c=!1;if(Array.from(e.childNodes).forEach(i=>{if(i.nodeType===Node.ELEMENT_NODE&&K.has(i.tagName)){s=null;return}i.nodeType===Node.TEXT_NODE&&!(i.textContent||"").trim()||i.nodeType!==Node.TEXT_NODE&&i.nodeType!==Node.ELEMENT_NODE||(s||(s=document.createElement("p"),e.insertBefore(s,i)),s.appendChild(i),c=!0)}),!c)return;try{r===e?t.setStart(e,0):r.isConnected&&t.setStart(r,n),o===e?t.setEnd(e,e.childNodes.length):o.isConnected&&t.setEnd(o,a)}catch{}const u=window.getSelection();u&&(u.removeAllRanges(),u.addRange(t))},q=e=>{const t=[],r=document.createElement("div"),n=()=>{const o=r.innerHTML.trim();if(!o)return;const a=document.createElement("p");a.innerHTML=o,t.push(a),r.innerHTML=""};if(e.childNodes.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(o.tagName)){n();return}if(o.nodeType===Node.ELEMENT_NODE&&o.tagName==="P"){n();const a=o.innerHTML.trim(),s=document.createElement("p");s.innerHTML=a||"<br>",t.push(s);return}o.nodeType===Node.TEXT_NODE&&!(o.textContent||"").trim()||r.appendChild(o.cloneNode(!0))}),n(),t.length===0){const o=document.createElement("p");o.innerHTML="<br>",t.push(o)}return t},V=()=>({name:"checklist",init:()=>{if(!(typeof document>"u"||typeof window>"u")){if(!window.__checklistPluginClickInitialized){window.__checklistPluginClickInitialized=!0;const e=t=>{const n=t.target.closest('li[data-type="checklist-item"]');if(!n)return;const o=n.getBoundingClientRect();if(!(t.clientX-o.left<32))return;t.preventDefault(),t.stopPropagation();const c=n.closest("[contenteditable], .rte-content, .editora-content");if(c?.getAttribute("contenteditable")==="false"||!!c?.closest('[data-readonly="true"], .editora-editor[readonly], editora-editor[readonly]'))return;const i=c?.innerHTML||"",d=n.getAttribute("data-checked")==="true";n.setAttribute("data-checked",(!d).toString()),c&&(L(c,i),y(c))};document.addEventListener("click",e)}if(!window.__checklistPluginKeydownInitialized){window.__checklistPluginKeydownInitialized=!0;const e=t=>{if(t.key!=="Enter"||t.shiftKey||t.altKey||t.ctrlKey||t.metaKey||t.defaultPrevented)return;const r=window.getSelection();if(!r||r.rangeCount===0)return;const n=r.getRangeAt(0),a=A(n.startContainer)?.closest('li[data-type="checklist-item"]');if(!a)return;const s=a.closest('ul[data-type="checklist"]');if(!s)return;const c=a.closest("[contenteditable], .rte-content, .editora-content");if(!c||c.getAttribute("contenteditable")==="false"||!!c.closest('[data-readonly="true"], .editora-editor[readonly], editora-editor[readonly]'))return;t.preventDefault();const i=c.innerHTML,d=b(a);I(d)?D(c,s,a):x(c,a,n),L(c,i),y(c)};document.addEventListener("keydown",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,r=()=>(L(e,t),y(e),!0),n=O(e);if(!n)return!1;z(e,n);const o=A(n.startContainer);if(!o)return!1;const a=o.closest('ul[data-type="checklist"]');if(a&&e.contains(a)){const l=T(a);if(l.length===0)return!1;const h=document.createDocumentFragment();let f=null;return l.forEach((m,E)=>{const g=q(m);g.forEach(w=>{h.appendChild(w),!f&&(m.contains(n.startContainer)||E===0)&&(f=w)}),!f&&E===0&&g[0]&&(f=g[0])}),a.replaceWith(h),f&&C(f,e),r()}const s=o.closest("ul, ol");if(s&&e.contains(s)){let l;if(s.tagName.toLowerCase()==="ul")l=s;else{for(l=document.createElement("ul");s.firstChild;)l.appendChild(s.firstChild);s.replaceWith(l)}l.setAttribute("data-type","checklist");let h=T(l);h.length===0&&(l.appendChild(k("")),h=T(l));let f=null;h.forEach(E=>{E.setAttribute("data-type","checklist-item"),E.hasAttribute("data-checked")||E.setAttribute("data-checked","false");const g=b(E);E.contains(n.startContainer)&&(f=g)});const m=l.querySelector(':scope > li[data-type="checklist-item"] > p');return C(f||m||l,e),r()}const c=F(n,e);if(c.length>1){const l=document.createElement("ul");l.setAttribute("data-type","checklist"),c.forEach(m=>{l.appendChild(k(m.innerHTML))}),c[0].replaceWith(l),c.slice(1).forEach(m=>{m.isConnected&&m.remove()});const f=l.querySelector(':scope > li[data-type="checklist-item"] > p');return f&&C(f,e),r()}const u=c[0]||o.closest("p, h1, h2, h3, h4, h5, h6, blockquote, pre");if(u&&u!==e){const l=document.createElement("ul");l.setAttribute("data-type","checklist");const h=k(u.innerHTML);l.appendChild(h),u.replaceWith(l);const f=h.querySelector(":scope > p");return f&&C(f,e),r()}const i=document.createElement("ul");i.setAttribute("data-type","checklist");const d=k("");i.appendChild(d),n.deleteContents(),n.insertNode(i);const p=d.querySelector(":scope > p");return p&&C(p,e),r()}catch(e){return console.error("Failed to toggle checklist:",e),!1}}},keymap:{"Mod-Shift-9":"toggleChecklist"}});exports.ChecklistPlugin=V;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M="__editoraCommandEditorRoot",S=e=>{if(!e)return null;const t=e.querySelector('[contenteditable="true"]');return t instanceof HTMLElement?t:null},R=()=>{if(typeof window>"u")return null;const e=window[M];if(!(e instanceof HTMLElement))return null;window[M]=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 n=S(t);if(n)return n;if(t.getAttribute("contenteditable")==="true")return t}if(e.getAttribute("contenteditable")==="true")return e;const r=e.closest('[contenteditable="true"]');return r instanceof HTMLElement?r:null},O=()=>{const e=R();if(e&&document.contains(e))return e;const t=window.getSelection();if(t&&t.rangeCount>0){let n=t.getRangeAt(0).startContainer;for(;n&&n!==document.body;){if(n.nodeType===Node.ELEMENT_NODE){const o=n;if(o.getAttribute("contenteditable")==="true")return o}n=n.parentNode}}const r=document.activeElement;if(r){if(r.getAttribute("contenteditable")==="true")return r;const n=r.closest('[contenteditable="true"]');if(n)return n}return document.querySelector('[contenteditable="true"]')},A=e=>e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null,_=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const r=t.getRangeAt(0);return e.contains(r.commonAncestorContainer)?r:null},y=e=>{e.dispatchEvent(new Event("input",{bubbles:!0}))},L=(e,t)=>{if(t===e.innerHTML)return;const r=window.execEditorCommand||window.executeEditorCommand;if(typeof r=="function")try{r("recordDomTransaction",e,t,e.innerHTML)}catch{}},C=(e,t)=>{if(!e.isConnected){t.focus({preventScroll:!0});return}const r=window.getSelection();if(!r)return;const n=document.createRange();n.selectNodeContents(e),n.collapse(!1),r.removeAllRanges();try{r.addRange(n)}catch{t.focus({preventScroll:!0});return}t.focus({preventScroll:!0})},b=e=>{let t=e.querySelector(":scope > p");if(!t){t=document.createElement("p");const r=[];e.childNodes.forEach(n=>{n.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(n.tagName)||r.push(n)}),r.forEach(n=>t.appendChild(n)),e.insertBefore(t,e.firstChild)}return t.innerHTML.trim()||(t.innerHTML="<br>"),t},I=e=>(e.textContent||"").replace(/\u200B/g,"").trim()?!1:!e.querySelector("img, video, table, iframe, hr, pre, ul, ol"),v=()=>{const e=document.createElement("p");return e.innerHTML="<br>",e},H=(e,t)=>{if(!e.isConnected){t.focus({preventScroll:!0});return}const r=window.getSelection();if(!r)return;const n=document.createRange();n.selectNodeContents(e),n.collapse(!0),r.removeAllRanges();try{r.addRange(n)}catch{t.focus({preventScroll:!0});return}t.focus({preventScroll:!0})},P=(e,t)=>{e.appendChild(t),e.innerHTML.trim()||(e.innerHTML="<br>")},D=(e,t,r)=>{const n=v();t.parentNode?.insertBefore(n,t.nextSibling),r.remove(),T(t).length===0&&t.remove(),H(n,e)},x=(e,t,r)=>{const n=b(t),o=r.cloneRange();o.deleteContents();const a=document.createRange();a.setStart(o.startContainer,o.startOffset),a.setEndAfter(n.lastChild||n);const s=document.createDocumentFragment();try{s.appendChild(a.extractContents())}catch{}n.innerHTML.trim()||(n.innerHTML="<br>");const c=document.createElement("li");c.setAttribute("data-type","checklist-item"),c.setAttribute("data-checked","false");const u=document.createElement("p");P(u,s),c.appendChild(u),t.parentNode?.insertBefore(c,t.nextSibling),H(u,e)},k=e=>{const t=document.createElement("li");t.setAttribute("data-type","checklist-item"),t.setAttribute("data-checked","false");const r=document.createElement("p");return r.innerHTML=e.trim()||"<br>",t.appendChild(r),t},T=e=>Array.from(e.children).filter(t=>t instanceof HTMLLIElement),B=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","LI"]),N=e=>B.has(e.tagName)&&e.getAttribute("contenteditable")!=="true",F=(e,t)=>{const r=[],n=new Set,o=i=>{!i||n.has(i)||t.contains(i)&&N(i)&&(i.closest("ul, ol")||(n.add(i),r.push(i)))},a=i=>{let d=i;for(;d&&d!==document.body;){if(d.nodeType===Node.ELEMENT_NODE){const h=d;if(N(h))return h;if(h.getAttribute("contenteditable")==="true")break}d=d.parentNode}return null};if(e.collapsed)return o(a(e.startContainer)),r;const s=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:i=>{const d=i;if(!N(d)||d.closest("ul, ol"))return NodeFilter.FILTER_SKIP;if(typeof e.intersectsNode=="function")return e.intersectsNode(d)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP;const h=document.createRange();return h.selectNodeContents(d),e.compareBoundaryPoints(Range.END_TO_START,h)>0&&e.compareBoundaryPoints(Range.START_TO_END,h)<0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let c=s.nextNode();for(;c;)o(c),c=s.nextNode();if(r.length===0&&o(a(e.commonAncestorContainer)),r.length<=1)return r;const u=r.filter(i=>!r.some(d=>d!==i&&i.contains(d)));return u.length>0?u:r},K=new Set(["P","DIV","UL","OL","LI","BLOCKQUOTE","H1","H2","H3","H4","H5","H6","TABLE","PRE","FIGURE","SECTION","ARTICLE","HEADER","FOOTER","HR"]),z=(e,t)=>{const r=t.startContainer,n=t.startOffset,o=t.endContainer,a=t.endOffset;let s=null,c=!1;if(Array.from(e.childNodes).forEach(i=>{if(i.nodeType===Node.ELEMENT_NODE&&K.has(i.tagName)){s=null;return}i.nodeType===Node.TEXT_NODE&&!(i.textContent||"").trim()||i.nodeType!==Node.TEXT_NODE&&i.nodeType!==Node.ELEMENT_NODE||(s||(s=document.createElement("p"),e.insertBefore(s,i)),s.appendChild(i),c=!0)}),!c)return;try{r===e?t.setStart(e,0):r.isConnected&&t.setStart(r,n),o===e?t.setEnd(e,e.childNodes.length):o.isConnected&&t.setEnd(o,a)}catch{}const u=window.getSelection();u&&(u.removeAllRanges(),u.addRange(t))},q=e=>{const t=[],r=document.createElement("div"),n=()=>{const o=r.innerHTML.trim();if(!o)return;const a=document.createElement("p");a.innerHTML=o,t.push(a),r.innerHTML=""};if(e.childNodes.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(o.tagName)){n();return}if(o.nodeType===Node.ELEMENT_NODE&&o.tagName==="P"){n();const a=o.innerHTML.trim(),s=document.createElement("p");s.innerHTML=a||"<br>",t.push(s);return}o.nodeType===Node.TEXT_NODE&&!(o.textContent||"").trim()||r.appendChild(o.cloneNode(!0))}),n(),t.length===0){const o=document.createElement("p");o.innerHTML="<br>",t.push(o)}return t},X=()=>({name:"checklist",init:()=>{if(!(typeof document>"u"||typeof window>"u")){if(!window.__checklistPluginClickInitialized){window.__checklistPluginClickInitialized=!0;const e=t=>{const n=t.target.closest('li[data-type="checklist-item"]');if(!n)return;const o=n.getBoundingClientRect();if(!(t.clientX-o.left<32))return;t.preventDefault(),t.stopPropagation();const c=n.closest("[contenteditable], .rte-content, .editora-content");if(c?.getAttribute("contenteditable")==="false"||!!c?.closest('[data-readonly="true"], .editora-editor[readonly], editora-editor[readonly]'))return;const i=c?.innerHTML||"",d=n.getAttribute("data-checked")==="true";n.setAttribute("data-checked",(!d).toString()),c&&(L(c,i),y(c))};document.addEventListener("click",e)}if(!window.__checklistPluginKeydownInitialized){window.__checklistPluginKeydownInitialized=!0;const e=t=>{if(t.key!=="Enter"||t.shiftKey||t.altKey||t.ctrlKey||t.metaKey||t.defaultPrevented)return;const r=window.getSelection();if(!r||r.rangeCount===0)return;const n=r.getRangeAt(0),a=A(n.startContainer)?.closest('li[data-type="checklist-item"]');if(!a)return;const s=a.closest('ul[data-type="checklist"]');if(!s)return;const c=a.closest("[contenteditable], .rte-content, .editora-content");if(!c||c.getAttribute("contenteditable")==="false"||!!c.closest('[data-readonly="true"], .editora-editor[readonly], editora-editor[readonly]'))return;t.preventDefault();const i=c.innerHTML,d=b(a);I(d)?D(c,s,a):x(c,a,n),L(c,i),y(c)};document.addEventListener("keydown",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 stroke-width="0"></g><g stroke-linecap="round" stroke-linejoin="round"></g><g><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=O();if(!e)return!1;const t=e.innerHTML,r=()=>(L(e,t),y(e),!0),n=_(e);if(!n)return!1;z(e,n);const o=A(n.startContainer);if(!o)return!1;const a=o.closest('ul[data-type="checklist"]');if(a&&e.contains(a)){const l=T(a);if(l.length===0)return!1;const p=document.createDocumentFragment();let f=null;return l.forEach((m,E)=>{const g=q(m);g.forEach(w=>{p.appendChild(w),!f&&(m.contains(n.startContainer)||E===0)&&(f=w)}),!f&&E===0&&g[0]&&(f=g[0])}),a.replaceWith(p),f&&C(f,e),r()}const s=o.closest("ul, ol");if(s&&e.contains(s)){let l;if(s.tagName.toLowerCase()==="ul")l=s;else{for(l=document.createElement("ul");s.firstChild;)l.appendChild(s.firstChild);s.replaceWith(l)}l.setAttribute("data-type","checklist");let p=T(l);p.length===0&&(l.appendChild(k("")),p=T(l));let f=null;p.forEach(E=>{E.setAttribute("data-type","checklist-item"),E.hasAttribute("data-checked")||E.setAttribute("data-checked","false");const g=b(E);E.contains(n.startContainer)&&(f=g)});const m=l.querySelector(':scope > li[data-type="checklist-item"] > p');return C(f||m||l,e),r()}const c=F(n,e);if(c.length>1){const l=document.createElement("ul");l.setAttribute("data-type","checklist"),c.forEach(m=>{l.appendChild(k(m.innerHTML))}),c[0].replaceWith(l),c.slice(1).forEach(m=>{m.isConnected&&m.remove()});const f=l.querySelector(':scope > li[data-type="checklist-item"] > p');return f&&C(f,e),r()}const u=c[0]||o.closest("p, h1, h2, h3, h4, h5, h6, blockquote, pre");if(u&&u!==e){const l=document.createElement("ul");l.setAttribute("data-type","checklist");const p=k(u.innerHTML);l.appendChild(p),u.replaceWith(l);const f=p.querySelector(":scope > p");return f&&C(f,e),r()}const i=document.createElement("ul");i.setAttribute("data-type","checklist");const d=k("");i.appendChild(d),n.deleteContents(),n.insertNode(i);const h=d.querySelector(":scope > p");return h&&C(h,e),r()}catch(e){return console.error("Failed to toggle checklist:",e),!1}}},keymap:{"Mod-Shift-9":"toggleChecklist"}});exports.ChecklistPlugin=X;
|
package/dist/checklist.esm.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
const A = "__editoraCommandEditorRoot",
|
|
1
|
+
const A = "__editoraCommandEditorRoot", R = (e) => {
|
|
2
2
|
if (!e) return null;
|
|
3
3
|
const t = e.querySelector('[contenteditable="true"]');
|
|
4
4
|
return t instanceof HTMLElement ? t : null;
|
|
5
|
-
},
|
|
5
|
+
}, S = () => {
|
|
6
6
|
if (typeof window > "u") return null;
|
|
7
7
|
const e = window[A];
|
|
8
8
|
if (!(e instanceof HTMLElement)) return null;
|
|
9
9
|
window[A] = null;
|
|
10
10
|
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);
|
|
11
11
|
if (t) {
|
|
12
|
-
const n =
|
|
12
|
+
const n = R(t);
|
|
13
13
|
if (n) return n;
|
|
14
14
|
if (t.getAttribute("contenteditable") === "true") return t;
|
|
15
15
|
}
|
|
@@ -17,8 +17,8 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
17
17
|
return e;
|
|
18
18
|
const r = e.closest('[contenteditable="true"]');
|
|
19
19
|
return r instanceof HTMLElement ? r : null;
|
|
20
|
-
},
|
|
21
|
-
const e =
|
|
20
|
+
}, O = () => {
|
|
21
|
+
const e = S();
|
|
22
22
|
if (e && document.contains(e))
|
|
23
23
|
return e;
|
|
24
24
|
const t = window.getSelection();
|
|
@@ -41,7 +41,7 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
41
41
|
if (n) return n;
|
|
42
42
|
}
|
|
43
43
|
return document.querySelector('[contenteditable="true"]');
|
|
44
|
-
}, M = (e) => e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null,
|
|
44
|
+
}, M = (e) => e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null, _ = (e) => {
|
|
45
45
|
const t = window.getSelection();
|
|
46
46
|
if (!t || t.rangeCount === 0) return null;
|
|
47
47
|
const r = t.getRangeAt(0);
|
|
@@ -85,7 +85,7 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
85
85
|
}, I = (e) => (e.textContent || "").replace(/\u200B/g, "").trim() ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, ul, ol"), v = () => {
|
|
86
86
|
const e = document.createElement("p");
|
|
87
87
|
return e.innerHTML = "<br>", e;
|
|
88
|
-
},
|
|
88
|
+
}, H = (e, t) => {
|
|
89
89
|
if (!e.isConnected) {
|
|
90
90
|
t.focus({ preventScroll: !0 });
|
|
91
91
|
return;
|
|
@@ -105,7 +105,7 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
105
105
|
e.appendChild(t), e.innerHTML.trim() || (e.innerHTML = "<br>");
|
|
106
106
|
}, x = (e, t, r) => {
|
|
107
107
|
const n = v();
|
|
108
|
-
t.parentNode?.insertBefore(n, t.nextSibling), r.remove(), T(t).length === 0 && t.remove(),
|
|
108
|
+
t.parentNode?.insertBefore(n, t.nextSibling), r.remove(), T(t).length === 0 && t.remove(), H(n, e);
|
|
109
109
|
}, P = (e, t, r) => {
|
|
110
110
|
const n = b(t), o = r.cloneRange();
|
|
111
111
|
o.deleteContents();
|
|
@@ -120,7 +120,7 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
120
120
|
const c = document.createElement("li");
|
|
121
121
|
c.setAttribute("data-type", "checklist-item"), c.setAttribute("data-checked", "false");
|
|
122
122
|
const u = document.createElement("p");
|
|
123
|
-
D(u, s), c.appendChild(u), t.parentNode?.insertBefore(c, t.nextSibling),
|
|
123
|
+
D(u, s), c.appendChild(u), t.parentNode?.insertBefore(c, t.nextSibling), H(u, e);
|
|
124
124
|
}, k = (e) => {
|
|
125
125
|
const t = document.createElement("li");
|
|
126
126
|
t.setAttribute("data-type", "checklist-item"), t.setAttribute("data-checked", "false");
|
|
@@ -147,9 +147,9 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
147
147
|
let d = i;
|
|
148
148
|
for (; d && d !== document.body; ) {
|
|
149
149
|
if (d.nodeType === Node.ELEMENT_NODE) {
|
|
150
|
-
const
|
|
151
|
-
if (N(
|
|
152
|
-
if (
|
|
150
|
+
const h = d;
|
|
151
|
+
if (N(h)) return h;
|
|
152
|
+
if (h.getAttribute("contenteditable") === "true") break;
|
|
153
153
|
}
|
|
154
154
|
d = d.parentNode;
|
|
155
155
|
}
|
|
@@ -166,8 +166,8 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
166
166
|
if (!N(d) || d.closest("ul, ol")) return NodeFilter.FILTER_SKIP;
|
|
167
167
|
if (typeof e.intersectsNode == "function")
|
|
168
168
|
return e.intersectsNode(d) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
169
|
-
const
|
|
170
|
-
return
|
|
169
|
+
const h = document.createRange();
|
|
170
|
+
return h.selectNodeContents(d), e.compareBoundaryPoints(Range.END_TO_START, h) > 0 && e.compareBoundaryPoints(Range.START_TO_END, h) < 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
);
|
|
@@ -239,7 +239,7 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
239
239
|
o.innerHTML = "<br>", t.push(o);
|
|
240
240
|
}
|
|
241
241
|
return t;
|
|
242
|
-
},
|
|
242
|
+
}, X = () => ({
|
|
243
243
|
name: "checklist",
|
|
244
244
|
// Initialize click handler when plugin is loaded
|
|
245
245
|
init: () => {
|
|
@@ -314,16 +314,16 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
314
314
|
{
|
|
315
315
|
label: "Checklist",
|
|
316
316
|
command: "toggleChecklist",
|
|
317
|
-
icon: '<svg width="24px" height="24px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g
|
|
317
|
+
icon: '<svg width="24px" height="24px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g stroke-width="0"></g><g stroke-linecap="round" stroke-linejoin="round"></g><g><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>',
|
|
318
318
|
shortcut: "Mod-Shift-9"
|
|
319
319
|
}
|
|
320
320
|
],
|
|
321
321
|
commands: {
|
|
322
322
|
toggleChecklist: () => {
|
|
323
323
|
try {
|
|
324
|
-
const e =
|
|
324
|
+
const e = O();
|
|
325
325
|
if (!e) return !1;
|
|
326
|
-
const t = e.innerHTML, r = () => (L(e, t), y(e), !0), n =
|
|
326
|
+
const t = e.innerHTML, r = () => (L(e, t), y(e), !0), n = _(e);
|
|
327
327
|
if (!n) return !1;
|
|
328
328
|
z(e, n);
|
|
329
329
|
const o = M(n.startContainer);
|
|
@@ -332,14 +332,14 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
332
332
|
if (a && e.contains(a)) {
|
|
333
333
|
const l = T(a);
|
|
334
334
|
if (l.length === 0) return !1;
|
|
335
|
-
const
|
|
335
|
+
const p = document.createDocumentFragment();
|
|
336
336
|
let f = null;
|
|
337
337
|
return l.forEach((m, E) => {
|
|
338
338
|
const g = q(m);
|
|
339
339
|
g.forEach((w) => {
|
|
340
|
-
|
|
340
|
+
p.appendChild(w), !f && (m.contains(n.startContainer) || E === 0) && (f = w);
|
|
341
341
|
}), !f && E === 0 && g[0] && (f = g[0]);
|
|
342
|
-
}), a.replaceWith(
|
|
342
|
+
}), a.replaceWith(p), f && C(f, e), r();
|
|
343
343
|
}
|
|
344
344
|
const s = o.closest("ul, ol");
|
|
345
345
|
if (s && e.contains(s)) {
|
|
@@ -352,10 +352,10 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
352
352
|
s.replaceWith(l);
|
|
353
353
|
}
|
|
354
354
|
l.setAttribute("data-type", "checklist");
|
|
355
|
-
let
|
|
356
|
-
|
|
355
|
+
let p = T(l);
|
|
356
|
+
p.length === 0 && (l.appendChild(k("")), p = T(l));
|
|
357
357
|
let f = null;
|
|
358
|
-
|
|
358
|
+
p.forEach((E) => {
|
|
359
359
|
E.setAttribute("data-type", "checklist-item"), E.hasAttribute("data-checked") || E.setAttribute("data-checked", "false");
|
|
360
360
|
const g = b(E);
|
|
361
361
|
E.contains(n.startContainer) && (f = g);
|
|
@@ -378,17 +378,17 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
378
378
|
if (u && u !== e) {
|
|
379
379
|
const l = document.createElement("ul");
|
|
380
380
|
l.setAttribute("data-type", "checklist");
|
|
381
|
-
const
|
|
382
|
-
l.appendChild(
|
|
383
|
-
const f =
|
|
381
|
+
const p = k(u.innerHTML);
|
|
382
|
+
l.appendChild(p), u.replaceWith(l);
|
|
383
|
+
const f = p.querySelector(":scope > p");
|
|
384
384
|
return f && C(f, e), r();
|
|
385
385
|
}
|
|
386
386
|
const i = document.createElement("ul");
|
|
387
387
|
i.setAttribute("data-type", "checklist");
|
|
388
388
|
const d = k("");
|
|
389
389
|
i.appendChild(d), n.deleteContents(), n.insertNode(i);
|
|
390
|
-
const
|
|
391
|
-
return
|
|
390
|
+
const h = d.querySelector(":scope > p");
|
|
391
|
+
return h && C(h, e), r();
|
|
392
392
|
} catch (e) {
|
|
393
393
|
return console.error("Failed to toggle checklist:", e), !1;
|
|
394
394
|
}
|
|
@@ -399,5 +399,5 @@ const A = "__editoraCommandEditorRoot", S = (e) => {
|
|
|
399
399
|
}
|
|
400
400
|
});
|
|
401
401
|
export {
|
|
402
|
-
|
|
402
|
+
X as ChecklistPlugin
|
|
403
403
|
};
|