@editora/core 1.0.2 → 1.0.4
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 +42 -4
- package/dist/{A11yCheckerPlugin.native-CZKpi3uF.mjs → A11yCheckerPlugin.native-BRdGYMju.mjs} +225 -173
- package/dist/AnchorPlugin.native-C1Rw5m04.mjs +404 -0
- package/dist/BackgroundColorPlugin.native-BE-p9DRd.mjs +489 -0
- package/dist/ChecklistPlugin.native-nuSSEFNI.mjs +309 -0
- package/dist/ClearFormattingPlugin.native-Bq_XcTh2.mjs +140 -0
- package/dist/CodePlugin.native-0Zari_zp.mjs +2041 -0
- package/dist/CodeSamplePlugin.native-B-KS1pOl.mjs +384 -0
- package/dist/CommentsPlugin.native-tMnWn8a2.mjs +723 -0
- package/dist/DirectionPlugin.native-CDnbdNyl.mjs +130 -0
- package/dist/{EmbedIframePlugin.native-ifr9KLdN.mjs → EmbedIframePlugin.native-CSWIB1jm.mjs} +154 -50
- package/dist/{EmojisPlugin.native-D6mJSnSR.mjs → EmojisPlugin.native-DxTm_DL-.mjs} +156 -103
- package/dist/FontFamilyPlugin.native-j8hMTbg4.mjs +158 -0
- package/dist/FontSizePlugin.native-B_jCh7dY.mjs +286 -0
- package/dist/FootnotePlugin.native-D730OGRm.mjs +425 -0
- package/dist/HistoryPlugin.native-DCrPdeSW.mjs +257 -0
- package/dist/IndentPlugin.native-BHixp8sP.mjs +150 -0
- package/dist/LineHeightPlugin.native-CM7iXdQj.mjs +151 -0
- package/dist/{LinkPlugin.native-BdAOV-iu.mjs → LinkPlugin.native-CS2g-G18.mjs} +128 -53
- package/dist/{ListPlugin.native-CLFU5AUQ.mjs → ListPlugin.native-V7EZC1lM.mjs} +59 -12
- package/dist/MathPlugin.native-KUxz0o8C.mjs +251 -0
- package/dist/MediaManagerPlugin.native-CgP5iInD.mjs +970 -0
- package/dist/MergeTagPlugin.native-CU9LtsfD.mjs +416 -0
- package/dist/PageBreakPlugin.native-CGiQxXqR.mjs +297 -0
- package/dist/{PrintPlugin.native-BUpm52VJ.mjs → PrintPlugin.native-7qt5v7L5.mjs} +10 -10
- package/dist/{SpecialCharactersPlugin.native-x7a2SWXc.mjs → SpecialCharactersPlugin.native-DANrbExJ.mjs} +143 -97
- package/dist/SpellCheckPlugin.native-C8bPvRHy.mjs +1019 -0
- package/dist/StrikethroughPlugin.native-0Be7j49s.mjs +73 -0
- package/dist/{TablePlugin.native-EEWXn1-s.mjs → TablePlugin.native-DrHX-efe.mjs} +149 -145
- package/dist/TemplatePlugin.native-4lKEm-WY.mjs +578 -0
- package/dist/TextAlignmentPlugin.native-sM_1s00t.mjs +108 -0
- package/dist/{TextColorPlugin.native-D6SmTglm.mjs → TextColorPlugin.native-Clgtb50j.mjs} +173 -92
- package/dist/colorSelectionApply-CK1My9N2.mjs +67 -0
- package/dist/core.css +1 -1
- package/dist/editora.min.js +31 -29
- package/dist/editora.umd.js +31 -29
- package/dist/index-CqWQFb3D.js +10 -0
- package/dist/index-OwnkG39N.mjs +2227 -0
- package/dist/index.cjs.js +14 -18
- package/dist/index.esm.js +204 -521
- package/dist/plugin-loader.js +26 -26
- package/dist/webcomponent-core.js +1286 -295
- package/dist/webcomponent-core.min.css +1 -1
- package/dist/webcomponent-core.min.js +116 -106
- package/dist/webcomponent.cjs.js +1 -1
- package/dist/webcomponent.esm.js +1 -1
- package/dist/webcomponent.js +1252 -261
- package/dist/webcomponent.min.css +1 -1
- package/dist/webcomponent.min.js +2980 -1488
- package/index.d.ts +355 -0
- package/package.json +21 -19
- package/LICENSE +0 -21
- package/dist/A11yCheckerPlugin.native-CZKpi3uF.mjs.map +0 -1
- package/dist/AnchorPlugin.native-7es9PVZ9.mjs +0 -340
- package/dist/AnchorPlugin.native-7es9PVZ9.mjs.map +0 -1
- package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs +0 -449
- package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs.map +0 -1
- package/dist/BlockquotePlugin.native-JFmOLsxN.mjs.map +0 -1
- package/dist/BoldPlugin.native-BAzzoqU5.mjs.map +0 -1
- package/dist/CapitalizationPlugin.native-DOMsh5R7.mjs.map +0 -1
- package/dist/ChecklistPlugin.native-Dccs3nLe.mjs +0 -153
- package/dist/ChecklistPlugin.native-Dccs3nLe.mjs.map +0 -1
- package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs +0 -27
- package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs.map +0 -1
- package/dist/CodePlugin.native-DD9xFIid.mjs +0 -1679
- package/dist/CodePlugin.native-DD9xFIid.mjs.map +0 -1
- package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs +0 -326
- package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs.map +0 -1
- package/dist/CommentsPlugin.native-2zQV8Ia4.mjs +0 -473
- package/dist/CommentsPlugin.native-2zQV8Ia4.mjs.map +0 -1
- package/dist/DirectionPlugin.native-Be7wCzkI.mjs +0 -59
- package/dist/DirectionPlugin.native-Be7wCzkI.mjs.map +0 -1
- package/dist/DocumentManagerPlugin.native-BvZL5CSG.mjs.map +0 -1
- package/dist/EmbedIframePlugin.native-ifr9KLdN.mjs.map +0 -1
- package/dist/EmojisPlugin.native-D6mJSnSR.mjs.map +0 -1
- package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs +0 -106
- package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs.map +0 -1
- package/dist/FontSizePlugin.native-DkLMLPue.mjs +0 -186
- package/dist/FontSizePlugin.native-DkLMLPue.mjs.map +0 -1
- package/dist/FootnotePlugin.native-BciVc9W6.mjs +0 -128
- package/dist/FootnotePlugin.native-BciVc9W6.mjs.map +0 -1
- package/dist/FullscreenPlugin.native-ChXyxeNw.mjs.map +0 -1
- package/dist/HeadingPlugin.native-DrLYwQnQ.mjs.map +0 -1
- package/dist/HistoryPlugin.native-DoDRifCf.mjs +0 -89
- package/dist/HistoryPlugin.native-DoDRifCf.mjs.map +0 -1
- package/dist/IndentPlugin.native-CbFugPoi.mjs +0 -133
- package/dist/IndentPlugin.native-CbFugPoi.mjs.map +0 -1
- package/dist/ItalicPlugin.native-CQjjDyUL.mjs.map +0 -1
- package/dist/LineHeightPlugin.native-CWQT2FIa.mjs +0 -73
- package/dist/LineHeightPlugin.native-CWQT2FIa.mjs.map +0 -1
- package/dist/LinkPlugin.native-BdAOV-iu.mjs.map +0 -1
- package/dist/ListPlugin.native-CLFU5AUQ.mjs.map +0 -1
- package/dist/MathPlugin.native-DE_ii-LA.mjs +0 -182
- package/dist/MathPlugin.native-DE_ii-LA.mjs.map +0 -1
- package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs +0 -533
- package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs.map +0 -1
- package/dist/MergeTagPlugin.native-CrxyThyn.mjs +0 -178
- package/dist/MergeTagPlugin.native-CrxyThyn.mjs.map +0 -1
- package/dist/PageBreakPlugin.native-DDjcDyRW.mjs +0 -172
- package/dist/PageBreakPlugin.native-DDjcDyRW.mjs.map +0 -1
- package/dist/PreviewPlugin.native-DBvfpmIv.mjs.map +0 -1
- package/dist/PrintPlugin.native-BUpm52VJ.mjs.map +0 -1
- package/dist/SpecialCharactersPlugin.native-x7a2SWXc.mjs.map +0 -1
- package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs +0 -465
- package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs.map +0 -1
- package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs +0 -43
- package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs.map +0 -1
- package/dist/TablePlugin.native-EEWXn1-s.mjs.map +0 -1
- package/dist/TemplatePlugin.native-BlSn1c9h.mjs +0 -564
- package/dist/TemplatePlugin.native-BlSn1c9h.mjs.map +0 -1
- package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs +0 -97
- package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs.map +0 -1
- package/dist/TextColorPlugin.native-D6SmTglm.mjs.map +0 -1
- package/dist/UnderlinePlugin.native-QpIcK4L2.mjs.map +0 -1
- package/dist/documentManager-irzj9n3V.mjs.map +0 -1
- package/dist/editorContainerHelpers-C7kdWnS0.mjs.map +0 -1
- package/dist/editora.min.js.map +0 -1
- package/dist/editora.umd.js.map +0 -1
- package/dist/index-BF5RBhL9.js +0 -4
- package/dist/index-BF5RBhL9.js.map +0 -1
- package/dist/index-BPsf460l.mjs +0 -1243
- package/dist/index-BPsf460l.mjs.map +0 -1
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.es-CuicffkQ.mjs.map +0 -1
- package/dist/index.esm.js.map +0 -1
- package/dist/plugin-loader.js.map +0 -1
- package/dist/purify.es-CKpwg8Tk.mjs.map +0 -1
- package/dist/webcomponent-core.js.map +0 -1
- package/dist/webcomponent-core.min.js.map +0 -1
- package/dist/webcomponent.cjs.js.map +0 -1
- package/dist/webcomponent.esm.js.map +0 -1
- package/dist/webcomponent.js.map +0 -1
- package/dist/webcomponent.min.js.map +0 -1
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
const w = () => {
|
|
2
|
+
const d = window.getSelection();
|
|
3
|
+
if (d && d.rangeCount > 0) {
|
|
4
|
+
let t = d.getRangeAt(0).startContainer;
|
|
5
|
+
for (; t && t !== document.body; ) {
|
|
6
|
+
if (t.nodeType === Node.ELEMENT_NODE) {
|
|
7
|
+
const r = t;
|
|
8
|
+
if (r.getAttribute("contenteditable") === "true")
|
|
9
|
+
return r;
|
|
10
|
+
}
|
|
11
|
+
t = t.parentNode;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const l = document.activeElement;
|
|
15
|
+
if (l) {
|
|
16
|
+
if (l.getAttribute("contenteditable") === "true")
|
|
17
|
+
return l;
|
|
18
|
+
const t = l.closest('[contenteditable="true"]');
|
|
19
|
+
if (t) return t;
|
|
20
|
+
}
|
|
21
|
+
return document.querySelector('[contenteditable="true"]');
|
|
22
|
+
}, k = '[data-theme="dark"], .dark, .editora-theme-dark', N = () => {
|
|
23
|
+
const d = w();
|
|
24
|
+
if (d != null && d.closest(k)) return !0;
|
|
25
|
+
const l = window.getSelection();
|
|
26
|
+
if (l && l.rangeCount > 0) {
|
|
27
|
+
const r = l.getRangeAt(0).startContainer, i = r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement;
|
|
28
|
+
if (i != null && i.closest(k)) return !0;
|
|
29
|
+
}
|
|
30
|
+
const t = document.activeElement;
|
|
31
|
+
return t != null && t.closest(k) ? !0 : document.body.matches(k) || document.documentElement.matches(k);
|
|
32
|
+
}, A = [
|
|
33
|
+
{ value: "javascript", label: "JavaScript" },
|
|
34
|
+
{ value: "typescript", label: "TypeScript" },
|
|
35
|
+
{ value: "python", label: "Python" },
|
|
36
|
+
{ value: "java", label: "Java" },
|
|
37
|
+
{ value: "csharp", label: "C#" },
|
|
38
|
+
{ value: "cpp", label: "C++" },
|
|
39
|
+
{ value: "c", label: "C" },
|
|
40
|
+
{ value: "php", label: "PHP" },
|
|
41
|
+
{ value: "ruby", label: "Ruby" },
|
|
42
|
+
{ value: "go", label: "Go" },
|
|
43
|
+
{ value: "rust", label: "Rust" },
|
|
44
|
+
{ value: "swift", label: "Swift" },
|
|
45
|
+
{ value: "kotlin", label: "Kotlin" },
|
|
46
|
+
{ value: "html", label: "HTML" },
|
|
47
|
+
{ value: "css", label: "CSS" },
|
|
48
|
+
{ value: "scss", label: "SCSS" },
|
|
49
|
+
{ value: "json", label: "JSON" },
|
|
50
|
+
{ value: "xml", label: "XML" },
|
|
51
|
+
{ value: "yaml", label: "YAML" },
|
|
52
|
+
{ value: "markdown", label: "Markdown" },
|
|
53
|
+
{ value: "sql", label: "SQL" },
|
|
54
|
+
{ value: "bash", label: "Bash" },
|
|
55
|
+
{ value: "shell", label: "Shell" },
|
|
56
|
+
{ value: "plaintext", label: "Plain Text" }
|
|
57
|
+
], S = /* @__PURE__ */ new Map();
|
|
58
|
+
function $(d, l, t, r) {
|
|
59
|
+
const i = !!l, n = r || "javascript", g = t || "", p = N(), e = p ? {
|
|
60
|
+
overlay: "rgba(0, 0, 0, 0.62)",
|
|
61
|
+
dialogBg: "#1f2937",
|
|
62
|
+
dialogBorder: "#4b5563",
|
|
63
|
+
text: "#e2e8f0",
|
|
64
|
+
mutedText: "#a8b5c8",
|
|
65
|
+
headerFooterBg: "#222d3a",
|
|
66
|
+
border: "#3b4657",
|
|
67
|
+
fieldBg: "#111827",
|
|
68
|
+
fieldBorder: "#4b5563",
|
|
69
|
+
cancelBg: "#334155",
|
|
70
|
+
cancelHover: "#475569",
|
|
71
|
+
cancelText: "#e2e8f0",
|
|
72
|
+
primaryBg: "#3b82f6",
|
|
73
|
+
primaryHover: "#2563eb"
|
|
74
|
+
} : {
|
|
75
|
+
overlay: "rgba(0, 0, 0, 0.5)",
|
|
76
|
+
dialogBg: "#ffffff",
|
|
77
|
+
dialogBorder: "#e0e0e0",
|
|
78
|
+
text: "#333333",
|
|
79
|
+
mutedText: "#666666",
|
|
80
|
+
headerFooterBg: "#ffffff",
|
|
81
|
+
border: "#e0e0e0",
|
|
82
|
+
fieldBg: "#ffffff",
|
|
83
|
+
fieldBorder: "#dddddd",
|
|
84
|
+
cancelBg: "#e5e7eb",
|
|
85
|
+
cancelHover: "#d1d5db",
|
|
86
|
+
cancelText: "#333333",
|
|
87
|
+
primaryBg: "#2563eb",
|
|
88
|
+
primaryHover: "#1d4ed8"
|
|
89
|
+
}, c = document.createElement("div");
|
|
90
|
+
c.className = "rte-code-sample-overlay", p && c.classList.add("rte-theme-dark"), c.style.cssText = `
|
|
91
|
+
position: fixed;
|
|
92
|
+
top: 0;
|
|
93
|
+
left: 0;
|
|
94
|
+
right: 0;
|
|
95
|
+
bottom: 0;
|
|
96
|
+
background: ${e.overlay};
|
|
97
|
+
display: flex;
|
|
98
|
+
align-items: center;
|
|
99
|
+
justify-content: center;
|
|
100
|
+
z-index: 10000;
|
|
101
|
+
animation: fadeIn 160ms ease-out;
|
|
102
|
+
`;
|
|
103
|
+
const o = document.createElement("div");
|
|
104
|
+
o.className = "rte-code-sample-dialog", o.style.cssText = `
|
|
105
|
+
background: ${e.dialogBg};
|
|
106
|
+
border: 1px solid ${e.dialogBorder};
|
|
107
|
+
border-radius: 8px;
|
|
108
|
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
109
|
+
max-width: 700px;
|
|
110
|
+
width: 90vw;
|
|
111
|
+
max-height: 80vh;
|
|
112
|
+
display: flex;
|
|
113
|
+
flex-direction: column;
|
|
114
|
+
animation: slideUp 200ms cubic-bezier(0.2, 0.9, 0.25, 1);
|
|
115
|
+
`;
|
|
116
|
+
const u = document.createElement("div");
|
|
117
|
+
u.style.cssText = `
|
|
118
|
+
padding: 20px;
|
|
119
|
+
border-bottom: 1px solid ${e.border};
|
|
120
|
+
background: ${e.headerFooterBg};
|
|
121
|
+
display: flex;
|
|
122
|
+
justify-content: space-between;
|
|
123
|
+
align-items: center;
|
|
124
|
+
`, u.innerHTML = `
|
|
125
|
+
<h2 style="margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};">
|
|
126
|
+
${i ? "Edit Code Sample" : "Insert Code Sample"}
|
|
127
|
+
</h2>
|
|
128
|
+
<button class="rte-code-close-btn" style="background: none; border: none; font-size: 28px; color: ${e.mutedText}; cursor: pointer; padding: 0; width: 32px; height: 32px;">×</button>
|
|
129
|
+
`;
|
|
130
|
+
const m = document.createElement("div");
|
|
131
|
+
m.style.cssText = `
|
|
132
|
+
flex: 1;
|
|
133
|
+
overflow-y: auto;
|
|
134
|
+
padding: 20px;
|
|
135
|
+
`;
|
|
136
|
+
const s = document.createElement("div");
|
|
137
|
+
s.style.marginBottom = "20px", s.innerHTML = `
|
|
138
|
+
<label style="display: block; margin-bottom: 8px; font-weight: 500; color: ${e.text}; font-size: 14px;">Language</label>
|
|
139
|
+
<select class="rte-code-language" style="
|
|
140
|
+
width: 100%;
|
|
141
|
+
padding: 10px 12px;
|
|
142
|
+
border: 1px solid ${e.fieldBorder};
|
|
143
|
+
border-radius: 4px;
|
|
144
|
+
font-size: 14px;
|
|
145
|
+
background-color: ${e.fieldBg};
|
|
146
|
+
color: ${e.text};
|
|
147
|
+
cursor: pointer;
|
|
148
|
+
">
|
|
149
|
+
${A.map((a) => `
|
|
150
|
+
<option value="${a.value}" ${a.value === n ? "selected" : ""}>
|
|
151
|
+
${a.label}
|
|
152
|
+
</option>
|
|
153
|
+
`).join("")}
|
|
154
|
+
</select>
|
|
155
|
+
`;
|
|
156
|
+
const b = document.createElement("div");
|
|
157
|
+
b.style.marginBottom = "20px", b.innerHTML = `
|
|
158
|
+
<label style="display: block; margin-bottom: 8px; font-weight: 500; color: ${e.text}; font-size: 14px;">Code</label>
|
|
159
|
+
<textarea class="rte-code-textarea" spellcheck="false" placeholder="Paste or type your code here..." style="
|
|
160
|
+
width: 100%;
|
|
161
|
+
padding: 12px;
|
|
162
|
+
border: 1px solid ${e.fieldBorder};
|
|
163
|
+
border-radius: 4px;
|
|
164
|
+
font-family: 'Courier New', Courier, monospace;
|
|
165
|
+
font-size: 13px;
|
|
166
|
+
line-height: 1.5;
|
|
167
|
+
resize: vertical;
|
|
168
|
+
min-height: 250px;
|
|
169
|
+
max-height: 400px;
|
|
170
|
+
background-color: ${e.fieldBg};
|
|
171
|
+
color: ${e.text};
|
|
172
|
+
box-sizing: border-box;
|
|
173
|
+
">${g}</textarea>
|
|
174
|
+
<div class="rte-code-error" style="color: #dc2626; font-size: 12px; margin-top: 6px; display: none;"></div>
|
|
175
|
+
`;
|
|
176
|
+
const x = document.createElement("div");
|
|
177
|
+
x.style.cssText = `color: ${e.mutedText}; font-size: 12px; margin-top: 10px;`, x.innerHTML = "💡 Tip: Press Ctrl+Enter (or Cmd+Enter on Mac) to save, or Escape to cancel", m.appendChild(s), m.appendChild(b), m.appendChild(x);
|
|
178
|
+
const y = document.createElement("div");
|
|
179
|
+
y.style.cssText = `
|
|
180
|
+
padding: 20px;
|
|
181
|
+
border-top: 1px solid ${e.border};
|
|
182
|
+
background: ${e.headerFooterBg};
|
|
183
|
+
display: flex;
|
|
184
|
+
justify-content: flex-end;
|
|
185
|
+
gap: 12px;
|
|
186
|
+
`, y.innerHTML = `
|
|
187
|
+
<button class="rte-code-cancel-btn" style="
|
|
188
|
+
padding: 10px 16px;
|
|
189
|
+
border: none;
|
|
190
|
+
border-radius: 4px;
|
|
191
|
+
font-size: 14px;
|
|
192
|
+
font-weight: 500;
|
|
193
|
+
cursor: pointer;
|
|
194
|
+
background: ${e.cancelBg};
|
|
195
|
+
color: ${e.cancelText};
|
|
196
|
+
">Cancel</button>
|
|
197
|
+
<button class="rte-code-save-btn" style="
|
|
198
|
+
padding: 10px 16px;
|
|
199
|
+
border: none;
|
|
200
|
+
border-radius: 4px;
|
|
201
|
+
font-size: 14px;
|
|
202
|
+
font-weight: 500;
|
|
203
|
+
cursor: pointer;
|
|
204
|
+
background: ${e.primaryBg};
|
|
205
|
+
color: #fff;
|
|
206
|
+
">${i ? "Update Code Sample" : "Insert Code Sample"}</button>
|
|
207
|
+
`, o.appendChild(u), o.appendChild(m), o.appendChild(y), c.appendChild(o);
|
|
208
|
+
const L = s.querySelector(".rte-code-language"), E = b.querySelector(".rte-code-textarea"), B = b.querySelector(".rte-code-error"), f = u.querySelector(".rte-code-close-btn"), v = y.querySelector(".rte-code-cancel-btn"), h = y.querySelector(".rte-code-save-btn");
|
|
209
|
+
f.onmouseover = () => {
|
|
210
|
+
f.style.color = "#f8fafc", f.style.background = p ? "#334155" : "#f0f0f0", f.style.borderRadius = "4px";
|
|
211
|
+
}, f.onmouseout = () => {
|
|
212
|
+
f.style.color = e.mutedText, f.style.background = "none";
|
|
213
|
+
}, v.onmouseover = () => {
|
|
214
|
+
v.style.background = e.cancelHover;
|
|
215
|
+
}, v.onmouseout = () => {
|
|
216
|
+
v.style.background = e.cancelBg;
|
|
217
|
+
}, h.onmouseover = () => {
|
|
218
|
+
h.style.background = e.primaryHover;
|
|
219
|
+
}, h.onmouseout = () => {
|
|
220
|
+
h.style.background = e.primaryBg;
|
|
221
|
+
};
|
|
222
|
+
const C = () => {
|
|
223
|
+
c.remove();
|
|
224
|
+
}, T = () => {
|
|
225
|
+
const a = E.value.trim();
|
|
226
|
+
if (!a) {
|
|
227
|
+
B.textContent = "⚠ Code cannot be empty", B.style.display = "block";
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const M = L.value;
|
|
231
|
+
d(a, M), C();
|
|
232
|
+
};
|
|
233
|
+
if (f.onclick = C, v.onclick = C, h.onclick = T, E.addEventListener("keydown", (a) => {
|
|
234
|
+
(a.ctrlKey || a.metaKey) && a.key === "Enter" && (a.preventDefault(), T()), a.key === "Escape" && C();
|
|
235
|
+
}), E.addEventListener("input", () => {
|
|
236
|
+
B.style.display = "none";
|
|
237
|
+
}), c.addEventListener("click", (a) => {
|
|
238
|
+
a.target === c && C();
|
|
239
|
+
}), !document.getElementById("rte-code-sample-animations")) {
|
|
240
|
+
const a = document.createElement("style");
|
|
241
|
+
a.id = "rte-code-sample-animations", a.textContent = `
|
|
242
|
+
@keyframes fadeIn {
|
|
243
|
+
from { opacity: 0; }
|
|
244
|
+
to { opacity: 1; }
|
|
245
|
+
}
|
|
246
|
+
@keyframes slideUp {
|
|
247
|
+
from { transform: translateY(20px); opacity: 0; }
|
|
248
|
+
to { transform: translateY(0); opacity: 1; }
|
|
249
|
+
}
|
|
250
|
+
`, document.head.appendChild(a);
|
|
251
|
+
}
|
|
252
|
+
return document.body.appendChild(c), setTimeout(() => E.focus(), 100), c;
|
|
253
|
+
}
|
|
254
|
+
function R() {
|
|
255
|
+
if (!w()) return;
|
|
256
|
+
let l = null;
|
|
257
|
+
const t = window.getSelection();
|
|
258
|
+
t && t.rangeCount > 0 && (l = t.getRangeAt(0).cloneRange()), $((r, i) => {
|
|
259
|
+
const n = window.getSelection();
|
|
260
|
+
if (l && (n == null || n.removeAllRanges(), n == null || n.addRange(l)), !n || n.rangeCount === 0) return;
|
|
261
|
+
const g = w();
|
|
262
|
+
if (!g) return;
|
|
263
|
+
const p = n.anchorNode;
|
|
264
|
+
if (!p || !g.contains(p)) return;
|
|
265
|
+
const e = n.getRangeAt(0), c = `code-block-${Date.now()}`, o = document.createElement("pre");
|
|
266
|
+
o.className = "rte-code-block", o.id = c, o.setAttribute("data-type", "code-block"), o.setAttribute("data-lang", i), o.setAttribute("data-code-id", c), o.setAttribute("contenteditable", "false"), o.style.cssText = `
|
|
267
|
+
display: block;
|
|
268
|
+
position: relative;
|
|
269
|
+
background: #f5f5f5;
|
|
270
|
+
border: 1px solid #e0e0e0;
|
|
271
|
+
border-radius: 6px;
|
|
272
|
+
padding: 12px;
|
|
273
|
+
margin: 12px 0;
|
|
274
|
+
overflow-x: auto;
|
|
275
|
+
font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
|
|
276
|
+
font-size: 13px;
|
|
277
|
+
line-height: 1.5;
|
|
278
|
+
color: #333;
|
|
279
|
+
user-select: text;
|
|
280
|
+
cursor: default;
|
|
281
|
+
`;
|
|
282
|
+
const u = document.createElement("code");
|
|
283
|
+
u.className = `language-${i}`, u.style.cssText = `
|
|
284
|
+
font-family: inherit;
|
|
285
|
+
font-size: inherit;
|
|
286
|
+
line-height: inherit;
|
|
287
|
+
color: inherit;
|
|
288
|
+
white-space: pre;
|
|
289
|
+
word-break: normal;
|
|
290
|
+
display: block;
|
|
291
|
+
`, u.textContent = r;
|
|
292
|
+
const m = document.createElement("span");
|
|
293
|
+
m.style.cssText = `
|
|
294
|
+
position: absolute;
|
|
295
|
+
top: 0;
|
|
296
|
+
right: 0;
|
|
297
|
+
background: #333;
|
|
298
|
+
color: #fff;
|
|
299
|
+
padding: 2px 8px;
|
|
300
|
+
font-size: 11px;
|
|
301
|
+
font-weight: bold;
|
|
302
|
+
border-radius: 0 6px 0 4px;
|
|
303
|
+
text-transform: uppercase;
|
|
304
|
+
letter-spacing: 0.5px;
|
|
305
|
+
pointer-events: none;
|
|
306
|
+
`, m.textContent = i;
|
|
307
|
+
const s = document.createElement("button");
|
|
308
|
+
s.className = "rte-code-copy", s.textContent = "Copy", s.style.cssText = `
|
|
309
|
+
position: absolute;
|
|
310
|
+
top: 8px;
|
|
311
|
+
left: 8px;
|
|
312
|
+
background: #fff;
|
|
313
|
+
border: 1px solid #d0d0d0;
|
|
314
|
+
border-radius: 3px;
|
|
315
|
+
padding: 4px 8px;
|
|
316
|
+
font-size: 11px;
|
|
317
|
+
cursor: pointer;
|
|
318
|
+
opacity: 0;
|
|
319
|
+
transition: opacity 0.2s ease;
|
|
320
|
+
`, s.onclick = (x) => {
|
|
321
|
+
x.stopPropagation(), navigator.clipboard.writeText(r).then(() => {
|
|
322
|
+
s.textContent = "✓ Copied!", setTimeout(() => {
|
|
323
|
+
s.textContent = "Copy";
|
|
324
|
+
}, 2e3);
|
|
325
|
+
});
|
|
326
|
+
}, o.appendChild(m), o.appendChild(s), o.appendChild(u), o.addEventListener("mouseenter", () => {
|
|
327
|
+
s.style.opacity = "1";
|
|
328
|
+
}), o.addEventListener("mouseleave", () => {
|
|
329
|
+
s.style.opacity = "0";
|
|
330
|
+
}), o.addEventListener("dblclick", () => {
|
|
331
|
+
z(c);
|
|
332
|
+
}), S.set(c, {
|
|
333
|
+
id: c,
|
|
334
|
+
language: i,
|
|
335
|
+
code: r
|
|
336
|
+
}), e.insertNode(o);
|
|
337
|
+
const b = document.createRange();
|
|
338
|
+
b.setStartAfter(o), b.collapse(!0), n.removeAllRanges(), n.addRange(b);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function z(d) {
|
|
342
|
+
const l = w();
|
|
343
|
+
if (!l) return;
|
|
344
|
+
const t = l.querySelector(`#${d}`);
|
|
345
|
+
if (!t) return;
|
|
346
|
+
const r = S.get(d);
|
|
347
|
+
r && $(
|
|
348
|
+
(i, n) => {
|
|
349
|
+
const g = t.querySelector("code");
|
|
350
|
+
g && (g.textContent = i, g.className = `language-${n}`);
|
|
351
|
+
const p = t.querySelector("span");
|
|
352
|
+
p && (p.textContent = n), t.setAttribute("data-lang", n), r.language = n, r.code = i;
|
|
353
|
+
const e = t.querySelector(".rte-code-copy");
|
|
354
|
+
e && (e.onclick = (c) => {
|
|
355
|
+
c.stopPropagation(), navigator.clipboard.writeText(i).then(() => {
|
|
356
|
+
e.textContent = "✓ Copied!", setTimeout(() => {
|
|
357
|
+
e.textContent = "Copy";
|
|
358
|
+
}, 2e3);
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
},
|
|
362
|
+
d,
|
|
363
|
+
r.code,
|
|
364
|
+
r.language
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
const H = () => ({
|
|
368
|
+
name: "codeSample",
|
|
369
|
+
toolbar: [
|
|
370
|
+
{
|
|
371
|
+
label: "Code Block",
|
|
372
|
+
command: "insertCodeBlock",
|
|
373
|
+
icon: '<svg width="18px" height="18px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7 8L3 11.6923L7 16M17 8L21 11.6923L17 16M14 4L10 20" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
374
|
+
shortcut: "Mod-Shift-C"
|
|
375
|
+
}
|
|
376
|
+
],
|
|
377
|
+
commands: {
|
|
378
|
+
insertCodeBlock: (...d) => (R(), !0)
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
export {
|
|
382
|
+
H as CodeSamplePlugin
|
|
383
|
+
};
|
|
384
|
+
//# sourceMappingURL=CodeSamplePlugin.native-B-KS1pOl.mjs.map
|