@editora/plugins 1.0.8 → 1.0.10
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 +27 -0
- package/dist/_commonjsHelpers-6763f629.js +1 -0
- package/dist/_commonjsHelpers-c5d32002.mjs +30 -0
- package/dist/a11y-checker.cjs.js +12 -12
- package/dist/a11y-checker.esm.js +98 -80
- package/dist/anchor.cjs.js +12 -12
- package/dist/anchor.esm.js +128 -115
- package/dist/anchoredPopover-33f1358d.mjs +109 -0
- package/dist/anchoredPopover-8151d535.js +1 -0
- package/dist/approval-workflow.cjs.js +447 -0
- package/dist/approval-workflow.esm.js +1111 -0
- package/dist/background-color.cjs.js +2 -2
- package/dist/background-color.esm.js +68 -55
- package/dist/blockquote.esm.js +2 -1
- package/dist/blocks-library.cjs.js +442 -0
- package/dist/blocks-library.esm.js +1384 -0
- package/dist/capitalization.esm.js +2 -1
- package/dist/checklist.cjs.js +1 -1
- package/dist/checklist.esm.js +82 -58
- package/dist/citations.cjs.js +548 -0
- package/dist/citations.esm.js +1530 -0
- package/dist/clear-formatting.cjs.js +1 -1
- package/dist/clear-formatting.esm.js +33 -27
- package/dist/code-sample.cjs.js +14 -14
- package/dist/code-sample.esm.js +93 -82
- package/dist/code.cjs.js +32 -32
- package/dist/code.esm.js +653 -594
- package/dist/comments.cjs.js +6 -6
- package/dist/comments.esm.js +158 -116
- package/dist/conditional-content.cjs.js +626 -0
- package/dist/conditional-content.esm.js +1421 -0
- package/dist/content-rules.cjs.js +408 -0
- package/dist/content-rules.esm.js +1147 -0
- package/dist/data-binding.cjs.js +321 -0
- package/dist/data-binding.esm.js +953 -0
- package/dist/direction.esm.js +18 -9
- package/dist/doc-schema.cjs.js +398 -0
- package/dist/doc-schema.esm.js +1378 -0
- package/dist/document-manager.cjs.js +1 -1
- package/dist/document-manager.esm.js +5 -4
- package/dist/documentManager-25b6203c.mjs +9122 -0
- package/dist/documentManager-b69e7054.js +17 -0
- package/dist/{editorContainerHelpers-C7kdWnS0.mjs → editorContainerHelpers-69585c07.mjs} +2 -1
- package/dist/embed-iframe.cjs.js +4 -4
- package/dist/embed-iframe.esm.js +81 -73
- package/dist/emojis.cjs.js +8 -8
- package/dist/emojis.esm.js +77 -65
- package/dist/enterprise.cjs.js +1 -0
- package/dist/enterprise.esm.js +58 -0
- package/dist/font-family.cjs.js +1 -1
- package/dist/font-family.esm.js +47 -39
- package/dist/font-size.cjs.js +1 -1
- package/dist/font-size.esm.js +53 -37
- package/dist/footnote.cjs.js +2 -2
- package/dist/footnote.esm.js +117 -76
- package/dist/history.cjs.js +1 -1
- package/dist/history.esm.js +92 -70
- package/dist/html2canvas.esm-09133e29.js +22 -0
- package/dist/{html2canvas.esm-BWVIUcAF.mjs → html2canvas.esm-1a1724a1.mjs} +225 -141
- package/dist/indent.cjs.js +1 -1
- package/dist/indent.esm.js +24 -12
- package/dist/index-656d224b.js +231 -0
- package/dist/index-6a8c48bb.js +1 -0
- package/dist/index-d027b7e2.mjs +16859 -0
- package/dist/{index-BFsKNTTj.mjs → index-f04538f2.mjs} +71 -70
- package/dist/index.cjs.js +1 -1
- package/dist/index.es-730f2d98.mjs +5775 -0
- package/dist/index.es-dd40173b.js +18 -0
- package/dist/index.esm.js +124 -93
- package/dist/italic.cjs.js +1 -1
- package/dist/italic.esm.js +9 -8
- package/dist/jspdf.es.min-90db2c97.js +243 -0
- package/dist/{jspdf.es.min-DQCoX5yh.mjs → jspdf.es.min-c36a4fd8.mjs} +4682 -3658
- package/dist/line-height.cjs.js +1 -1
- package/dist/line-height.esm.js +24 -11
- package/dist/link.cjs.js +5 -5
- package/dist/link.esm.js +30 -24
- package/dist/list.cjs.js +1 -1
- package/dist/list.esm.js +25 -20
- package/dist/lite.cjs.js +1 -1
- package/dist/lite.esm.js +61 -59
- package/dist/math.cjs.js +21 -21
- package/dist/math.esm.js +146 -139
- package/dist/media-manager.cjs.js +38 -38
- package/dist/media-manager.esm.js +325 -308
- package/dist/mentions.cjs.js +105 -0
- package/dist/mentions.esm.js +774 -0
- package/dist/merge-tag.cjs.js +2 -2
- package/dist/merge-tag.esm.js +216 -177
- package/dist/page-break.cjs.js +2 -2
- package/dist/page-break.esm.js +67 -51
- package/dist/pii-redaction.cjs.js +436 -0
- package/dist/pii-redaction.esm.js +1447 -0
- package/dist/preview.cjs.js +3 -3
- package/dist/preview.esm.js +37 -32
- package/dist/print.cjs.js +4 -4
- package/dist/print.esm.js +20 -17
- package/dist/{purify.es-DHhaBdbu.mjs → purify.es-35a15df8.mjs} +19 -9
- package/dist/{purify.es-T2a3nLiC.js → purify.es-a8d731c6.js} +1 -1
- package/dist/slash-commands.cjs.js +90 -0
- package/dist/slash-commands.esm.js +788 -0
- package/dist/smart-paste.cjs.js +398 -0
- package/dist/smart-paste.esm.js +1444 -0
- package/dist/special-characters.cjs.js +7 -7
- package/dist/special-characters.esm.js +69 -61
- package/dist/spell-check.cjs.js +5 -5
- package/dist/spell-check.esm.js +123 -97
- package/dist/strikethrough.cjs.js +1 -1
- package/dist/strikethrough.esm.js +19 -14
- package/dist/style.css +1 -0
- package/dist/table.cjs.js +4 -4
- package/dist/table.esm.js +225 -191
- package/dist/template.cjs.js +11 -11
- package/dist/template.esm.js +153 -124
- package/dist/text-alignment.cjs.js +1 -1
- package/dist/text-alignment.esm.js +27 -21
- package/dist/text-color.cjs.js +3 -3
- package/dist/text-color.esm.js +87 -70
- package/dist/track-changes.cjs.js +77 -0
- package/dist/track-changes.esm.js +817 -0
- package/dist/translation-workflow.cjs.js +626 -0
- package/dist/translation-workflow.esm.js +1794 -0
- package/dist/version-diff.cjs.js +362 -0
- package/dist/version-diff.esm.js +797 -0
- package/index.d.ts +798 -0
- package/package.json +114 -9
- package/dist/_commonjsHelpers-BH3jXuIh.js +0 -1
- package/dist/_commonjsHelpers-ByX85dGu.mjs +0 -33
- package/dist/anchoredPopover-BzqGPOAE.js +0 -1
- package/dist/anchoredPopover-Dts0IrgU.mjs +0 -106
- package/dist/documentManager-CTqRftU8.mjs +0 -8369
- package/dist/documentManager-Jf0RbSks.js +0 -17
- package/dist/html2canvas.esm-B5qzocYs.js +0 -5
- package/dist/index-CvJk4DKa.js +0 -221
- package/dist/index-D3CycEFU.mjs +0 -16543
- package/dist/index-tqLTHcO6.js +0 -1
- package/dist/index.es-CE_A4QSm.js +0 -5
- package/dist/index.es-DQ78mYYo.mjs +0 -6665
- package/dist/jspdf.es.min-BoS80556.js +0 -77
- package/dist/plugins.css +0 -1
- /package/dist/{editorContainerHelpers-CFbfiOJI.js → editorContainerHelpers-36b8ddf3.js} +0 -0
package/dist/anchor.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("./editorContainerHelpers-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("./editorContainerHelpers-36b8ddf3.js"),h=new Set,y='[data-theme="dark"], .dark, .editora-theme-dark';function $(t,l){if(l===t.innerHTML)return;const s=window.execEditorCommand||window.executeEditorCommand;if(typeof s=="function")try{s("recordDomTransaction",t,l,t.innerHTML)}catch{}}function z(){if(typeof window>"u"||window.__anchorObserverInitialized)return;window.__anchorObserverInitialized=!0,new MutationObserver(l=>{l.forEach(s=>{s.removedNodes.forEach(d=>{var a,e;if(d.nodeType===Node.ELEMENT_NODE){const i=d;if((a=i.classList)!=null&&a.contains("rte-anchor")){const r=i.id;r&&h.delete(r)}const u=(e=i.querySelectorAll)==null?void 0:e.call(i,".rte-anchor");u==null||u.forEach(r=>{const f=r.id;f&&h.delete(f)})}})})}).observe(document.body,{childList:!0,subtree:!0})}function S(t){return!t||t.trim().length===0?{valid:!1,error:"Anchor ID cannot be empty"}:t.length>256?{valid:!1,error:"Anchor ID must be less than 256 characters"}:/^[a-z_]/.test(t)?/^[a-z0-9\-_]+$/.test(t)?{valid:!0,error:""}:{valid:!1,error:"Anchor ID can only contain letters, numbers, hyphens, and underscores"}:{valid:!1,error:"Anchor ID must start with a letter or underscore"}}function M(){const t=w.findEditorContainerFromSelection();if(!t)return;const l=w.getContentElement(t);if(!l)return;const s=l.querySelectorAll(".rte-anchor"),d=new Set;s.forEach(a=>{const e=a.id;e&&d.add(e)}),h.clear(),d.forEach(a=>h.add(a))}function R(t){if(t){const d=t.startContainer,a=d.nodeType===Node.ELEMENT_NODE?d:d.parentElement;if(a!=null&&a.closest(y))return!0}const l=window.getSelection();if(l&&l.rangeCount>0){const d=l.getRangeAt(0).startContainer,a=d.nodeType===Node.ELEMENT_NODE?d:d.parentElement;if(a!=null&&a.closest(y))return!0}const s=document.activeElement;return s!=null&&s.closest(y)?!0:document.body.matches(y)||document.documentElement.matches(y)}function H(t,l,s,d){M();const a=R(d),e=a?{overlay:"rgba(0, 0, 0, 0.62)",dialogBg:"#1f2937",panelBg:"#222d3a",border:"#3b4657",text:"#e2e8f0",muted:"#94a3b8",closeHoverBg:"#334155",fieldBg:"#111827",fieldFocusBg:"#111827",fieldBorder:"#4b5563",fieldText:"#e2e8f0",fieldPlaceholder:"#94a3b8",fieldErrorBg:"#3f2124",fieldErrorBorder:"#ef4444",cancelBg:"#334155",cancelHover:"#475569",cancelText:"#e2e8f0",saveBg:"#3b82f6",saveHover:"#2563eb",saveDisabledBg:"#374151",saveDisabledText:"#7f8ca1",help:"#9fb0c6",focusRing:"rgba(88, 166, 255, 0.25)",errorRing:"rgba(239, 68, 68, 0.25)"}:{overlay:"rgba(0, 0, 0, 0.5)",dialogBg:"#ffffff",panelBg:"#f9f9f9",border:"#e0e0e0",text:"#333333",muted:"#999999",closeHoverBg:"#e0e0e0",fieldBg:"#ffffff",fieldFocusBg:"#f9f9ff",fieldBorder:"#d0d0d0",fieldText:"#333333",fieldPlaceholder:"#9ca3af",fieldErrorBg:"#ffebee",fieldErrorBorder:"#d32f2f",cancelBg:"#f0f0f0",cancelHover:"#e0e0e0",cancelText:"#333333",saveBg:"#0066cc",saveHover:"#0052a3",saveDisabledBg:"#d0d0d0",saveDisabledText:"#999999",help:"#999999",focusRing:"rgba(0, 102, 204, 0.1)",errorRing:"rgba(211, 47, 47, 0.1)"},i=document.createElement("div");i.className="rte-anchor-dialog-overlay",i.style.cssText=`
|
|
2
2
|
position: fixed;
|
|
3
3
|
top: 0;
|
|
4
4
|
left: 0;
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
max-width: 450px;
|
|
20
20
|
overflow: hidden;
|
|
21
21
|
animation: rte-anchor-dialog-appear 0.2s ease;
|
|
22
|
-
`,!document.getElementById("rte-anchor-dialog-styles")){const
|
|
22
|
+
`,!document.getElementById("rte-anchor-dialog-styles")){const n=document.createElement("style");n.id="rte-anchor-dialog-styles",n.textContent=`
|
|
23
23
|
@keyframes rte-anchor-dialog-appear {
|
|
24
24
|
from { opacity: 0; transform: scale(0.95); }
|
|
25
25
|
to { opacity: 1; transform: scale(1); }
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
.rte-anchor-dialog input:focus {
|
|
28
28
|
outline: none !important;
|
|
29
29
|
}
|
|
30
|
-
`,document.head.appendChild(
|
|
30
|
+
`,document.head.appendChild(n)}let r="";const f=document.createElement("div");f.style.cssText=`
|
|
31
31
|
display: flex;
|
|
32
32
|
align-items: center;
|
|
33
33
|
justify-content: space-between;
|
|
34
34
|
padding: 16px 20px;
|
|
35
35
|
border-bottom: 1px solid ${e.border};
|
|
36
36
|
background: ${e.panelBg};
|
|
37
|
-
`;const C=document.createElement("h3");C.style.cssText=`margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`,C.textContent="Add Anchor";const
|
|
37
|
+
`;const C=document.createElement("h3");C.style.cssText=`margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`,C.textContent=t==="add"?"Add Anchor":"Edit Anchor";const p=document.createElement("button");p.textContent="✕",p.style.cssText=`
|
|
38
38
|
background: none;
|
|
39
39
|
border: none;
|
|
40
40
|
font-size: 24px;
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
justify-content: center;
|
|
49
49
|
border-radius: 4px;
|
|
50
50
|
transition: all 0.2s ease;
|
|
51
|
-
`,
|
|
51
|
+
`,p.onmouseover=()=>{p.style.background=e.closeHoverBg,p.style.color="#f8fafc"},p.onmouseout=()=>{p.style.background="none",p.style.color=e.muted},f.appendChild(C),f.appendChild(p);const B=document.createElement("div");B.style.cssText="padding: 20px;";const x=document.createElement("div");x.style.cssText="margin-bottom: 0;";const m=document.createElement("label");m.textContent="Anchor ID",m.style.cssText=`display: block; font-size: 14px; font-weight: 500; color: ${e.text}; margin-bottom: 8px;`,m.setAttribute("for","anchor-id-input");const o=document.createElement("input");o.id="anchor-id-input",o.type="text",o.placeholder="e.g., section-introduction",o.value=l||"",o.style.cssText=`
|
|
52
52
|
width: 100%;
|
|
53
53
|
padding: 10px 12px;
|
|
54
54
|
font-size: 14px;
|
|
@@ -59,19 +59,19 @@
|
|
|
59
59
|
background: ${e.fieldBg};
|
|
60
60
|
transition: all 0.2s ease;
|
|
61
61
|
box-sizing: border-box;
|
|
62
|
-
`,o.style.setProperty("caret-color",e.fieldText);const
|
|
62
|
+
`,o.style.setProperty("caret-color",e.fieldText);const g=document.createElement("div");g.style.cssText=`
|
|
63
63
|
color: #d32f2f;
|
|
64
64
|
font-size: 12px;
|
|
65
65
|
margin-top: 6px;
|
|
66
66
|
display: none;
|
|
67
|
-
`;const k=document.createElement("div");k.textContent="URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.",k.style.cssText=`color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`,
|
|
67
|
+
`;const k=document.createElement("div");k.textContent="URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.",k.style.cssText=`color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`,x.appendChild(m),x.appendChild(o),x.appendChild(g),x.appendChild(k),B.appendChild(x);const v=document.createElement("div");v.style.cssText=`
|
|
68
68
|
display: flex;
|
|
69
69
|
gap: 12px;
|
|
70
70
|
padding: 16px 20px;
|
|
71
71
|
border-top: 1px solid ${e.border};
|
|
72
72
|
background: ${e.panelBg};
|
|
73
73
|
justify-content: flex-end;
|
|
74
|
-
`;const
|
|
74
|
+
`;const b=document.createElement("button");b.textContent="Cancel",b.style.cssText=`
|
|
75
75
|
padding: 8px 16px;
|
|
76
76
|
font-size: 14px;
|
|
77
77
|
font-weight: 500;
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
transition: all 0.2s ease;
|
|
82
82
|
background: ${e.cancelBg};
|
|
83
83
|
color: ${e.cancelText};
|
|
84
|
-
`,
|
|
84
|
+
`,b.onmouseover=()=>b.style.background=e.cancelHover,b.onmouseout=()=>b.style.background=e.cancelBg;const c=document.createElement("button");c.textContent=t==="add"?"Add Anchor":"Save Changes",c.style.cssText=`
|
|
85
85
|
padding: 8px 16px;
|
|
86
86
|
font-size: 14px;
|
|
87
87
|
font-weight: 500;
|
|
@@ -91,11 +91,11 @@
|
|
|
91
91
|
transition: all 0.2s ease;
|
|
92
92
|
background: ${e.saveBg};
|
|
93
93
|
color: white;
|
|
94
|
-
`,
|
|
94
|
+
`,c.disabled=!o.value.trim();const N=()=>{o.value.trim()?(c.disabled=!1,c.style.background=e.saveBg,c.style.color="white",c.style.cursor="pointer"):(c.disabled=!0,c.style.background=e.saveDisabledBg,c.style.color=e.saveDisabledText,c.style.cursor="not-allowed")};c.onmouseover=()=>{c.disabled||(c.style.background=e.saveHover,c.style.boxShadow=a?"0 2px 8px rgba(59, 130, 246, 0.35)":"0 2px 8px rgba(0, 102, 204, 0.3)")},c.onmouseout=()=>{c.disabled||(c.style.background=e.saveBg,c.style.boxShadow="none")},v.appendChild(b),v.appendChild(c),o.oninput=()=>{const n=o.value;if(N(),n.trim()){const T=S(n);T.valid?t==="add"&&h.has(n)?(r=`Anchor ID already exists: ${n}`,g.textContent="⚠ "+r,g.style.display="block",o.style.borderColor=e.fieldErrorBorder,o.style.background=e.fieldErrorBg):t==="edit"&&n!==l&&h.has(n)?(r=`Anchor ID already exists: ${n}`,g.textContent="⚠ "+r,g.style.display="block",o.style.borderColor=e.fieldErrorBorder,o.style.background=e.fieldErrorBg):(r="",g.style.display="none",o.style.borderColor=e.fieldBorder,o.style.background=e.fieldBg):(r=T.error,g.textContent="⚠ "+r,g.style.display="block",o.style.borderColor=e.fieldErrorBorder,o.style.background=e.fieldErrorBg)}else g.style.display="none",o.style.borderColor=e.fieldBorder,o.style.background=e.fieldBg},o.onfocus=()=>{o.style.borderColor=r?e.fieldErrorBorder:e.saveBg,o.style.boxShadow=r?`0 0 0 3px ${e.errorRing}`:`0 0 0 3px ${e.focusRing}`,o.style.background=r?e.fieldErrorBg:e.fieldFocusBg},o.onblur=()=>{o.style.boxShadow="none",r||(o.style.background=e.fieldBg)};const A=()=>{const n=o.value.trim();!n||!S(n).valid||t==="add"&&h.has(n)||t==="edit"&&n!==l&&h.has(n)||(s&&s(n),i.remove())},E=()=>{i.remove()};c.onclick=A,b.onclick=E,p.onclick=E,o.onkeydown=n=>{n.key==="Enter"?(n.preventDefault(),A()):n.key==="Escape"&&(n.preventDefault(),E())},i.onclick=n=>{n.target===i&&E()},u.appendChild(f),u.appendChild(B),u.appendChild(v),i.appendChild(u),document.body.appendChild(i),setTimeout(()=>o.focus(),100)}function _(t,l){let s;if(l)s=l;else{const r=window.getSelection();if(!r||r.rangeCount===0)return;s=r.getRangeAt(0)}let d=null,a=s.startContainer;for(;a&&a!==document.body;){if(a.nodeType===Node.ELEMENT_NODE){const r=a;if(r.getAttribute("contenteditable")==="true"){d=r;break}}a=a.parentNode}const e=(d==null?void 0:d.innerHTML)??"",i=document.createElement("span");i.id=t,i.className="rte-anchor",i.setAttribute("data-type","anchor"),i.setAttribute("data-anchor-id",t),i.setAttribute("title",`Anchor: ${t}`),i.style.cssText=`
|
|
95
95
|
display: inline;
|
|
96
96
|
position: relative;
|
|
97
97
|
cursor: pointer;
|
|
98
|
-
`,
|
|
98
|
+
`,s.insertNode(i),h.add(t),s.setStart(i.nextSibling||i.parentNode,0),s.collapse(!0);const u=window.getSelection();if(u&&(u.removeAllRanges(),u.addRange(s)),d)$(d,e),d.dispatchEvent(new Event("input",{bubbles:!0}));else{const r=w.findEditorContainerFromSelection();if(r){const f=w.getContentElement(r);f&&f.dispatchEvent(new Event("input",{bubbles:!0}))}}D()}function D(){if(document.getElementById("rte-anchor-styles"))return;const t=document.createElement("style");t.id="rte-anchor-styles",t.textContent=`
|
|
99
99
|
.rte-anchor {
|
|
100
100
|
display: inline;
|
|
101
101
|
position: relative;
|
|
@@ -173,4 +173,4 @@
|
|
|
173
173
|
outline: 2px solid #0066cc;
|
|
174
174
|
outline-offset: 2px;
|
|
175
175
|
}
|
|
176
|
-
`,document.head.appendChild(t)}const I=()=>(typeof window<"u"&&(z(),D()),{name:"anchor",toolbar:[{label:"Anchor",command:"insertAnchor",icon:'<svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M12 8.4C13.4912 8.4 14.7 7.19117 14.7 5.7C14.7 4.20883 13.4912 3 12 3C10.5088 3 9.3 4.20883 9.3 5.7C9.3 7.19117 10.5088 8.4 12 8.4ZM12 8.4V20.9999M12 20.9999C9.61305 20.9999 7.32387 20.0518 5.63604 18.364C3.94821 16.6761 3 14.3869 3 12H5M12 20.9999C14.3869 20.9999 16.6761 20.0518 18.364 18.364C20.0518 16.6761 21 14.3869 21 12H19" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',shortcut:"Mod-Shift-k"}],commands:{insertAnchor:()=>{try{const t=window.getSelection();if(!t||t.rangeCount===0)return alert("Please place your cursor where you want to insert the anchor."),!1;const
|
|
176
|
+
`,document.head.appendChild(t)}const I=()=>(typeof window<"u"&&(z(),D()),{name:"anchor",toolbar:[{label:"Anchor",command:"insertAnchor",icon:'<svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M12 8.4C13.4912 8.4 14.7 7.19117 14.7 5.7C14.7 4.20883 13.4912 3 12 3C10.5088 3 9.3 4.20883 9.3 5.7C9.3 7.19117 10.5088 8.4 12 8.4ZM12 8.4V20.9999M12 20.9999C9.61305 20.9999 7.32387 20.0518 5.63604 18.364C3.94821 16.6761 3 14.3869 3 12H5M12 20.9999C14.3869 20.9999 16.6761 20.0518 18.364 18.364C20.0518 16.6761 21 14.3869 21 12H19" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',shortcut:"Mod-Shift-k"}],commands:{insertAnchor:()=>{try{const t=window.getSelection();if(!t||t.rangeCount===0)return alert("Please place your cursor where you want to insert the anchor."),!1;const l=t.getRangeAt(0).cloneRange();return H("add","",s=>{_(s,l)},l),!0}catch(t){return console.error("Failed to insert anchor:",t),!1}}},keymap:{"Mod-Shift-k":"insertAnchor"}});exports.AnchorPlugin=I;
|
package/dist/anchor.esm.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import { f as D, g as S } from "./editorContainerHelpers-
|
|
2
|
-
const
|
|
3
|
-
function z(t,
|
|
4
|
-
if (
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { f as D, g as S } from "./editorContainerHelpers-69585c07.mjs";
|
|
2
|
+
const h = /* @__PURE__ */ new Set(), y = '[data-theme="dark"], .dark, .editora-theme-dark';
|
|
3
|
+
function z(t, l) {
|
|
4
|
+
if (l === t.innerHTML)
|
|
5
|
+
return;
|
|
6
|
+
const s = window.execEditorCommand || window.executeEditorCommand;
|
|
7
|
+
if (typeof s == "function")
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
+
s("recordDomTransaction", t, l, t.innerHTML);
|
|
9
10
|
} catch {
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
function R() {
|
|
13
|
-
if (typeof window > "u" || window.__anchorObserverInitialized)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
if (typeof window > "u" || window.__anchorObserverInitialized)
|
|
15
|
+
return;
|
|
16
|
+
window.__anchorObserverInitialized = !0, new MutationObserver((l) => {
|
|
17
|
+
l.forEach((s) => {
|
|
18
|
+
s.removedNodes.forEach((d) => {
|
|
19
|
+
var a, e;
|
|
20
|
+
if (d.nodeType === Node.ELEMENT_NODE) {
|
|
21
|
+
const i = d;
|
|
22
|
+
if ((a = i.classList) != null && a.contains("rte-anchor")) {
|
|
23
|
+
const r = i.id;
|
|
24
|
+
r && h.delete(r);
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
const u = (e = i.querySelectorAll) == null ? void 0 : e.call(i, ".rte-anchor");
|
|
27
|
+
u == null || u.forEach((r) => {
|
|
28
|
+
const f = r.id;
|
|
29
|
+
f && h.delete(f);
|
|
26
30
|
});
|
|
27
31
|
}
|
|
28
32
|
});
|
|
@@ -37,30 +41,35 @@ function A(t) {
|
|
|
37
41
|
}
|
|
38
42
|
function M() {
|
|
39
43
|
const t = D();
|
|
40
|
-
if (!t)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
if (!t)
|
|
45
|
+
return;
|
|
46
|
+
const l = S(t);
|
|
47
|
+
if (!l)
|
|
48
|
+
return;
|
|
49
|
+
const s = l.querySelectorAll(".rte-anchor"), d = /* @__PURE__ */ new Set();
|
|
50
|
+
s.forEach((a) => {
|
|
51
|
+
const e = a.id;
|
|
52
|
+
e && d.add(e);
|
|
53
|
+
}), h.clear(), d.forEach((a) => h.add(a));
|
|
48
54
|
}
|
|
49
55
|
function H(t) {
|
|
50
56
|
if (t) {
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
57
|
+
const d = t.startContainer, a = d.nodeType === Node.ELEMENT_NODE ? d : d.parentElement;
|
|
58
|
+
if (a != null && a.closest(y))
|
|
59
|
+
return !0;
|
|
53
60
|
}
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
61
|
+
const l = window.getSelection();
|
|
62
|
+
if (l && l.rangeCount > 0) {
|
|
63
|
+
const d = l.getRangeAt(0).startContainer, a = d.nodeType === Node.ELEMENT_NODE ? d : d.parentElement;
|
|
64
|
+
if (a != null && a.closest(y))
|
|
65
|
+
return !0;
|
|
58
66
|
}
|
|
59
|
-
|
|
67
|
+
const s = document.activeElement;
|
|
68
|
+
return s != null && s.closest(y) ? !0 : document.body.matches(y) || document.documentElement.matches(y);
|
|
60
69
|
}
|
|
61
|
-
function _(t,
|
|
70
|
+
function _(t, l, s, d) {
|
|
62
71
|
M();
|
|
63
|
-
const
|
|
72
|
+
const a = H(d), e = a ? {
|
|
64
73
|
overlay: "rgba(0, 0, 0, 0.62)",
|
|
65
74
|
dialogBg: "#1f2937",
|
|
66
75
|
panelBg: "#222d3a",
|
|
@@ -72,6 +81,7 @@ function _(t, c, i, n) {
|
|
|
72
81
|
fieldFocusBg: "#111827",
|
|
73
82
|
fieldBorder: "#4b5563",
|
|
74
83
|
fieldText: "#e2e8f0",
|
|
84
|
+
fieldPlaceholder: "#94a3b8",
|
|
75
85
|
fieldErrorBg: "#3f2124",
|
|
76
86
|
fieldErrorBorder: "#ef4444",
|
|
77
87
|
cancelBg: "#334155",
|
|
@@ -96,6 +106,7 @@ function _(t, c, i, n) {
|
|
|
96
106
|
fieldFocusBg: "#f9f9ff",
|
|
97
107
|
fieldBorder: "#d0d0d0",
|
|
98
108
|
fieldText: "#333333",
|
|
109
|
+
fieldPlaceholder: "#9ca3af",
|
|
99
110
|
fieldErrorBg: "#ffebee",
|
|
100
111
|
fieldErrorBorder: "#d32f2f",
|
|
101
112
|
cancelBg: "#f0f0f0",
|
|
@@ -108,8 +119,8 @@ function _(t, c, i, n) {
|
|
|
108
119
|
help: "#999999",
|
|
109
120
|
focusRing: "rgba(0, 102, 204, 0.1)",
|
|
110
121
|
errorRing: "rgba(211, 47, 47, 0.1)"
|
|
111
|
-
},
|
|
112
|
-
|
|
122
|
+
}, i = document.createElement("div");
|
|
123
|
+
i.className = "rte-anchor-dialog-overlay", i.style.cssText = `
|
|
113
124
|
position: fixed;
|
|
114
125
|
top: 0;
|
|
115
126
|
left: 0;
|
|
@@ -133,8 +144,8 @@ function _(t, c, i, n) {
|
|
|
133
144
|
overflow: hidden;
|
|
134
145
|
animation: rte-anchor-dialog-appear 0.2s ease;
|
|
135
146
|
`, !document.getElementById("rte-anchor-dialog-styles")) {
|
|
136
|
-
const
|
|
137
|
-
|
|
147
|
+
const n = document.createElement("style");
|
|
148
|
+
n.id = "rte-anchor-dialog-styles", n.textContent = `
|
|
138
149
|
@keyframes rte-anchor-dialog-appear {
|
|
139
150
|
from { opacity: 0; transform: scale(0.95); }
|
|
140
151
|
to { opacity: 1; transform: scale(1); }
|
|
@@ -142,11 +153,11 @@ function _(t, c, i, n) {
|
|
|
142
153
|
.rte-anchor-dialog input:focus {
|
|
143
154
|
outline: none !important;
|
|
144
155
|
}
|
|
145
|
-
`, document.head.appendChild(
|
|
156
|
+
`, document.head.appendChild(n);
|
|
146
157
|
}
|
|
147
|
-
let
|
|
148
|
-
const
|
|
149
|
-
|
|
158
|
+
let r = "";
|
|
159
|
+
const f = document.createElement("div");
|
|
160
|
+
f.style.cssText = `
|
|
150
161
|
display: flex;
|
|
151
162
|
align-items: center;
|
|
152
163
|
justify-content: space-between;
|
|
@@ -155,9 +166,9 @@ function _(t, c, i, n) {
|
|
|
155
166
|
background: ${e.panelBg};
|
|
156
167
|
`;
|
|
157
168
|
const w = document.createElement("h3");
|
|
158
|
-
w.style.cssText = `margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`, w.textContent = "Add Anchor";
|
|
159
|
-
const
|
|
160
|
-
|
|
169
|
+
w.style.cssText = `margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`, w.textContent = t === "add" ? "Add Anchor" : "Edit Anchor";
|
|
170
|
+
const p = document.createElement("button");
|
|
171
|
+
p.textContent = "✕", p.style.cssText = `
|
|
161
172
|
background: none;
|
|
162
173
|
border: none;
|
|
163
174
|
font-size: 24px;
|
|
@@ -171,19 +182,19 @@ function _(t, c, i, n) {
|
|
|
171
182
|
justify-content: center;
|
|
172
183
|
border-radius: 4px;
|
|
173
184
|
transition: all 0.2s ease;
|
|
174
|
-
`,
|
|
175
|
-
|
|
176
|
-
},
|
|
177
|
-
|
|
178
|
-
},
|
|
185
|
+
`, p.onmouseover = () => {
|
|
186
|
+
p.style.background = e.closeHoverBg, p.style.color = "#f8fafc";
|
|
187
|
+
}, p.onmouseout = () => {
|
|
188
|
+
p.style.background = "none", p.style.color = e.muted;
|
|
189
|
+
}, f.appendChild(w), f.appendChild(p);
|
|
179
190
|
const C = document.createElement("div");
|
|
180
191
|
C.style.cssText = "padding: 20px;";
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
192
|
+
const x = document.createElement("div");
|
|
193
|
+
x.style.cssText = "margin-bottom: 0;";
|
|
194
|
+
const m = document.createElement("label");
|
|
195
|
+
m.textContent = "Anchor ID", m.style.cssText = `display: block; font-size: 14px; font-weight: 500; color: ${e.text}; margin-bottom: 8px;`, m.setAttribute("for", "anchor-id-input");
|
|
185
196
|
const o = document.createElement("input");
|
|
186
|
-
o.id = "anchor-id-input", o.type = "text", o.placeholder = "e.g., section-introduction", o.value = "", o.style.cssText = `
|
|
197
|
+
o.id = "anchor-id-input", o.type = "text", o.placeholder = "e.g., section-introduction", o.value = l || "", o.style.cssText = `
|
|
187
198
|
width: 100%;
|
|
188
199
|
padding: 10px 12px;
|
|
189
200
|
font-size: 14px;
|
|
@@ -195,15 +206,15 @@ function _(t, c, i, n) {
|
|
|
195
206
|
transition: all 0.2s ease;
|
|
196
207
|
box-sizing: border-box;
|
|
197
208
|
`, o.style.setProperty("caret-color", e.fieldText);
|
|
198
|
-
const
|
|
199
|
-
|
|
209
|
+
const g = document.createElement("div");
|
|
210
|
+
g.style.cssText = `
|
|
200
211
|
color: #d32f2f;
|
|
201
212
|
font-size: 12px;
|
|
202
213
|
margin-top: 6px;
|
|
203
214
|
display: none;
|
|
204
215
|
`;
|
|
205
216
|
const B = document.createElement("div");
|
|
206
|
-
B.textContent = "URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.", B.style.cssText = `color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`,
|
|
217
|
+
B.textContent = "URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.", B.style.cssText = `color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`, x.appendChild(m), x.appendChild(o), x.appendChild(g), x.appendChild(B), C.appendChild(x);
|
|
207
218
|
const v = document.createElement("div");
|
|
208
219
|
v.style.cssText = `
|
|
209
220
|
display: flex;
|
|
@@ -213,8 +224,8 @@ function _(t, c, i, n) {
|
|
|
213
224
|
background: ${e.panelBg};
|
|
214
225
|
justify-content: flex-end;
|
|
215
226
|
`;
|
|
216
|
-
const
|
|
217
|
-
|
|
227
|
+
const b = document.createElement("button");
|
|
228
|
+
b.textContent = "Cancel", b.style.cssText = `
|
|
218
229
|
padding: 8px 16px;
|
|
219
230
|
font-size: 14px;
|
|
220
231
|
font-weight: 500;
|
|
@@ -224,9 +235,9 @@ function _(t, c, i, n) {
|
|
|
224
235
|
transition: all 0.2s ease;
|
|
225
236
|
background: ${e.cancelBg};
|
|
226
237
|
color: ${e.cancelText};
|
|
227
|
-
`,
|
|
228
|
-
const
|
|
229
|
-
|
|
238
|
+
`, b.onmouseover = () => b.style.background = e.cancelHover, b.onmouseout = () => b.style.background = e.cancelBg;
|
|
239
|
+
const c = document.createElement("button");
|
|
240
|
+
c.textContent = t === "add" ? "Add Anchor" : "Save Changes", c.style.cssText = `
|
|
230
241
|
padding: 8px 16px;
|
|
231
242
|
font-size: 14px;
|
|
232
243
|
font-weight: 500;
|
|
@@ -236,78 +247,80 @@ function _(t, c, i, n) {
|
|
|
236
247
|
transition: all 0.2s ease;
|
|
237
248
|
background: ${e.saveBg};
|
|
238
249
|
color: white;
|
|
239
|
-
`,
|
|
250
|
+
`, c.disabled = !o.value.trim();
|
|
240
251
|
const $ = () => {
|
|
241
|
-
o.value.trim() ? (
|
|
252
|
+
o.value.trim() ? (c.disabled = !1, c.style.background = e.saveBg, c.style.color = "white", c.style.cursor = "pointer") : (c.disabled = !0, c.style.background = e.saveDisabledBg, c.style.color = e.saveDisabledText, c.style.cursor = "not-allowed");
|
|
242
253
|
};
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
},
|
|
246
|
-
|
|
247
|
-
}, v.appendChild(
|
|
248
|
-
const
|
|
249
|
-
if ($(),
|
|
250
|
-
const k = A(
|
|
251
|
-
k.valid ?
|
|
254
|
+
c.onmouseover = () => {
|
|
255
|
+
c.disabled || (c.style.background = e.saveHover, c.style.boxShadow = a ? "0 2px 8px rgba(59, 130, 246, 0.35)" : "0 2px 8px rgba(0, 102, 204, 0.3)");
|
|
256
|
+
}, c.onmouseout = () => {
|
|
257
|
+
c.disabled || (c.style.background = e.saveBg, c.style.boxShadow = "none");
|
|
258
|
+
}, v.appendChild(b), v.appendChild(c), o.oninput = () => {
|
|
259
|
+
const n = o.value;
|
|
260
|
+
if ($(), n.trim()) {
|
|
261
|
+
const k = A(n);
|
|
262
|
+
k.valid ? t === "add" && h.has(n) ? (r = `Anchor ID already exists: ${n}`, g.textContent = "⚠ " + r, g.style.display = "block", o.style.borderColor = e.fieldErrorBorder, o.style.background = e.fieldErrorBg) : t === "edit" && n !== l && h.has(n) ? (r = `Anchor ID already exists: ${n}`, g.textContent = "⚠ " + r, g.style.display = "block", o.style.borderColor = e.fieldErrorBorder, o.style.background = e.fieldErrorBg) : (r = "", g.style.display = "none", o.style.borderColor = e.fieldBorder, o.style.background = e.fieldBg) : (r = k.error, g.textContent = "⚠ " + r, g.style.display = "block", o.style.borderColor = e.fieldErrorBorder, o.style.background = e.fieldErrorBg);
|
|
252
263
|
} else
|
|
253
|
-
|
|
264
|
+
g.style.display = "none", o.style.borderColor = e.fieldBorder, o.style.background = e.fieldBg;
|
|
254
265
|
}, o.onfocus = () => {
|
|
255
|
-
o.style.borderColor =
|
|
266
|
+
o.style.borderColor = r ? e.fieldErrorBorder : e.saveBg, o.style.boxShadow = r ? `0 0 0 3px ${e.errorRing}` : `0 0 0 3px ${e.focusRing}`, o.style.background = r ? e.fieldErrorBg : e.fieldFocusBg;
|
|
256
267
|
}, o.onblur = () => {
|
|
257
|
-
o.style.boxShadow = "none",
|
|
268
|
+
o.style.boxShadow = "none", r || (o.style.background = e.fieldBg);
|
|
258
269
|
};
|
|
259
270
|
const T = () => {
|
|
260
|
-
const
|
|
261
|
-
!
|
|
271
|
+
const n = o.value.trim();
|
|
272
|
+
!n || !A(n).valid || t === "add" && h.has(n) || t === "edit" && n !== l && h.has(n) || (s && s(n), i.remove());
|
|
262
273
|
}, E = () => {
|
|
263
|
-
|
|
274
|
+
i.remove();
|
|
264
275
|
};
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
},
|
|
268
|
-
|
|
269
|
-
}, u.appendChild(
|
|
276
|
+
c.onclick = T, b.onclick = E, p.onclick = E, o.onkeydown = (n) => {
|
|
277
|
+
n.key === "Enter" ? (n.preventDefault(), T()) : n.key === "Escape" && (n.preventDefault(), E());
|
|
278
|
+
}, i.onclick = (n) => {
|
|
279
|
+
n.target === i && E();
|
|
280
|
+
}, u.appendChild(f), u.appendChild(C), u.appendChild(v), i.appendChild(u), document.body.appendChild(i), setTimeout(() => o.focus(), 100);
|
|
270
281
|
}
|
|
271
|
-
function I(t,
|
|
272
|
-
let
|
|
273
|
-
if (
|
|
274
|
-
|
|
282
|
+
function I(t, l) {
|
|
283
|
+
let s;
|
|
284
|
+
if (l)
|
|
285
|
+
s = l;
|
|
275
286
|
else {
|
|
276
|
-
const
|
|
277
|
-
if (!
|
|
278
|
-
|
|
287
|
+
const r = window.getSelection();
|
|
288
|
+
if (!r || r.rangeCount === 0)
|
|
289
|
+
return;
|
|
290
|
+
s = r.getRangeAt(0);
|
|
279
291
|
}
|
|
280
|
-
let
|
|
281
|
-
for (;
|
|
282
|
-
if (
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
285
|
-
|
|
292
|
+
let d = null, a = s.startContainer;
|
|
293
|
+
for (; a && a !== document.body; ) {
|
|
294
|
+
if (a.nodeType === Node.ELEMENT_NODE) {
|
|
295
|
+
const r = a;
|
|
296
|
+
if (r.getAttribute("contenteditable") === "true") {
|
|
297
|
+
d = r;
|
|
286
298
|
break;
|
|
287
299
|
}
|
|
288
300
|
}
|
|
289
|
-
|
|
301
|
+
a = a.parentNode;
|
|
290
302
|
}
|
|
291
|
-
const e =
|
|
292
|
-
|
|
303
|
+
const e = (d == null ? void 0 : d.innerHTML) ?? "", i = document.createElement("span");
|
|
304
|
+
i.id = t, i.className = "rte-anchor", i.setAttribute("data-type", "anchor"), i.setAttribute("data-anchor-id", t), i.setAttribute("title", `Anchor: ${t}`), i.style.cssText = `
|
|
293
305
|
display: inline;
|
|
294
306
|
position: relative;
|
|
295
307
|
cursor: pointer;
|
|
296
|
-
`,
|
|
308
|
+
`, s.insertNode(i), h.add(t), s.setStart(i.nextSibling || i.parentNode, 0), s.collapse(!0);
|
|
297
309
|
const u = window.getSelection();
|
|
298
|
-
if (u && (u.removeAllRanges(), u.addRange(
|
|
299
|
-
z(
|
|
310
|
+
if (u && (u.removeAllRanges(), u.addRange(s)), d)
|
|
311
|
+
z(d, e), d.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
300
312
|
else {
|
|
301
|
-
const
|
|
302
|
-
if (
|
|
303
|
-
const
|
|
304
|
-
|
|
313
|
+
const r = D();
|
|
314
|
+
if (r) {
|
|
315
|
+
const f = S(r);
|
|
316
|
+
f && f.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
305
317
|
}
|
|
306
318
|
}
|
|
307
319
|
N();
|
|
308
320
|
}
|
|
309
321
|
function N() {
|
|
310
|
-
if (document.getElementById("rte-anchor-styles"))
|
|
322
|
+
if (document.getElementById("rte-anchor-styles"))
|
|
323
|
+
return;
|
|
311
324
|
const t = document.createElement("style");
|
|
312
325
|
t.id = "rte-anchor-styles", t.textContent = `
|
|
313
326
|
.rte-anchor {
|
|
@@ -405,10 +418,10 @@ const O = () => (typeof window < "u" && (R(), N()), {
|
|
|
405
418
|
const t = window.getSelection();
|
|
406
419
|
if (!t || t.rangeCount === 0)
|
|
407
420
|
return alert("Please place your cursor where you want to insert the anchor."), !1;
|
|
408
|
-
const
|
|
409
|
-
return _("add", "", (
|
|
410
|
-
I(
|
|
411
|
-
},
|
|
421
|
+
const l = t.getRangeAt(0).cloneRange();
|
|
422
|
+
return _("add", "", (s) => {
|
|
423
|
+
I(s, l);
|
|
424
|
+
}, l), !0;
|
|
412
425
|
} catch (t) {
|
|
413
426
|
return console.error("Failed to insert anchor:", t), !1;
|
|
414
427
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const b = "p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre";
|
|
2
|
+
function p(e) {
|
|
3
|
+
return !!e.cloneContents().querySelector(b);
|
|
4
|
+
}
|
|
5
|
+
function v(e, n) {
|
|
6
|
+
var o;
|
|
7
|
+
const t = (e == null ? void 0 : e.nodeType) === Node.ELEMENT_NODE ? e : (e == null ? void 0 : e.parentElement) ?? null;
|
|
8
|
+
return (t == null ? void 0 : t.closest('[contenteditable="true"]')) || ((o = n()) == null ? void 0 : o.querySelector('[contenteditable="true"]')) || document.querySelector('[contenteditable="true"]');
|
|
9
|
+
}
|
|
10
|
+
function C(e, n) {
|
|
11
|
+
const t = v(e, n);
|
|
12
|
+
t && t.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
13
|
+
}
|
|
14
|
+
function A(e, n) {
|
|
15
|
+
let o = e.startContainer.nodeType === Node.TEXT_NODE ? e.startContainer.parentElement : e.startContainer;
|
|
16
|
+
for (; o && o !== document.body; ) {
|
|
17
|
+
if (o.classList.contains(n)) {
|
|
18
|
+
const r = document.createRange();
|
|
19
|
+
if (r.selectNodeContents(o), r.compareBoundaryPoints(Range.START_TO_START, e) <= 0 && r.compareBoundaryPoints(Range.END_TO_END, e) >= 0)
|
|
20
|
+
return o;
|
|
21
|
+
}
|
|
22
|
+
o = o.parentElement;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
function N(e) {
|
|
27
|
+
try {
|
|
28
|
+
if (e.savedRange) {
|
|
29
|
+
const c = window.getSelection();
|
|
30
|
+
c && (c.removeAllRanges(), c.addRange(e.savedRange.cloneRange()));
|
|
31
|
+
}
|
|
32
|
+
const n = window.getSelection();
|
|
33
|
+
if (!n || n.rangeCount === 0 || n.isCollapsed)
|
|
34
|
+
return !1;
|
|
35
|
+
const t = n.getRangeAt(0);
|
|
36
|
+
if (t.collapsed)
|
|
37
|
+
return !1;
|
|
38
|
+
const o = A(t, e.className);
|
|
39
|
+
if (o)
|
|
40
|
+
return e.styleProperty === "backgroundColor" ? o.style.backgroundColor = e.color : o.style.color = e.color, C(o, e.getActiveEditorRoot), !0;
|
|
41
|
+
const r = v(
|
|
42
|
+
t.commonAncestorContainer,
|
|
43
|
+
e.getActiveEditorRoot
|
|
44
|
+
);
|
|
45
|
+
r == null || r.focus({ preventScroll: !0 });
|
|
46
|
+
try {
|
|
47
|
+
document.execCommand("styleWithCSS", !1, "true");
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
let l = !1;
|
|
51
|
+
if (e.commands.forEach((c) => {
|
|
52
|
+
l || (l = document.execCommand(c, !1, e.color));
|
|
53
|
+
}), !l && !p(t)) {
|
|
54
|
+
const c = document.createElement("span");
|
|
55
|
+
e.styleProperty === "backgroundColor" ? c.style.backgroundColor = e.color : c.style.color = e.color, c.className = e.className;
|
|
56
|
+
const a = t.extractContents();
|
|
57
|
+
c.appendChild(a), t.insertNode(c), t.setStartAfter(c), t.collapse(!0), n.removeAllRanges(), n.addRange(t), l = !0;
|
|
58
|
+
}
|
|
59
|
+
return l ? (C(t.commonAncestorContainer, e.getActiveEditorRoot), !0) : (e.warnMessage && console.warn(e.warnMessage), !1);
|
|
60
|
+
} catch (n) {
|
|
61
|
+
return e.warnMessage ? console.error(e.warnMessage, n) : console.error("[ColorApply] Failed to apply color", n), !1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function T({
|
|
65
|
+
popover: e,
|
|
66
|
+
anchor: n,
|
|
67
|
+
onClose: t,
|
|
68
|
+
gap: o = 6,
|
|
69
|
+
margin: r = 8,
|
|
70
|
+
zIndex: l = 1e4
|
|
71
|
+
}) {
|
|
72
|
+
e.style.position = "fixed", e.style.zIndex = `${l}`, e.style.visibility = "hidden";
|
|
73
|
+
const c = () => {
|
|
74
|
+
if (!e.isConnected || !n.isConnected) {
|
|
75
|
+
t();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const s = n.getBoundingClientRect();
|
|
79
|
+
if (s.width === 0 && s.height === 0) {
|
|
80
|
+
t();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const i = e.getBoundingClientRect(), w = i.width || e.offsetWidth || 220, f = i.height || e.offsetHeight || 260, y = window.innerWidth, E = window.innerHeight;
|
|
84
|
+
let u = s.left, d = s.bottom + o;
|
|
85
|
+
if (u + w > y - r && (u = y - w - r), u = Math.max(r, u), d + f > E - r) {
|
|
86
|
+
const g = s.top - f - o;
|
|
87
|
+
g >= r ? d = g : d = Math.max(r, E - f - r);
|
|
88
|
+
}
|
|
89
|
+
d < r && (d = r), e.style.left = `${Math.round(u)}px`, e.style.top = `${Math.round(d)}px`, e.style.visibility = "visible";
|
|
90
|
+
}, a = () => {
|
|
91
|
+
c();
|
|
92
|
+
}, h = (s) => {
|
|
93
|
+
const i = s.target;
|
|
94
|
+
i && (e.contains(i) || n.contains(i) || t());
|
|
95
|
+
}, m = (s) => {
|
|
96
|
+
s.key === "Escape" && t();
|
|
97
|
+
};
|
|
98
|
+
window.addEventListener("resize", a), window.addEventListener("scroll", a, !0), document.addEventListener("keydown", m);
|
|
99
|
+
const R = window.requestAnimationFrame(() => {
|
|
100
|
+
document.addEventListener("mousedown", h, !0);
|
|
101
|
+
});
|
|
102
|
+
return c(), { reposition: c, destroy: () => {
|
|
103
|
+
window.cancelAnimationFrame(R), window.removeEventListener("resize", a), window.removeEventListener("scroll", a, !0), document.removeEventListener("keydown", m), document.removeEventListener("mousedown", h, !0);
|
|
104
|
+
} };
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
N as a,
|
|
108
|
+
T as b
|
|
109
|
+
};
|