@editora/plugins 1.0.13 → 1.0.15

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=()=>({name:"clearFormatting",toolbar:[{label:"Clear Formatting",command:"clearFormatting",icon:'<svg width="24" height="24" focusable="false"><path d="M13.2 6a1 1 0 0 1 0 .2l-2.6 10a1 1 0 0 1-1 .8h-.2a.8.8 0 0 1-.8-1l2.6-10H8a1 1 0 1 1 0-2h9a1 1 0 0 1 0 2h-3.8ZM5 18h7a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Zm13 1.5L16.5 18 15 19.5a.7.7 0 0 1-1-1l1.5-1.5-1.5-1.5a.7.7 0 0 1 1-1l1.5 1.5 1.5-1.5a.7.7 0 0 1 1 1L17.5 17l1.5 1.5a.7.7 0 0 1-1 1Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-\\"}],commands:{clearFormatting:()=>{const t=m();if(!t)return!1;const e=window.getSelection();if(!e||e.rangeCount===0)return!1;const n=e.getRangeAt(0);if(!t.contains(n.commonAncestorContainer))return!1;const r=n.cloneRange();return t.focus({preventScroll:!0}),A(t,r),C(t,r),t.dispatchEvent(new Event("input",{bubbles:!0})),!0}},keymap:{"Mod-\\":"clearFormatting"}}),d=new Set(["A","B","STRONG","I","EM","U","S","STRIKE","DEL","FONT","MARK","CODE","SUB","SUP"]),g=new Set(["H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE"]),h=["color","background-color","font-size","font-family","font-weight","font-style","text-decoration","text-transform","line-height","letter-spacing","word-spacing","vertical-align","text-align","padding-left"];function m(){const t=window.getSelection();if(t&&t.rangeCount>0){const n=t.getRangeAt(0).startContainer,o=(n.nodeType===Node.ELEMENT_NODE?n:n.parentElement)?.closest('[contenteditable="true"], .rte-content, .editora-content');if(o)return o}const e=document.activeElement;return e?e.getAttribute("contenteditable")==="true"?e:e.closest('[contenteditable="true"], .rte-content, .editora-content'):null}function c(t,e){try{if(typeof t.intersectsNode=="function")return t.intersectsNode(e)}catch{}const n=document.createRange();return e.nodeType===Node.ELEMENT_NODE?n.selectNodeContents(e):n.selectNode(e),t.compareBoundaryPoints(Range.END_TO_START,n)>0&&t.compareBoundaryPoints(Range.START_TO_END,n)<0}function i(t){let e=0,n=t;for(;n&&n.parentNode;)e+=1,n=n.parentNode;return e}function p(t){h.forEach(e=>{t.style.removeProperty(e)}),(!t.getAttribute("style")||t.style.length===0)&&t.removeAttribute("style"),t.classList.contains("rte-text-color")&&t.classList.remove("rte-text-color"),t.classList.contains("rte-bg-color")&&t.classList.remove("rte-bg-color"),t.classList.length===0&&t.removeAttribute("class")}function a(t){const e=t.parentNode;if(e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);e.removeChild(t)}}function E(t){return t.tagName!=="P"||t.attributes.length>0||(t.textContent||"").trim()!==""?!1:!t.querySelector("img, video, table, iframe, hr, pre, ul, ol")}function l(t){Array.from(t.children).forEach(e=>{E(e)&&e.remove()})}function s(t){l(t),a(t)}function f(t){const e=document.createElement("p");for(Array.from(t.attributes).forEach(n=>{e.setAttribute(n.name,n.value)});t.firstChild;)e.appendChild(t.firstChild);e.innerHTML.trim()||(e.innerHTML="<br>"),t.parentNode?.replaceChild(e,t)}function N(t){if(l(t),t.parentElement instanceof HTMLLIElement){s(t);return}if(Array.from(t.childNodes).filter(o=>o.nodeType!==Node.TEXT_NODE||(o.textContent||"").trim()!=="").some(o=>o instanceof HTMLElement&&/^(P|DIV|H[1-6]|UL|OL|PRE|TABLE|BLOCKQUOTE)$/.test(o.tagName))){s(t);return}f(t)}function C(t,e){Array.from(t.querySelectorAll("h1,h2,h3,h4,h5,h6,blockquote,pre")).forEach(r=>{if(c(e,r)&&g.has(r.tagName)){if(r.tagName==="BLOCKQUOTE"){N(r);return}f(r)}})}function A(t,e){const n=Array.from(t.querySelectorAll("a,b,strong,i,em,u,s,strike,del,font,mark,code,sub,sup,span,[style],[class]"));n.sort((r,o)=>i(o)-i(r)),n.forEach(r=>{if(r.isConnected&&c(e,r)&&!(r.getAttribute("contenteditable")==="false"||r.closest('[contenteditable="false"]'))){if(p(r),d.has(r.tagName)){a(r);return}r.tagName==="SPAN"&&r.attributes.length===0&&a(r)}})}exports.ClearFormattingPlugin=u;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=()=>({name:"clearFormatting",toolbar:[{label:"Clear Formatting",command:"clearFormatting",icon:'<svg width="24" height="24" focusable="false"><path d="M13.2 6a1 1 0 0 1 0 .2l-2.6 10a1 1 0 0 1-1 .8h-.2a.8.8 0 0 1-.8-1l2.6-10H8a1 1 0 1 1 0-2h9a1 1 0 0 1 0 2h-3.8ZM5 18h7a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Zm13 1.5L16.5 18 15 19.5a.7.7 0 0 1-1-1l1.5-1.5-1.5-1.5a.7.7 0 0 1 1-1l1.5 1.5 1.5-1.5a.7.7 0 0 1 1 1L17.5 17l1.5 1.5a.7.7 0 0 1-1 1Z" fill-rule="evenodd"></path></svg>',shortcut:"Mod-\\"}],commands:{clearFormatting:()=>{const t=m();if(!t)return!1;const e=window.getSelection();if(!e||e.rangeCount===0)return!1;const r=e.getRangeAt(0);if(!t.contains(r.commonAncestorContainer))return!1;const n=r.cloneRange();return t.focus({preventScroll:!0}),T(t,n),C(t,n),t.dispatchEvent(new Event("input",{bubbles:!0})),!0}},keymap:{"Mod-\\":"clearFormatting"}}),d=new Set(["A","B","STRONG","I","EM","U","S","STRIKE","DEL","FONT","MARK","CODE","SUB","SUP"]),g=new Set(["H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE"]),h=["color","background-color","font-size","font-family","font-weight","font-style","text-decoration","text-transform","line-height","letter-spacing","word-spacing","vertical-align","text-align","padding-left"];function m(){const t=window.getSelection();if(t&&t.rangeCount>0){const r=t.getRangeAt(0).startContainer,o=(r.nodeType===Node.ELEMENT_NODE?r:r.parentElement)?.closest('[contenteditable="true"], .rte-content, .editora-content');if(o)return o}const e=document.activeElement;return e?e.getAttribute("contenteditable")==="true"?e:e.closest('[contenteditable="true"], .rte-content, .editora-content'):null}function c(t,e){try{if(typeof t.intersectsNode=="function")return t.intersectsNode(e)}catch{}const r=document.createRange();return e.nodeType===Node.ELEMENT_NODE?r.selectNodeContents(e):r.selectNode(e),t.compareBoundaryPoints(Range.END_TO_START,r)>0&&t.compareBoundaryPoints(Range.START_TO_END,r)<0}function a(t){let e=0,r=t;for(;r&&r.parentNode;)e+=1,r=r.parentNode;return e}function E(t){h.forEach(e=>{t.style.removeProperty(e)}),(!t.getAttribute("style")||t.style.length===0)&&t.removeAttribute("style"),t.classList.contains("rte-text-color")&&t.classList.remove("rte-text-color"),t.classList.contains("rte-bg-color")&&t.classList.remove("rte-bg-color"),t.classList.contains("rte-format-painted")&&t.classList.remove("rte-format-painted"),t.classList.length===0&&t.removeAttribute("class")}function i(t){const e=t.parentNode;if(e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);e.removeChild(t)}}function p(t){return t.tagName!=="P"||t.attributes.length>0||(t.textContent||"").trim()!==""?!1:!t.querySelector("img, video, table, iframe, hr, pre, ul, ol")}function l(t){Array.from(t.children).forEach(e=>{p(e)&&e.remove()})}function s(t){l(t),i(t)}function f(t){const e=document.createElement("p");for(Array.from(t.attributes).forEach(r=>{e.setAttribute(r.name,r.value)});t.firstChild;)e.appendChild(t.firstChild);e.innerHTML.trim()||(e.innerHTML="<br>"),t.parentNode?.replaceChild(e,t)}function N(t){return!/^(A|B|STRONG|I|EM|U|S|STRIKE|DEL|FONT|MARK|CODE|SUB|SUP|SPAN)$/.test(t.tagName)||(t.textContent||"").trim()!==""?!1:!t.querySelector("img, video, table, iframe, hr, svg, math")}function A(t){Array.from(t.querySelectorAll("a,b,strong,i,em,u,s,strike,del,font,mark,code,sub,sup,span")).sort((r,n)=>a(n)-a(r)).forEach(r=>{r.isConnected&&N(r)&&r.remove()})}function y(t){if(l(t),t.parentElement instanceof HTMLLIElement){s(t);return}if(Array.from(t.childNodes).filter(o=>o.nodeType!==Node.TEXT_NODE||(o.textContent||"").trim()!=="").some(o=>o instanceof HTMLElement&&/^(P|DIV|H[1-6]|UL|OL|PRE|TABLE|BLOCKQUOTE)$/.test(o.tagName))){s(t);return}f(t)}function C(t,e){Array.from(t.querySelectorAll("h1,h2,h3,h4,h5,h6,blockquote,pre")).forEach(n=>{if(c(e,n)&&g.has(n.tagName)){if(n.tagName==="BLOCKQUOTE"){y(n);return}f(n)}})}function T(t,e){const r=Array.from(t.querySelectorAll("a,b,strong,i,em,u,s,strike,del,font,mark,code,sub,sup,span,[style],[class]"));r.sort((n,o)=>a(o)-a(n)),r.forEach(n=>{if(n.isConnected&&c(e,n)&&!(n.getAttribute("contenteditable")==="false"||n.closest('[contenteditable="false"]'))){if(E(n),d.has(n.tagName)){i(n);return}n.tagName==="SPAN"&&n.attributes.length===0&&i(n)}}),A(t)}exports.ClearFormattingPlugin=u;
@@ -1,4 +1,4 @@
1
- const C = () => ({
1
+ const T = () => ({
2
2
  name: "clearFormatting",
3
3
  // Toolbar button configuration
4
4
  toolbar: [
@@ -19,10 +19,10 @@ const C = () => ({
19
19
  if (!t) return !1;
20
20
  const e = window.getSelection();
21
21
  if (!e || e.rangeCount === 0) return !1;
22
- const n = e.getRangeAt(0);
23
- if (!t.contains(n.commonAncestorContainer)) return !1;
24
- const r = n.cloneRange();
25
- return t.focus({ preventScroll: !0 }), A(t, r), N(t, r), t.dispatchEvent(new Event("input", { bubbles: !0 })), !0;
22
+ const r = e.getRangeAt(0);
23
+ if (!t.contains(r.commonAncestorContainer)) return !1;
24
+ const n = r.cloneRange();
25
+ return t.focus({ preventScroll: !0 }), C(t, n), y(t, n), t.dispatchEvent(new Event("input", { bubbles: !0 })), !0;
26
26
  }
27
27
  },
28
28
  // Keyboard shortcuts
@@ -72,7 +72,7 @@ const C = () => ({
72
72
  function h() {
73
73
  const t = window.getSelection();
74
74
  if (t && t.rangeCount > 0) {
75
- const n = t.getRangeAt(0).startContainer, o = (n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement)?.closest('[contenteditable="true"], .rte-content, .editora-content');
75
+ const r = t.getRangeAt(0).startContainer, o = (r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement)?.closest('[contenteditable="true"], .rte-content, .editora-content');
76
76
  if (o) return o;
77
77
  }
78
78
  const e = document.activeElement;
@@ -84,21 +84,21 @@ function c(t, e) {
84
84
  return t.intersectsNode(e);
85
85
  } catch {
86
86
  }
87
- const n = document.createRange();
88
- return e.nodeType === Node.ELEMENT_NODE ? n.selectNodeContents(e) : n.selectNode(e), t.compareBoundaryPoints(Range.END_TO_START, n) > 0 && t.compareBoundaryPoints(Range.START_TO_END, n) < 0;
87
+ const r = document.createRange();
88
+ return e.nodeType === Node.ELEMENT_NODE ? r.selectNodeContents(e) : r.selectNode(e), t.compareBoundaryPoints(Range.END_TO_START, r) > 0 && t.compareBoundaryPoints(Range.START_TO_END, r) < 0;
89
89
  }
90
- function i(t) {
91
- let e = 0, n = t;
92
- for (; n && n.parentNode; )
93
- e += 1, n = n.parentNode;
90
+ function a(t) {
91
+ let e = 0, r = t;
92
+ for (; r && r.parentNode; )
93
+ e += 1, r = r.parentNode;
94
94
  return e;
95
95
  }
96
96
  function m(t) {
97
97
  g.forEach((e) => {
98
98
  t.style.removeProperty(e);
99
- }), (!t.getAttribute("style") || t.style.length === 0) && t.removeAttribute("style"), t.classList.contains("rte-text-color") && t.classList.remove("rte-text-color"), t.classList.contains("rte-bg-color") && t.classList.remove("rte-bg-color"), t.classList.length === 0 && t.removeAttribute("class");
99
+ }), (!t.getAttribute("style") || t.style.length === 0) && t.removeAttribute("style"), t.classList.contains("rte-text-color") && t.classList.remove("rte-text-color"), t.classList.contains("rte-bg-color") && t.classList.remove("rte-bg-color"), t.classList.contains("rte-format-painted") && t.classList.remove("rte-format-painted"), t.classList.length === 0 && t.removeAttribute("class");
100
100
  }
101
- function a(t) {
101
+ function i(t) {
102
102
  const e = t.parentNode;
103
103
  if (e) {
104
104
  for (; t.firstChild; )
@@ -106,26 +106,36 @@ function a(t) {
106
106
  e.removeChild(t);
107
107
  }
108
108
  }
109
- function p(t) {
109
+ function E(t) {
110
110
  return t.tagName !== "P" || t.attributes.length > 0 || (t.textContent || "").trim() !== "" ? !1 : !t.querySelector("img, video, table, iframe, hr, pre, ul, ol");
111
111
  }
112
112
  function l(t) {
113
113
  Array.from(t.children).forEach((e) => {
114
- p(e) && e.remove();
114
+ E(e) && e.remove();
115
115
  });
116
116
  }
117
117
  function s(t) {
118
- l(t), a(t);
118
+ l(t), i(t);
119
119
  }
120
120
  function f(t) {
121
121
  const e = document.createElement("p");
122
- for (Array.from(t.attributes).forEach((n) => {
123
- e.setAttribute(n.name, n.value);
122
+ for (Array.from(t.attributes).forEach((r) => {
123
+ e.setAttribute(r.name, r.value);
124
124
  }); t.firstChild; )
125
125
  e.appendChild(t.firstChild);
126
126
  e.innerHTML.trim() || (e.innerHTML = "<br>"), t.parentNode?.replaceChild(e, t);
127
127
  }
128
- function E(t) {
128
+ function p(t) {
129
+ return !/^(A|B|STRONG|I|EM|U|S|STRIKE|DEL|FONT|MARK|CODE|SUB|SUP|SPAN)$/.test(t.tagName) || (t.textContent || "").trim() !== "" ? !1 : !t.querySelector("img, video, table, iframe, hr, svg, math");
130
+ }
131
+ function N(t) {
132
+ Array.from(
133
+ t.querySelectorAll("a,b,strong,i,em,u,s,strike,del,font,mark,code,sub,sup,span")
134
+ ).sort((r, n) => a(n) - a(r)).forEach((r) => {
135
+ r.isConnected && p(r) && r.remove();
136
+ });
137
+ }
138
+ function A(t) {
129
139
  if (l(t), t.parentElement instanceof HTMLLIElement) {
130
140
  s(t);
131
141
  return;
@@ -136,35 +146,35 @@ function E(t) {
136
146
  }
137
147
  f(t);
138
148
  }
139
- function N(t, e) {
149
+ function y(t, e) {
140
150
  Array.from(
141
151
  t.querySelectorAll("h1,h2,h3,h4,h5,h6,blockquote,pre")
142
- ).forEach((r) => {
143
- if (c(e, r) && d.has(r.tagName)) {
144
- if (r.tagName === "BLOCKQUOTE") {
145
- E(r);
152
+ ).forEach((n) => {
153
+ if (c(e, n) && d.has(n.tagName)) {
154
+ if (n.tagName === "BLOCKQUOTE") {
155
+ A(n);
146
156
  return;
147
157
  }
148
- f(r);
158
+ f(n);
149
159
  }
150
160
  });
151
161
  }
152
- function A(t, e) {
153
- const n = Array.from(
162
+ function C(t, e) {
163
+ const r = Array.from(
154
164
  t.querySelectorAll(
155
165
  "a,b,strong,i,em,u,s,strike,del,font,mark,code,sub,sup,span,[style],[class]"
156
166
  )
157
167
  );
158
- n.sort((r, o) => i(o) - i(r)), n.forEach((r) => {
159
- if (r.isConnected && c(e, r) && !(r.getAttribute("contenteditable") === "false" || r.closest('[contenteditable="false"]'))) {
160
- if (m(r), u.has(r.tagName)) {
161
- a(r);
168
+ r.sort((n, o) => a(o) - a(n)), r.forEach((n) => {
169
+ if (n.isConnected && c(e, n) && !(n.getAttribute("contenteditable") === "false" || n.closest('[contenteditable="false"]'))) {
170
+ if (m(n), u.has(n.tagName)) {
171
+ i(n);
162
172
  return;
163
173
  }
164
- r.tagName === "SPAN" && r.attributes.length === 0 && a(r);
174
+ n.tagName === "SPAN" && n.attributes.length === 0 && i(n);
165
175
  }
166
- });
176
+ }), N(t);
167
177
  }
168
178
  export {
169
- C as ClearFormattingPlugin
179
+ T as ClearFormattingPlugin
170
180
  };