@editora/plugin-table 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +35 -0
- package/dist/index.esm.js +498 -0
- package/dist/plugin-table.css +1 -0
- package/package.json +27 -0
- package/src/TablePlugin.native.ts +1053 -0
- package/src/index.ts +1 -0
- package/src/table.css +407 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function q(){const e=window.getSelection();if(!e||!e.rangeCount)return null;const n=e.getRangeAt(0).startContainer,o=n.nodeType===Node.TEXT_NODE?n.parentElement:n;return X(o)}function X(e){if(!e)return null;if(e.hasAttribute("data-editora-editor"))return e;let t=e.parentElement;for(;t;){if(t.hasAttribute("data-editora-editor"))return t;t=t.parentElement}return null}function _(e){return e?e.querySelector(".rte-content"):(console.warn("[Editora] Editor container not found"),null)}let h=null,m=null,R=null,x=null,I=null,S=null,M=null;const w='[data-theme="dark"], .dark, .editora-theme-dark';let g=!1,p=null,V=0,L=0,C=!1,A=0,k=0,B=0,D=0;const P=()=>{const e=q(),t=_(e);if(!t)return alert("Please place your cursor in the editor before inserting a table"),!1;const n=window.getSelection();if(!n||n.rangeCount===0)return;const o=n.getRangeAt(0),l=document.createElement("table");l.className="rte-table";const r=document.createElement("thead"),a=document.createElement("tr");for(let c=0;c<3;c++){const s=document.createElement("th"),u=document.createElement("p");u.appendChild(document.createElement("br")),s.appendChild(u),a.appendChild(s)}r.appendChild(a);const i=document.createElement("tbody");for(let c=0;c<2;c++){const s=document.createElement("tr");for(let u=0;u<3;u++){const v=document.createElement("td"),T=document.createElement("p");T.appendChild(document.createElement("br")),v.appendChild(T),s.appendChild(v)}i.appendChild(s)}l.appendChild(r),l.appendChild(i),o.deleteContents(),o.insertNode(l);const d=l.querySelector("th p");if(d){const c=document.createRange();c.setStart(d,0),c.collapse(!0),n.removeAllRanges(),n.addRange(c)}t.focus()},O=()=>{const e=f();if(!e)return;const{table:t,rowIndex:n}=e,o=document.createElement("tr"),l=t.rows[0]?.cells.length||0;for(let a=0;a<l;a++){const i=document.createElement("td"),d=document.createElement("p");d.innerHTML="<br>",i.appendChild(d),o.appendChild(i)}const r=t.rows[n];r&&r.parentElement?r.parentElement.insertBefore(o,r):t.appendChild(o),b()},H=()=>{const e=f();if(!e)return;const{table:t,rowIndex:n}=e,o=document.createElement("tr"),l=t.rows[0]?.cells.length||0;for(let r=0;r<l;r++){const a=document.createElement("td"),i=document.createElement("p");i.innerHTML="<br>",a.appendChild(i),o.appendChild(a)}n>=t.rows.length-1?t.appendChild(o):t.insertBefore(o,t.rows[n+1]),b()},W=()=>{const e=f();if(!e)return;const{table:t,colIndex:n}=e;for(let o=0;o<t.rows.length;o++){const l=t.rows[o],r=document.createElement("td"),a=document.createElement("p");a.innerHTML="<br>",r.appendChild(a),n===0?l.insertBefore(r,l.cells[0]):l.insertBefore(r,l.cells[n])}b()},z=()=>{const e=f();if(!e)return;const{table:t,colIndex:n}=e;for(let o=0;o<t.rows.length;o++){const l=t.rows[o],r=document.createElement("td"),a=document.createElement("p");a.innerHTML="<br>",r.appendChild(a),n>=l.cells.length-1?l.appendChild(r):l.insertBefore(r,l.cells[n+1])}b()},K=()=>{const e=f();if(!e||e.rowCount<=1)return;const{table:t,rowIndex:n}=e;t.deleteRow(n),b()},Y=()=>{const e=f();if(!e||e.cellCount<=1)return;const{table:t,colIndex:n}=e;for(let o=0;o<t.rows.length;o++){const l=t.rows[o];l.cells[n]&&l.deleteCell(n)}b()},F=()=>{const e=f();if(!e)return;const{table:t,rowIndex:n}=e,o=t.rows[n];if(o.parentElement?.tagName.toLowerCase()==="thead"){const r=t.querySelector("tbody")||t.appendChild(document.createElement("tbody")),a=t.querySelector("thead");a&&(r.insertBefore(o,r.firstChild),a.rows.length===0&&a.remove())}else{let r=t.querySelector("thead");r||(r=document.createElement("thead"),t.insertBefore(r,t.firstChild)),r.appendChild(o)}b()},U=()=>{const e=f();if(!e)return;const{table:t,colIndex:n}=e;for(let o=0;o<t.rows.length;o++){const l=t.rows[o].cells[n];if(l){const r=l.tagName.toLowerCase()==="th"?"td":"th",a=document.createElement(r);a.innerHTML=l.innerHTML;for(let i=0;i<l.attributes.length;i++){const d=l.attributes[i];a.setAttribute(d.name,d.value)}l.parentNode?.replaceChild(a,l)}}b()},j=()=>{const e=f();if(!e)return;e.table.remove(),document.dispatchEvent(new CustomEvent("tableDeleted"))},G=()=>{const e=window.getSelection();if(!e||e.rangeCount===0)return;const n=e.getRangeAt(0).startContainer;if(!(n.nodeType===Node.TEXT_NODE?n.parentElement?.closest("table"):n.closest("table")))return;let l=null;if(n.nodeType===Node.TEXT_NODE?l=n.parentElement?.closest("td, th"):n.nodeType===Node.ELEMENT_NODE&&(l=n.closest("td, th")),!l)return;const r=l.parentElement;if(!r)return;let a=-1;for(let u=0;u<r.cells.length;u++)if(r.cells[u]===l){a=u;break}if(a===-1||a===r.cells.length-1)return;const i=r.cells[a+1];if(!i)return;const d=parseInt(l.getAttribute("colspan")||"1"),c=parseInt(i.getAttribute("colspan")||"1");l.setAttribute("colspan",String(d+c)),Array.from(i.childNodes).forEach(u=>{l.appendChild(u)}),i.remove(),b()};function f(){const e=window.getSelection();if(!e||e.rangeCount===0)return null;const n=e.getRangeAt(0).startContainer;let o=n.nodeType===Node.TEXT_NODE?n.parentElement?.closest("table"):n.closest("table");if(!o)return null;const l=o;let r=0,a=0;const i=n.nodeType===Node.TEXT_NODE?n.parentElement?.closest("td, th"):n.closest("td, th");if(i){let d=i.parentElement;for(;d&&d!==l.rows[r]&&(r++,!(r>=l.rows.length)););const c=d;if(c){for(let s=0;s<c.cells.length;s++)if(c.cells[s]===i){a=s;break}}}return{table:l,rowIndex:r,colIndex:a,rowCount:l.rows.length,cellCount:l.rows[0]?.cells.length||0}}function b(){if(!h||!m)return;const e=f();if(!e)return;const t=e.rowCount>1,n=e.cellCount>1;N(t,n)}function J(){R=()=>{const e=f();e?Q(e.table):E()},x=e=>{const t=e.target,n=t.closest("table"),o=t.closest(".table-toolbar");!n&&!o&&E()},I=()=>{E()},S=()=>{m&&h&&h.style.display!=="none"&&y(m)},M=()=>{m&&h&&h.style.display!=="none"&&y(m)},document.addEventListener("selectionchange",R),document.addEventListener("mousedown",x),document.addEventListener("tableDeleted",I),window.addEventListener("scroll",S,!0),window.addEventListener("resize",M)}function y(e){if(!h)return;const t=e.getBoundingClientRect(),n=h.getBoundingClientRect(),o=n.height||40,l=n.width||280,r=10;let a=t.top-o-r,i=t.left+t.width/2-l/2;a<r&&(a=t.bottom+r),i<r&&(i=r);const d=window.innerWidth;i+l>d-r&&(i=d-l-r);const c=window.innerHeight;a+o>c-r&&(a=c-o-r),h.style.top=a+"px",h.style.left=i+"px"}function Q(e){m=e,h||(h=Z(),document.body.appendChild(h));const t=!!e.closest(w)||document.body.matches(w)||document.documentElement.matches(w);h.classList.toggle("rte-theme-dark",t),h.style.display="flex",h.style.visibility="hidden",requestAnimationFrame(()=>{y(e),h&&(h.style.visibility="visible")});const n=f();n&&N(n.rowCount>1,n.cellCount>1),ee(e)}function E(){if(h&&(h.style.display="none"),m){m.querySelectorAll(".resize-handle").forEach(n=>n.remove());const t=m.querySelector(".table-resize-handle");t&&t.remove()}m=null}function N(e,t){if(!h)return;const n=h.querySelector('[data-action="deleteRow"]'),o=h.querySelector('[data-action="deleteColumn"]');n&&(n.disabled=!e),o&&(o.disabled=!t)}function Z(){const e=document.createElement("div");e.className="table-toolbar",e.style.cssText=`
|
|
2
|
+
position: fixed;
|
|
3
|
+
z-index: 1000;
|
|
4
|
+
display: none;
|
|
5
|
+
`,e.setAttribute("role","toolbar"),e.setAttribute("aria-label","Table editing toolbar");const t=s=>{const u=document.createElement("button");return u.className="toolbar-icon-btn",s.danger&&u.classList.add("toolbar-icon-btn-danger"),s.delete&&u.classList.add("toolbar-icon-btn-delete"),u.innerHTML=s.icon,u.title=s.title,u.setAttribute("aria-label",s.title),u.setAttribute("type","button"),u.setAttribute("data-action",s.action),u.onclick=()=>$(s.action),u},n=()=>{const s=document.createElement("div");return s.className="toolbar-divider",s},o=(...s)=>{const u=document.createElement("div");return u.className="toolbar-section",s.forEach(v=>u.appendChild(v)),u},l=o(t({icon:oe(),title:"Add row above (Ctrl+Shift+R)",action:"addRowAbove"}),t({icon:le(),title:"Add row below",action:"addRowBelow"}),t({icon:re(),title:"Delete row",action:"deleteRow",danger:!0})),r=o(t({icon:ae(),title:"Add column left",action:"addColumnLeft"}),t({icon:ie(),title:"Add column right (Ctrl+Shift+C)",action:"addColumnRight"}),t({icon:se(),title:"Delete column",action:"deleteColumn",danger:!0})),a=o(t({icon:de(),title:"Toggle header row",action:"toggleHeaderRow"}),t({icon:ce(),title:"Toggle header column",action:"toggleHeaderColumn"})),i=o(t({icon:he(),title:"Merge cells (horizontally)",action:"mergeCells"})),d=o(t({icon:ue(),title:"Delete table",action:"deleteTable",delete:!0}));e.appendChild(l),e.appendChild(n()),e.appendChild(r),e.appendChild(n()),e.appendChild(a),e.appendChild(n()),e.appendChild(i),e.appendChild(n()),e.appendChild(d);const c=s=>{!h||h.style.display==="none"||(s.ctrlKey||s.metaKey)&&s.shiftKey&&(s.key==="r"||s.key==="R"?(s.preventDefault(),H()):(s.key==="c"||s.key==="C")&&(s.preventDefault(),z()))};return window.addEventListener("keydown",c),e}function $(e){switch(e){case"addRowAbove":O();break;case"addRowBelow":H();break;case"addColumnLeft":W();break;case"addColumnRight":z();break;case"deleteRow":K();break;case"deleteColumn":Y();break;case"toggleHeaderRow":F();break;case"toggleHeaderColumn":U();break;case"deleteTable":j();break;case"mergeCells":G();break}}function ee(e){e.querySelectorAll(".resize-handle").forEach(a=>a.remove());const n=e.querySelector(".table-resize-handle");n&&n.remove();const o=e.querySelector("thead tr, tbody tr:first-child");if(!o)return;const l=o.querySelectorAll("td, th");l.forEach((a,i)=>{if(i===l.length-1)return;const d=document.createElement("div");d.className="resize-handle",d.style.cssText=`
|
|
6
|
+
position: absolute;
|
|
7
|
+
right: -4px;
|
|
8
|
+
top: 0;
|
|
9
|
+
bottom: 0;
|
|
10
|
+
width: 8px;
|
|
11
|
+
background: transparent;
|
|
12
|
+
cursor: col-resize;
|
|
13
|
+
z-index: 10;
|
|
14
|
+
transition: background 0.15s ease;
|
|
15
|
+
`,d.addEventListener("mouseenter",()=>{g||(d.style.background="rgba(0, 102, 204, 0.3)")}),d.addEventListener("mouseleave",()=>{g||(d.style.background="transparent")}),d.addEventListener("mousedown",c=>{c.preventDefault(),c.stopPropagation(),te(c,i)}),a.style.position="relative",a.appendChild(d)});const r=document.createElement("div");r.className="table-resize-handle",r.addEventListener("mousedown",a=>{a.preventDefault(),a.stopPropagation(),ne(a)}),e.appendChild(r)}function te(e,t){if(g=!0,p=t,V=e.clientX,!m)return;const n=m.querySelector("thead tr, tbody tr:first-child");n&&n.cells[t]&&(L=n.cells[t].offsetWidth),document.body.style.cursor="col-resize",document.body.style.userSelect="none";const o=r=>{if(!g||p===null||!m)return;const a=r.clientX-V,i=Math.max(50,L+a);m.querySelectorAll("tr").forEach(c=>{c.cells[p]&&(c.cells[p].style.width=i+"px")})},l=()=>{g=!1,p=null,document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",l)};document.addEventListener("mousemove",o),document.addEventListener("mouseup",l)}function ne(e){if(!m)return;C=!0,A=e.clientX,k=e.clientY,B=m.offsetWidth,D=m.offsetHeight,document.body.style.cursor="nwse-resize",document.body.style.userSelect="none";const t=o=>{if(!C||!m)return;const l=o.clientX-A,r=o.clientY-k,a=Math.max(200,B+l),i=Math.max(100,D+r);m.style.width=a+"px",m.style.height=i+"px"},n=()=>{C=!1,document.body.style.cursor="",document.body.style.userSelect="",document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",n)};document.addEventListener("mousemove",t),document.addEventListener("mouseup",n)}function oe(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
16
|
+
<path d="M2 7h12V5H2v2zm0 4h12V9H2v2zM8 1v3H5v2h3v3h2V6h3V4h-3V1H8z"/>
|
|
17
|
+
</svg>`}function le(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
18
|
+
<path d="M2 3h12V1H2v2zm0 4h12V5H2v2zm6 4v3h3v-2h2v-2h-2v-3h-2v3H5v2h3z"/>
|
|
19
|
+
</svg>`}function re(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
20
|
+
<path d="M2 5h12v2H2V5zm0 4h12v2H2V9zm4-6v2H4v2h2v2h2V7h2V5H8V3H6z"/>
|
|
21
|
+
</svg>`}function ae(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
22
|
+
<path d="M7 2v12h2V2H7zm4 0v12h2V2h-2zM1 8h3v-3H1v3zm3 2H1v3h3v-3z"/>
|
|
23
|
+
</svg>`}function ie(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
24
|
+
<path d="M2 2v12h2V2H2zm4 0v12h2V2H6zM12 8h3v-3h-3v3zm0 2h3v3h-3v-3z"/>
|
|
25
|
+
</svg>`}function se(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
26
|
+
<path d="M5 2v12h2V2H5zm4 0v12h2V2H9zm3 2h3V1h-3v3zm3 2h-3v3h3V6zm0 4h-3v3h3v-3z"/>
|
|
27
|
+
</svg>`}function de(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
28
|
+
<path d="M2 2h12v3H2V2zm0 5h12v8H2V7zm2 2v4h2V9H4zm4 0v4h2V9H8zm4 0v4h2V9h-2z"/>
|
|
29
|
+
</svg>`}function ce(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
30
|
+
<path d="M2 2v12h3V2H2zm5 0v12h8V2H7zm2 2h4v2H9V4zm0 4h4v2H9V8zm0 4h4v2H9v-2z"/>
|
|
31
|
+
</svg>`}function ue(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
32
|
+
<path d="M3 1h10v1H3V1zm1 2v11h8V3H4zM6 5h1v6H6V5zm3 0h1v6H9V5z"/>
|
|
33
|
+
</svg>`}function he(){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
34
|
+
<path d="M2 2h4v3H2V2zm5 0h4v3H7V2zm5 0h2v3h-2V2zm-10 4h4v3H2V6zm5 0h4v3H7V6zm5 0h2v3h-2V6zm-10 4h4v3H2v-3zm5 0h4v3H7v-3zm5 0h2v3h-2v-3z"/>
|
|
35
|
+
</svg>`}if(typeof window<"u"&&!window.__tablePluginInitialized){window.__tablePluginInitialized=!0;const e=()=>{J()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):setTimeout(e,100)}const me=()=>({name:"table",toolbar:[{label:"Insert Table",command:"insertTable",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="3" y="4" width="18" height="16" rx="2" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="M3 10h18M3 15h18M9 4v16M15 4v16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>'}],commands:{insertTable:()=>(P(),!0)},keymap:{"Mod-Shift-r":()=>(H(),!0),"Mod-Shift-c":()=>(z(),!0)}});exports.TablePlugin=me;
|
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
function q() {
|
|
2
|
+
const e = window.getSelection();
|
|
3
|
+
if (!e || !e.rangeCount)
|
|
4
|
+
return null;
|
|
5
|
+
const n = e.getRangeAt(0).startContainer, o = n.nodeType === Node.TEXT_NODE ? n.parentElement : n;
|
|
6
|
+
return X(o);
|
|
7
|
+
}
|
|
8
|
+
function X(e) {
|
|
9
|
+
if (!e) return null;
|
|
10
|
+
if (e.hasAttribute("data-editora-editor"))
|
|
11
|
+
return e;
|
|
12
|
+
let t = e.parentElement;
|
|
13
|
+
for (; t; ) {
|
|
14
|
+
if (t.hasAttribute("data-editora-editor"))
|
|
15
|
+
return t;
|
|
16
|
+
t = t.parentElement;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function _(e) {
|
|
21
|
+
return e ? e.querySelector(".rte-content") : (console.warn("[Editora] Editor container not found"), null);
|
|
22
|
+
}
|
|
23
|
+
let h = null, m = null, R = null, x = null, I = null, S = null, M = null;
|
|
24
|
+
const w = '[data-theme="dark"], .dark, .editora-theme-dark';
|
|
25
|
+
let g = !1, b = null, V = 0, L = 0, C = !1, A = 0, k = 0, B = 0, D = 0;
|
|
26
|
+
const O = () => {
|
|
27
|
+
const e = q(), t = _(e);
|
|
28
|
+
if (!t)
|
|
29
|
+
return alert("Please place your cursor in the editor before inserting a table"), !1;
|
|
30
|
+
const n = window.getSelection();
|
|
31
|
+
if (!n || n.rangeCount === 0) return;
|
|
32
|
+
const o = n.getRangeAt(0), l = document.createElement("table");
|
|
33
|
+
l.className = "rte-table";
|
|
34
|
+
const r = document.createElement("thead"), a = document.createElement("tr");
|
|
35
|
+
for (let c = 0; c < 3; c++) {
|
|
36
|
+
const s = document.createElement("th"), u = document.createElement("p");
|
|
37
|
+
u.appendChild(document.createElement("br")), s.appendChild(u), a.appendChild(s);
|
|
38
|
+
}
|
|
39
|
+
r.appendChild(a);
|
|
40
|
+
const i = document.createElement("tbody");
|
|
41
|
+
for (let c = 0; c < 2; c++) {
|
|
42
|
+
const s = document.createElement("tr");
|
|
43
|
+
for (let u = 0; u < 3; u++) {
|
|
44
|
+
const v = document.createElement("td"), T = document.createElement("p");
|
|
45
|
+
T.appendChild(document.createElement("br")), v.appendChild(T), s.appendChild(v);
|
|
46
|
+
}
|
|
47
|
+
i.appendChild(s);
|
|
48
|
+
}
|
|
49
|
+
l.appendChild(r), l.appendChild(i), o.deleteContents(), o.insertNode(l);
|
|
50
|
+
const d = l.querySelector("th p");
|
|
51
|
+
if (d) {
|
|
52
|
+
const c = document.createRange();
|
|
53
|
+
c.setStart(d, 0), c.collapse(!0), n.removeAllRanges(), n.addRange(c);
|
|
54
|
+
}
|
|
55
|
+
t.focus();
|
|
56
|
+
}, P = () => {
|
|
57
|
+
const e = f();
|
|
58
|
+
if (!e) return;
|
|
59
|
+
const { table: t, rowIndex: n } = e, o = document.createElement("tr"), l = t.rows[0]?.cells.length || 0;
|
|
60
|
+
for (let a = 0; a < l; a++) {
|
|
61
|
+
const i = document.createElement("td"), d = document.createElement("p");
|
|
62
|
+
d.innerHTML = "<br>", i.appendChild(d), o.appendChild(i);
|
|
63
|
+
}
|
|
64
|
+
const r = t.rows[n];
|
|
65
|
+
r && r.parentElement ? r.parentElement.insertBefore(o, r) : t.appendChild(o), p();
|
|
66
|
+
}, H = () => {
|
|
67
|
+
const e = f();
|
|
68
|
+
if (!e) return;
|
|
69
|
+
const { table: t, rowIndex: n } = e, o = document.createElement("tr"), l = t.rows[0]?.cells.length || 0;
|
|
70
|
+
for (let r = 0; r < l; r++) {
|
|
71
|
+
const a = document.createElement("td"), i = document.createElement("p");
|
|
72
|
+
i.innerHTML = "<br>", a.appendChild(i), o.appendChild(a);
|
|
73
|
+
}
|
|
74
|
+
n >= t.rows.length - 1 ? t.appendChild(o) : t.insertBefore(o, t.rows[n + 1]), p();
|
|
75
|
+
}, W = () => {
|
|
76
|
+
const e = f();
|
|
77
|
+
if (!e) return;
|
|
78
|
+
const { table: t, colIndex: n } = e;
|
|
79
|
+
for (let o = 0; o < t.rows.length; o++) {
|
|
80
|
+
const l = t.rows[o], r = document.createElement("td"), a = document.createElement("p");
|
|
81
|
+
a.innerHTML = "<br>", r.appendChild(a), n === 0 ? l.insertBefore(r, l.cells[0]) : l.insertBefore(r, l.cells[n]);
|
|
82
|
+
}
|
|
83
|
+
p();
|
|
84
|
+
}, z = () => {
|
|
85
|
+
const e = f();
|
|
86
|
+
if (!e) return;
|
|
87
|
+
const { table: t, colIndex: n } = e;
|
|
88
|
+
for (let o = 0; o < t.rows.length; o++) {
|
|
89
|
+
const l = t.rows[o], r = document.createElement("td"), a = document.createElement("p");
|
|
90
|
+
a.innerHTML = "<br>", r.appendChild(a), n >= l.cells.length - 1 ? l.appendChild(r) : l.insertBefore(r, l.cells[n + 1]);
|
|
91
|
+
}
|
|
92
|
+
p();
|
|
93
|
+
}, K = () => {
|
|
94
|
+
const e = f();
|
|
95
|
+
if (!e || e.rowCount <= 1) return;
|
|
96
|
+
const { table: t, rowIndex: n } = e;
|
|
97
|
+
t.deleteRow(n), p();
|
|
98
|
+
}, Y = () => {
|
|
99
|
+
const e = f();
|
|
100
|
+
if (!e || e.cellCount <= 1) return;
|
|
101
|
+
const { table: t, colIndex: n } = e;
|
|
102
|
+
for (let o = 0; o < t.rows.length; o++) {
|
|
103
|
+
const l = t.rows[o];
|
|
104
|
+
l.cells[n] && l.deleteCell(n);
|
|
105
|
+
}
|
|
106
|
+
p();
|
|
107
|
+
}, F = () => {
|
|
108
|
+
const e = f();
|
|
109
|
+
if (!e) return;
|
|
110
|
+
const { table: t, rowIndex: n } = e, o = t.rows[n];
|
|
111
|
+
if (o.parentElement?.tagName.toLowerCase() === "thead") {
|
|
112
|
+
const r = t.querySelector("tbody") || t.appendChild(document.createElement("tbody")), a = t.querySelector("thead");
|
|
113
|
+
a && (r.insertBefore(o, r.firstChild), a.rows.length === 0 && a.remove());
|
|
114
|
+
} else {
|
|
115
|
+
let r = t.querySelector("thead");
|
|
116
|
+
r || (r = document.createElement("thead"), t.insertBefore(r, t.firstChild)), r.appendChild(o);
|
|
117
|
+
}
|
|
118
|
+
p();
|
|
119
|
+
}, U = () => {
|
|
120
|
+
const e = f();
|
|
121
|
+
if (!e) return;
|
|
122
|
+
const { table: t, colIndex: n } = e;
|
|
123
|
+
for (let o = 0; o < t.rows.length; o++) {
|
|
124
|
+
const l = t.rows[o].cells[n];
|
|
125
|
+
if (l) {
|
|
126
|
+
const r = l.tagName.toLowerCase() === "th" ? "td" : "th", a = document.createElement(r);
|
|
127
|
+
a.innerHTML = l.innerHTML;
|
|
128
|
+
for (let i = 0; i < l.attributes.length; i++) {
|
|
129
|
+
const d = l.attributes[i];
|
|
130
|
+
a.setAttribute(d.name, d.value);
|
|
131
|
+
}
|
|
132
|
+
l.parentNode?.replaceChild(a, l);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
p();
|
|
136
|
+
}, j = () => {
|
|
137
|
+
const e = f();
|
|
138
|
+
if (!e) return;
|
|
139
|
+
e.table.remove(), document.dispatchEvent(new CustomEvent("tableDeleted"));
|
|
140
|
+
}, G = () => {
|
|
141
|
+
const e = window.getSelection();
|
|
142
|
+
if (!e || e.rangeCount === 0) return;
|
|
143
|
+
const n = e.getRangeAt(0).startContainer;
|
|
144
|
+
if (!(n.nodeType === Node.TEXT_NODE ? n.parentElement?.closest("table") : n.closest("table"))) return;
|
|
145
|
+
let l = null;
|
|
146
|
+
if (n.nodeType === Node.TEXT_NODE ? l = n.parentElement?.closest("td, th") : n.nodeType === Node.ELEMENT_NODE && (l = n.closest("td, th")), !l) return;
|
|
147
|
+
const r = l.parentElement;
|
|
148
|
+
if (!r) return;
|
|
149
|
+
let a = -1;
|
|
150
|
+
for (let u = 0; u < r.cells.length; u++)
|
|
151
|
+
if (r.cells[u] === l) {
|
|
152
|
+
a = u;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
if (a === -1 || a === r.cells.length - 1) return;
|
|
156
|
+
const i = r.cells[a + 1];
|
|
157
|
+
if (!i) return;
|
|
158
|
+
const d = parseInt(l.getAttribute("colspan") || "1"), c = parseInt(i.getAttribute("colspan") || "1");
|
|
159
|
+
l.setAttribute("colspan", String(d + c)), Array.from(i.childNodes).forEach((u) => {
|
|
160
|
+
l.appendChild(u);
|
|
161
|
+
}), i.remove(), p();
|
|
162
|
+
};
|
|
163
|
+
function f() {
|
|
164
|
+
const e = window.getSelection();
|
|
165
|
+
if (!e || e.rangeCount === 0) return null;
|
|
166
|
+
const n = e.getRangeAt(0).startContainer;
|
|
167
|
+
let o = n.nodeType === Node.TEXT_NODE ? n.parentElement?.closest("table") : n.closest("table");
|
|
168
|
+
if (!o) return null;
|
|
169
|
+
const l = o;
|
|
170
|
+
let r = 0, a = 0;
|
|
171
|
+
const i = n.nodeType === Node.TEXT_NODE ? n.parentElement?.closest("td, th") : n.closest("td, th");
|
|
172
|
+
if (i) {
|
|
173
|
+
let d = i.parentElement;
|
|
174
|
+
for (; d && d !== l.rows[r] && (r++, !(r >= l.rows.length)); )
|
|
175
|
+
;
|
|
176
|
+
const c = d;
|
|
177
|
+
if (c) {
|
|
178
|
+
for (let s = 0; s < c.cells.length; s++)
|
|
179
|
+
if (c.cells[s] === i) {
|
|
180
|
+
a = s;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
table: l,
|
|
187
|
+
rowIndex: r,
|
|
188
|
+
colIndex: a,
|
|
189
|
+
rowCount: l.rows.length,
|
|
190
|
+
cellCount: l.rows[0]?.cells.length || 0
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function p() {
|
|
194
|
+
if (!h || !m) return;
|
|
195
|
+
const e = f();
|
|
196
|
+
if (!e) return;
|
|
197
|
+
const t = e.rowCount > 1, n = e.cellCount > 1;
|
|
198
|
+
N(t, n);
|
|
199
|
+
}
|
|
200
|
+
function J() {
|
|
201
|
+
R = () => {
|
|
202
|
+
const e = f();
|
|
203
|
+
e ? Q(e.table) : E();
|
|
204
|
+
}, x = (e) => {
|
|
205
|
+
const t = e.target, n = t.closest("table"), o = t.closest(".table-toolbar");
|
|
206
|
+
!n && !o && E();
|
|
207
|
+
}, I = () => {
|
|
208
|
+
E();
|
|
209
|
+
}, S = () => {
|
|
210
|
+
m && h && h.style.display !== "none" && y(m);
|
|
211
|
+
}, M = () => {
|
|
212
|
+
m && h && h.style.display !== "none" && y(m);
|
|
213
|
+
}, document.addEventListener("selectionchange", R), document.addEventListener("mousedown", x), document.addEventListener("tableDeleted", I), window.addEventListener("scroll", S, !0), window.addEventListener("resize", M);
|
|
214
|
+
}
|
|
215
|
+
function y(e) {
|
|
216
|
+
if (!h) return;
|
|
217
|
+
const t = e.getBoundingClientRect(), n = h.getBoundingClientRect(), o = n.height || 40, l = n.width || 280, r = 10;
|
|
218
|
+
let a = t.top - o - r, i = t.left + t.width / 2 - l / 2;
|
|
219
|
+
a < r && (a = t.bottom + r), i < r && (i = r);
|
|
220
|
+
const d = window.innerWidth;
|
|
221
|
+
i + l > d - r && (i = d - l - r);
|
|
222
|
+
const c = window.innerHeight;
|
|
223
|
+
a + o > c - r && (a = c - o - r), h.style.top = a + "px", h.style.left = i + "px";
|
|
224
|
+
}
|
|
225
|
+
function Q(e) {
|
|
226
|
+
m = e, h || (h = Z(), document.body.appendChild(h));
|
|
227
|
+
const t = !!e.closest(w) || document.body.matches(w) || document.documentElement.matches(w);
|
|
228
|
+
h.classList.toggle("rte-theme-dark", t), h.style.display = "flex", h.style.visibility = "hidden", requestAnimationFrame(() => {
|
|
229
|
+
y(e), h && (h.style.visibility = "visible");
|
|
230
|
+
});
|
|
231
|
+
const n = f();
|
|
232
|
+
n && N(n.rowCount > 1, n.cellCount > 1), ee(e);
|
|
233
|
+
}
|
|
234
|
+
function E() {
|
|
235
|
+
if (h && (h.style.display = "none"), m) {
|
|
236
|
+
m.querySelectorAll(".resize-handle").forEach((n) => n.remove());
|
|
237
|
+
const t = m.querySelector(".table-resize-handle");
|
|
238
|
+
t && t.remove();
|
|
239
|
+
}
|
|
240
|
+
m = null;
|
|
241
|
+
}
|
|
242
|
+
function N(e, t) {
|
|
243
|
+
if (!h) return;
|
|
244
|
+
const n = h.querySelector('[data-action="deleteRow"]'), o = h.querySelector('[data-action="deleteColumn"]');
|
|
245
|
+
n && (n.disabled = !e), o && (o.disabled = !t);
|
|
246
|
+
}
|
|
247
|
+
function Z() {
|
|
248
|
+
const e = document.createElement("div");
|
|
249
|
+
e.className = "table-toolbar", e.style.cssText = `
|
|
250
|
+
position: fixed;
|
|
251
|
+
z-index: 1000;
|
|
252
|
+
display: none;
|
|
253
|
+
`, e.setAttribute("role", "toolbar"), e.setAttribute("aria-label", "Table editing toolbar");
|
|
254
|
+
const t = (s) => {
|
|
255
|
+
const u = document.createElement("button");
|
|
256
|
+
return u.className = "toolbar-icon-btn", s.danger && u.classList.add("toolbar-icon-btn-danger"), s.delete && u.classList.add("toolbar-icon-btn-delete"), u.innerHTML = s.icon, u.title = s.title, u.setAttribute("aria-label", s.title), u.setAttribute("type", "button"), u.setAttribute("data-action", s.action), u.onclick = () => $(s.action), u;
|
|
257
|
+
}, n = () => {
|
|
258
|
+
const s = document.createElement("div");
|
|
259
|
+
return s.className = "toolbar-divider", s;
|
|
260
|
+
}, o = (...s) => {
|
|
261
|
+
const u = document.createElement("div");
|
|
262
|
+
return u.className = "toolbar-section", s.forEach((v) => u.appendChild(v)), u;
|
|
263
|
+
}, l = o(
|
|
264
|
+
t({
|
|
265
|
+
icon: oe(),
|
|
266
|
+
title: "Add row above (Ctrl+Shift+R)",
|
|
267
|
+
action: "addRowAbove"
|
|
268
|
+
}),
|
|
269
|
+
t({
|
|
270
|
+
icon: le(),
|
|
271
|
+
title: "Add row below",
|
|
272
|
+
action: "addRowBelow"
|
|
273
|
+
}),
|
|
274
|
+
t({
|
|
275
|
+
icon: re(),
|
|
276
|
+
title: "Delete row",
|
|
277
|
+
action: "deleteRow",
|
|
278
|
+
danger: !0
|
|
279
|
+
})
|
|
280
|
+
), r = o(
|
|
281
|
+
t({
|
|
282
|
+
icon: ae(),
|
|
283
|
+
title: "Add column left",
|
|
284
|
+
action: "addColumnLeft"
|
|
285
|
+
}),
|
|
286
|
+
t({
|
|
287
|
+
icon: ie(),
|
|
288
|
+
title: "Add column right (Ctrl+Shift+C)",
|
|
289
|
+
action: "addColumnRight"
|
|
290
|
+
}),
|
|
291
|
+
t({
|
|
292
|
+
icon: se(),
|
|
293
|
+
title: "Delete column",
|
|
294
|
+
action: "deleteColumn",
|
|
295
|
+
danger: !0
|
|
296
|
+
})
|
|
297
|
+
), a = o(
|
|
298
|
+
t({
|
|
299
|
+
icon: de(),
|
|
300
|
+
title: "Toggle header row",
|
|
301
|
+
action: "toggleHeaderRow"
|
|
302
|
+
}),
|
|
303
|
+
t({
|
|
304
|
+
icon: ce(),
|
|
305
|
+
title: "Toggle header column",
|
|
306
|
+
action: "toggleHeaderColumn"
|
|
307
|
+
})
|
|
308
|
+
), i = o(
|
|
309
|
+
t({
|
|
310
|
+
icon: he(),
|
|
311
|
+
title: "Merge cells (horizontally)",
|
|
312
|
+
action: "mergeCells"
|
|
313
|
+
})
|
|
314
|
+
), d = o(
|
|
315
|
+
t({
|
|
316
|
+
icon: ue(),
|
|
317
|
+
title: "Delete table",
|
|
318
|
+
action: "deleteTable",
|
|
319
|
+
delete: !0
|
|
320
|
+
})
|
|
321
|
+
);
|
|
322
|
+
e.appendChild(l), e.appendChild(n()), e.appendChild(r), e.appendChild(n()), e.appendChild(a), e.appendChild(n()), e.appendChild(i), e.appendChild(n()), e.appendChild(d);
|
|
323
|
+
const c = (s) => {
|
|
324
|
+
!h || h.style.display === "none" || (s.ctrlKey || s.metaKey) && s.shiftKey && (s.key === "r" || s.key === "R" ? (s.preventDefault(), H()) : (s.key === "c" || s.key === "C") && (s.preventDefault(), z()));
|
|
325
|
+
};
|
|
326
|
+
return window.addEventListener("keydown", c), e;
|
|
327
|
+
}
|
|
328
|
+
function $(e) {
|
|
329
|
+
switch (e) {
|
|
330
|
+
case "addRowAbove":
|
|
331
|
+
P();
|
|
332
|
+
break;
|
|
333
|
+
case "addRowBelow":
|
|
334
|
+
H();
|
|
335
|
+
break;
|
|
336
|
+
case "addColumnLeft":
|
|
337
|
+
W();
|
|
338
|
+
break;
|
|
339
|
+
case "addColumnRight":
|
|
340
|
+
z();
|
|
341
|
+
break;
|
|
342
|
+
case "deleteRow":
|
|
343
|
+
K();
|
|
344
|
+
break;
|
|
345
|
+
case "deleteColumn":
|
|
346
|
+
Y();
|
|
347
|
+
break;
|
|
348
|
+
case "toggleHeaderRow":
|
|
349
|
+
F();
|
|
350
|
+
break;
|
|
351
|
+
case "toggleHeaderColumn":
|
|
352
|
+
U();
|
|
353
|
+
break;
|
|
354
|
+
case "deleteTable":
|
|
355
|
+
j();
|
|
356
|
+
break;
|
|
357
|
+
case "mergeCells":
|
|
358
|
+
G();
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function ee(e) {
|
|
363
|
+
e.querySelectorAll(".resize-handle").forEach((a) => a.remove());
|
|
364
|
+
const n = e.querySelector(".table-resize-handle");
|
|
365
|
+
n && n.remove();
|
|
366
|
+
const o = e.querySelector("thead tr, tbody tr:first-child");
|
|
367
|
+
if (!o) return;
|
|
368
|
+
const l = o.querySelectorAll("td, th");
|
|
369
|
+
l.forEach((a, i) => {
|
|
370
|
+
if (i === l.length - 1) return;
|
|
371
|
+
const d = document.createElement("div");
|
|
372
|
+
d.className = "resize-handle", d.style.cssText = `
|
|
373
|
+
position: absolute;
|
|
374
|
+
right: -4px;
|
|
375
|
+
top: 0;
|
|
376
|
+
bottom: 0;
|
|
377
|
+
width: 8px;
|
|
378
|
+
background: transparent;
|
|
379
|
+
cursor: col-resize;
|
|
380
|
+
z-index: 10;
|
|
381
|
+
transition: background 0.15s ease;
|
|
382
|
+
`, d.addEventListener("mouseenter", () => {
|
|
383
|
+
g || (d.style.background = "rgba(0, 102, 204, 0.3)");
|
|
384
|
+
}), d.addEventListener("mouseleave", () => {
|
|
385
|
+
g || (d.style.background = "transparent");
|
|
386
|
+
}), d.addEventListener("mousedown", (c) => {
|
|
387
|
+
c.preventDefault(), c.stopPropagation(), te(c, i);
|
|
388
|
+
}), a.style.position = "relative", a.appendChild(d);
|
|
389
|
+
});
|
|
390
|
+
const r = document.createElement("div");
|
|
391
|
+
r.className = "table-resize-handle", r.addEventListener("mousedown", (a) => {
|
|
392
|
+
a.preventDefault(), a.stopPropagation(), ne(a);
|
|
393
|
+
}), e.appendChild(r);
|
|
394
|
+
}
|
|
395
|
+
function te(e, t) {
|
|
396
|
+
if (g = !0, b = t, V = e.clientX, !m) return;
|
|
397
|
+
const n = m.querySelector("thead tr, tbody tr:first-child");
|
|
398
|
+
n && n.cells[t] && (L = n.cells[t].offsetWidth), document.body.style.cursor = "col-resize", document.body.style.userSelect = "none";
|
|
399
|
+
const o = (r) => {
|
|
400
|
+
if (!g || b === null || !m) return;
|
|
401
|
+
const a = r.clientX - V, i = Math.max(50, L + a);
|
|
402
|
+
m.querySelectorAll("tr").forEach((c) => {
|
|
403
|
+
c.cells[b] && (c.cells[b].style.width = i + "px");
|
|
404
|
+
});
|
|
405
|
+
}, l = () => {
|
|
406
|
+
g = !1, b = null, document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove", o), document.removeEventListener("mouseup", l);
|
|
407
|
+
};
|
|
408
|
+
document.addEventListener("mousemove", o), document.addEventListener("mouseup", l);
|
|
409
|
+
}
|
|
410
|
+
function ne(e) {
|
|
411
|
+
if (!m) return;
|
|
412
|
+
C = !0, A = e.clientX, k = e.clientY, B = m.offsetWidth, D = m.offsetHeight, document.body.style.cursor = "nwse-resize", document.body.style.userSelect = "none";
|
|
413
|
+
const t = (o) => {
|
|
414
|
+
if (!C || !m) return;
|
|
415
|
+
const l = o.clientX - A, r = o.clientY - k, a = Math.max(200, B + l), i = Math.max(100, D + r);
|
|
416
|
+
m.style.width = a + "px", m.style.height = i + "px";
|
|
417
|
+
}, n = () => {
|
|
418
|
+
C = !1, document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove", t), document.removeEventListener("mouseup", n);
|
|
419
|
+
};
|
|
420
|
+
document.addEventListener("mousemove", t), document.addEventListener("mouseup", n);
|
|
421
|
+
}
|
|
422
|
+
function oe() {
|
|
423
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
424
|
+
<path d="M2 7h12V5H2v2zm0 4h12V9H2v2zM8 1v3H5v2h3v3h2V6h3V4h-3V1H8z"/>
|
|
425
|
+
</svg>`;
|
|
426
|
+
}
|
|
427
|
+
function le() {
|
|
428
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
429
|
+
<path d="M2 3h12V1H2v2zm0 4h12V5H2v2zm6 4v3h3v-2h2v-2h-2v-3h-2v3H5v2h3z"/>
|
|
430
|
+
</svg>`;
|
|
431
|
+
}
|
|
432
|
+
function re() {
|
|
433
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
434
|
+
<path d="M2 5h12v2H2V5zm0 4h12v2H2V9zm4-6v2H4v2h2v2h2V7h2V5H8V3H6z"/>
|
|
435
|
+
</svg>`;
|
|
436
|
+
}
|
|
437
|
+
function ae() {
|
|
438
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
439
|
+
<path d="M7 2v12h2V2H7zm4 0v12h2V2h-2zM1 8h3v-3H1v3zm3 2H1v3h3v-3z"/>
|
|
440
|
+
</svg>`;
|
|
441
|
+
}
|
|
442
|
+
function ie() {
|
|
443
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
444
|
+
<path d="M2 2v12h2V2H2zm4 0v12h2V2H6zM12 8h3v-3h-3v3zm0 2h3v3h-3v-3z"/>
|
|
445
|
+
</svg>`;
|
|
446
|
+
}
|
|
447
|
+
function se() {
|
|
448
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
449
|
+
<path d="M5 2v12h2V2H5zm4 0v12h2V2H9zm3 2h3V1h-3v3zm3 2h-3v3h3V6zm0 4h-3v3h3v-3z"/>
|
|
450
|
+
</svg>`;
|
|
451
|
+
}
|
|
452
|
+
function de() {
|
|
453
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
454
|
+
<path d="M2 2h12v3H2V2zm0 5h12v8H2V7zm2 2v4h2V9H4zm4 0v4h2V9H8zm4 0v4h2V9h-2z"/>
|
|
455
|
+
</svg>`;
|
|
456
|
+
}
|
|
457
|
+
function ce() {
|
|
458
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
459
|
+
<path d="M2 2v12h3V2H2zm5 0v12h8V2H7zm2 2h4v2H9V4zm0 4h4v2H9V8zm0 4h4v2H9v-2z"/>
|
|
460
|
+
</svg>`;
|
|
461
|
+
}
|
|
462
|
+
function ue() {
|
|
463
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
464
|
+
<path d="M3 1h10v1H3V1zm1 2v11h8V3H4zM6 5h1v6H6V5zm3 0h1v6H9V5z"/>
|
|
465
|
+
</svg>`;
|
|
466
|
+
}
|
|
467
|
+
function he() {
|
|
468
|
+
return `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
469
|
+
<path d="M2 2h4v3H2V2zm5 0h4v3H7V2zm5 0h2v3h-2V2zm-10 4h4v3H2V6zm5 0h4v3H7V6zm5 0h2v3h-2V6zm-10 4h4v3H2v-3zm5 0h4v3H7v-3zm5 0h2v3h-2v-3z"/>
|
|
470
|
+
</svg>`;
|
|
471
|
+
}
|
|
472
|
+
if (typeof window < "u" && !window.__tablePluginInitialized) {
|
|
473
|
+
window.__tablePluginInitialized = !0;
|
|
474
|
+
const e = () => {
|
|
475
|
+
J();
|
|
476
|
+
};
|
|
477
|
+
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", e) : setTimeout(e, 100);
|
|
478
|
+
}
|
|
479
|
+
const me = () => ({
|
|
480
|
+
name: "table",
|
|
481
|
+
toolbar: [
|
|
482
|
+
{
|
|
483
|
+
label: "Insert Table",
|
|
484
|
+
command: "insertTable",
|
|
485
|
+
icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="3" y="4" width="18" height="16" rx="2" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="M3 10h18M3 15h18M9 4v16M15 4v16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>'
|
|
486
|
+
}
|
|
487
|
+
],
|
|
488
|
+
commands: {
|
|
489
|
+
insertTable: () => (O(), !0)
|
|
490
|
+
},
|
|
491
|
+
keymap: {
|
|
492
|
+
"Mod-Shift-r": () => (H(), !0),
|
|
493
|
+
"Mod-Shift-c": () => (z(), !0)
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
export {
|
|
497
|
+
me as TablePlugin
|
|
498
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.rte-table,table{border-collapse:collapse;width:100%;margin:1rem 0;border:1px solid #ddd;font-size:14px;line-height:1.4;position:relative}.rte-table td,.rte-table th,table td,table th{border:1px solid #ddd;padding:8px 12px;min-width:80px;vertical-align:top;position:relative;-webkit-user-select:none;user-select:none}.rte-table td:focus,.rte-table th:focus,table td:focus,table th:focus{outline:2px solid #007acc;outline-offset:-2px}.rte-table th,table th{background-color:#f8f9fa;font-weight:600;text-align:left}.rte-table td p,table td p{margin:0;padding:0}.rte-table td p:empty:before,table td p:empty:before{content:"";display:inline-block}.rte-table td[contenteditable]:empty:before,table td[contenteditable]:empty:before{content:"Type here...";color:#999;font-style:italic;pointer-events:none}.rte-table tr:hover,table tr:hover{background-color:#f8f9fa}.rte-table td.selected,table td.selected{background-color:#e3f2fd;border-color:#2196f3}.table-toolbar{background:#fff;border:1px solid #d0d0d0;border-radius:4px;box-shadow:0 2px 8px #0000001a;padding:4px;display:flex;align-items:center;gap:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;min-width:max-content}.toolbar-section{display:flex;align-items:center;gap:2px}.toolbar-divider{width:1px;height:20px;background:#e0e0e0;margin:0 4px}.toolbar-icon-btn{display:flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:1px solid transparent;background:transparent;cursor:pointer;color:#333;border-radius:3px;transition:all .2s ease;flex-shrink:0;font-size:14px;line-height:1}.toolbar-icon-btn svg{width:16px;height:16px}.toolbar-icon-btn:hover:not(:disabled){background:#f0f0f0;border-color:#d0d0d0;color:#06c}.toolbar-icon-btn:active:not(:disabled){background:#e8f0ff;border-color:#06c;transform:scale(.95)}.toolbar-icon-btn:disabled{opacity:.4;cursor:not-allowed;color:#ccc}.toolbar-icon-btn-danger{color:#d32f2f}.toolbar-icon-btn-danger:hover:not(:disabled){background:#fff3f3;border-color:#fcc;color:#d32f2f}.toolbar-icon-btn-danger:active:not(:disabled){background:#ffebee}.toolbar-icon-btn-delete{color:#d32f2f}.toolbar-icon-btn-delete:hover:not(:disabled){background:#fff3f3;border-color:#fcc;color:#d32f2f}.toolbar-icon-btn-delete:active:not(:disabled){background:#ffebee}.resize-handle{opacity:0;transition:all .15s ease}.resize-handle:hover{opacity:1}td:hover>.resize-handle,th:hover>.resize-handle{opacity:1}.table-resize-handle{position:absolute;bottom:-4px;right:-4px;width:12px;height:12px;background:transparent;cursor:nwse-resize;z-index:10;transition:background .15s ease}.table-resize-handle:after{content:"";position:absolute;bottom:0;right:0;width:8px;height:8px;background:#0066cc4d;border-bottom:2px solid #0066cc;border-right:2px solid #0066cc;border-radius:0 0 2px;opacity:0;transition:opacity .15s ease}.table-resize-handle:hover:after{opacity:1}.rte-table:hover .table-resize-handle:after,table:hover .table-resize-handle:after{opacity:1}:is([data-theme=dark],.dark,.editora-theme-dark) :is(.rte-table,table){border-color:#607088;background:#24303c;color:#e6eefb}:is([data-theme=dark],.dark,.editora-theme-dark) :is(.rte-table td,.rte-table th,table td,table th){border-color:#607088;color:#e6eefb}:is([data-theme=dark],.dark,.editora-theme-dark) :is(.rte-table th,table th){background:linear-gradient(180deg,#3b4553,#333d4a);color:#f3f8ff}:is([data-theme=dark],.dark,.editora-theme-dark) :is(.rte-table tr:hover,table tr:hover){background-color:#58a6ff1f}:is([data-theme=dark],.dark,.editora-theme-dark) :is(.rte-table td.selected,table td.selected){background-color:#58a6ff47;border-color:#79beff}:is([data-theme=dark],.dark,.editora-theme-dark) :is(.rte-table td[contenteditable]:empty:before,table td[contenteditable]:empty:before){color:#94a3b8}:is([data-theme=dark],.dark,.editora-theme-dark) .table-toolbar{background:linear-gradient(180deg,#2f3844,#2a323c);border-color:#4d596b;box-shadow:0 8px 20px #00000073}.table-toolbar.rte-theme-dark{background:linear-gradient(180deg,#2f3844,#2a323c);border-color:#4d596b;box-shadow:0 8px 20px #00000073}:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-divider{background:#4d596b}.table-toolbar.rte-theme-dark .toolbar-divider{background:#4d596b}:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn{color:#d7deea;border-color:transparent}.table-toolbar.rte-theme-dark .toolbar-icon-btn{color:#d7deea;border-color:transparent}:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn svg{color:currentColor;fill:currentColor}.table-toolbar.rte-theme-dark .toolbar-icon-btn svg{color:currentColor;fill:currentColor}:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn svg [stroke="#000" i],:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn svg [stroke="#000000" i],:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn svg [stroke=black i]{stroke:currentColor!important}.table-toolbar.rte-theme-dark .toolbar-icon-btn svg [stroke="#000" i],.table-toolbar.rte-theme-dark .toolbar-icon-btn svg [stroke="#000000" i],.table-toolbar.rte-theme-dark .toolbar-icon-btn svg [stroke=black i]{stroke:currentColor!important}:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn svg [fill="#000" i],:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn svg [fill="#000000" i],:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn svg [fill=black i]{fill:currentColor!important}.table-toolbar.rte-theme-dark .toolbar-icon-btn svg [fill="#000" i],.table-toolbar.rte-theme-dark .toolbar-icon-btn svg [fill="#000000" i],.table-toolbar.rte-theme-dark .toolbar-icon-btn svg [fill=black i]{fill:currentColor!important}:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn:hover:not(:disabled){background:#3a4554;border-color:#607088;color:#f3f8ff}.table-toolbar.rte-theme-dark .toolbar-icon-btn:hover:not(:disabled){background:#3a4554;border-color:#607088;color:#f3f8ff}:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn:active:not(:disabled){background:#4a95de;border-color:#67adf4;color:#0f1b2a}.table-toolbar.rte-theme-dark .toolbar-icon-btn:active:not(:disabled){background:#4a95de;border-color:#67adf4;color:#0f1b2a}:is([data-theme=dark],.dark,.editora-theme-dark) .toolbar-icon-btn:disabled{color:#7f8ca1}.table-toolbar.rte-theme-dark .toolbar-icon-btn:disabled{color:#7f8ca1}@media(max-width:768px){.rte-table,table{font-size:12px}.rte-table td,.rte-table th,table td,table th{padding:4px 6px;min-width:60px}.table-toolbar{padding:3px;gap:0;max-width:90vw;overflow-x:auto}.toolbar-icon-btn{width:26px;height:26px}.toolbar-divider{height:18px}}@media print{.rte-table,table{border:1px solid #000}.rte-table td,.rte-table th,table td,table th{border:1px solid #000;padding:4px}.table-toolbar{display:none}}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@editora/plugin-table",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Table plugin for Rich Text Editor",
|
|
5
|
+
"authors": [
|
|
6
|
+
"Ajay Kumar <ajaykr089@gmail.com>"
|
|
7
|
+
],
|
|
8
|
+
"main": "dist/index.cjs.js",
|
|
9
|
+
"module": "dist/index.esm.js",
|
|
10
|
+
"types": "src/index.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "vite build",
|
|
17
|
+
"dev": "vite build --watch",
|
|
18
|
+
"clean": "rm -rf dist"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@editora/core": "^1.0.5"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.0.0",
|
|
25
|
+
"vite": "^7.3.1"
|
|
26
|
+
}
|
|
27
|
+
}
|