@editorcn/editor 0.1.1 → 0.2.0

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 CHANGED
@@ -30,8 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ BubbleMenu: () => BubbleMenu,
34
+ CodeBlock: () => CodeBlock,
33
35
  DEFAULT_ICONS: () => DEFAULT_ICONS,
34
36
  DEFAULT_LABELS: () => DEFAULT_LABELS,
37
+ DEFAULT_LANGUAGE_ICONS: () => DEFAULT_LANGUAGE_ICONS,
35
38
  Link: () => Link,
36
39
  RichTextEditor: () => RichTextEditor,
37
40
  TwitterEmbed: () => TwitterEmbed,
@@ -41,7 +44,7 @@ __export(index_exports, {
41
44
  module.exports = __toCommonJS(index_exports);
42
45
 
43
46
  // src/rte-text-editor.tsx
44
- var import_react16 = require("react");
47
+ var import_react23 = require("react");
45
48
 
46
49
  // src/ui/utils.ts
47
50
  var import_clsx = require("clsx");
@@ -108,7 +111,28 @@ var DEFAULT_LABELS = {
108
111
  // src/icons.tsx
109
112
  var import_react3 = require("react");
110
113
  var import_jsx_runtime = require("react/jsx-runtime");
114
+ var iconProps = { className: "rte-editor-icon" };
111
115
  function Svg({
116
+ children,
117
+ className,
118
+ strokeWidth = 2
119
+ }) {
120
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
121
+ "svg",
122
+ {
123
+ xmlns: "http://www.w3.org/2000/svg",
124
+ viewBox: "0 0 24 24",
125
+ fill: "none",
126
+ stroke: "currentColor",
127
+ strokeWidth,
128
+ strokeLinecap: "round",
129
+ strokeLinejoin: "round",
130
+ className,
131
+ children
132
+ }
133
+ );
134
+ }
135
+ function LangIcon({
112
136
  children,
113
137
  className
114
138
  }) {
@@ -119,7 +143,7 @@ function Svg({
119
143
  viewBox: "0 0 24 24",
120
144
  fill: "none",
121
145
  stroke: "currentColor",
122
- strokeWidth: 2,
146
+ strokeWidth: 1.5,
123
147
  strokeLinecap: "round",
124
148
  strokeLinejoin: "round",
125
149
  className,
@@ -127,7 +151,120 @@ function Svg({
127
151
  }
128
152
  );
129
153
  }
130
- var iconProps = { className: "rte-editor-icon" };
154
+ var DEFAULT_LANGUAGE_ICONS = {
155
+ javascript: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
156
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
157
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10.5 8v6.5a2 2 0 0 1-3.5 1.3" }),
158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M17 8.8a2 2 0 0 0-2-.8c-1.1 0-2.2.6-2.2 1.7 0 1 .9 1.4 2.2 1.7 1.3.3 2.3.7 2.3 1.9 0 1.1-1 1.8-2.3 1.8a2.4 2.4 0 0 1-2.3-1.4" })
159
+ ] }),
160
+ typescript: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
161
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
162
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M7.3 8.2h5M9.8 8.2v7.6" }),
163
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M17 8.8a2 2 0 0 0-2-.8c-1.1 0-2.2.6-2.2 1.7 0 1 .9 1.4 2.2 1.7 1.3.3 2.3.7 2.3 1.9 0 1.1-1 1.8-2.3 1.8a2.4 2.4 0 0 1-2.3-1.4" })
164
+ ] }),
165
+ html: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
166
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
167
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9.5 8.5L6.5 12l3 3.5" }),
168
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14.5 8.5L17.5 12l-3 3.5" }),
169
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 7.3l-2 9.4" })
170
+ ] }),
171
+ css: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
172
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
173
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9.7 7.5l-1 9" }),
174
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M15.3 7.5l-1 9" }),
175
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M7 10.3h11" }),
176
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6.5 14.3h11" })
177
+ ] }),
178
+ json: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
179
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 3H7a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2 2 2 0 0 1 2 2v4a2 2 0 0 0 2 2" }),
180
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M16 3h1a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2 2 2 0 0 0-2 2v4a2 2 0 0 1-2 2" })
181
+ ] }),
182
+ python: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
183
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4.5 15c0-3 2.5-4.7 5.7-4.7h1.6c2.8 0 5-2 5-4.5" }),
184
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9.5 3.3c1.3-.3 2.6 0 3.3 1-.7 1-2 1.3-3.3 1" }),
185
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "15.5", cy: "4.3", r: ".55", fill: "currentColor", stroke: "none" }),
186
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M17.8 4.5l1.4-.6M17.8 4.9l1.4.6" })
187
+ ] }),
188
+ rust: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
189
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "7" }),
190
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "2.3" }),
191
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3" }),
192
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5.6 5.6l2.1 2.1M16.3 16.3l2.1 2.1M5.6 18.4l2.1-2.1M16.3 7.7l2.1-2.1" })
193
+ ] }),
194
+ go: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
195
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
196
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12.6 9.7A3.3 3.3 0 1 0 12.6 14.3" }),
197
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12.6 12h-1.9" }),
198
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "17", cy: "12", r: "2.9" })
199
+ ] }),
200
+ java: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
201
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 10h10v5a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-5z" }),
202
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M16 12h1.3a1.8 1.8 0 0 1 0 3.6H16" }),
203
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9.3 3.8c-.9.8-.9 1.6 0 2.4M13.3 3.8c-.9.8-.9 1.6 0 2.4" }),
204
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 19.3h10" })
205
+ ] }),
206
+ c: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
207
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "8.5" }),
208
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M15.6 9.3a4.5 4.5 0 1 0 0 5.4" })
209
+ ] }),
210
+ cpp: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
211
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "9.5", cy: "12", r: "6.5" }),
212
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12.3 9.7a3.3 3.3 0 1 0 0 4.6" }),
213
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M15.7 10.5v3M14.2 12h3" }),
214
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M19.3 10.5v3M17.8 12h3" })
215
+ ] }),
216
+ ruby: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
217
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polygon", { points: "12 2.5 19.5 8 12 21.5 4.5 8" }),
218
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4.5 8h15" }),
219
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 2.5v19" })
220
+ ] }),
221
+ php: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
222
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
223
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M11.5 8.5L7.5 12l4 3.5" }),
224
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M15.2 8.2c1.1 0 1.9.6 1.9 1.6 0 1.1-.9 1.5-1.8 1.8-.6.2-1 .5-1 1.1" }),
225
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "14.3", cy: "16.2", r: ".5", fill: "currentColor", stroke: "none" })
226
+ ] }),
227
+ swift: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LangIcon, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M19 4.5c-2.6 4-5.5 7-8.3 9 2-.2 3.7-1 4.8-2.6-.7 2.8-2.8 5-5.3 6.1 3 .5 5.6-.5 7.2-2.4.4 2-.4 3.9-1.9 4.9 3.7-1.3 6-4.2 6.6-7.6-1 2.6-2.8 4.6-4.6 5.8" }) }),
228
+ kotlin: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
229
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
230
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 7.5v9" }),
231
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 12l6-4.5" }),
232
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 12l6 4.5" })
233
+ ] }),
234
+ sql: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
235
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ellipse", { cx: "12", cy: "6", rx: "8", ry: "3" }),
236
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 6v6c0 1.7 3.6 3 8 3s8-1.3 8-3V6" }),
237
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 12v6c0 1.7 3.6 3 8 3s8-1.3 8-3v-6" })
238
+ ] }),
239
+ bash: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
240
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "2.5", y: "4", width: "19", height: "16", rx: "2" }),
241
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6.5 9.5l3.5 3-3.5 3" }),
242
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 15.5h5.5" })
243
+ ] }),
244
+ markdown: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
245
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "2", y: "5", width: "20", height: "14", rx: "2" }),
246
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 15V9l3 4 3-4v6" }),
247
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M16.5 9v6" }),
248
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14.5 13l2 2 2-2" })
249
+ ] }),
250
+ yaml: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
251
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "2.5", y: "3", width: "19", height: "18", rx: "2" }),
252
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6.5 8h2M9.5 8h8" }),
253
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6.5 12h2M9.5 12h6" }),
254
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6.5 16h2M9.5 16h7" })
255
+ ] }),
256
+ xml: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
257
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 7l-4.5 5 4.5 5" }),
258
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M16 7l4.5 5-4.5 5" }),
259
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 8v8" })
260
+ ] }),
261
+ plaintext: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LangIcon, { children: [
262
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "4", y: "2.5", width: "16", height: "19", rx: "2" }),
263
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "7.5", y1: "7.5", x2: "16.5", y2: "7.5" }),
264
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "7.5", y1: "11.5", x2: "16.5", y2: "11.5" }),
265
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "7.5", y1: "15.5", x2: "13.5", y2: "15.5" })
266
+ ] })
267
+ };
131
268
  var DEFAULT_ICONS = {
132
269
  boldControlIcon: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { ...iconProps, children: [
133
270
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 4h7a4 4 0 0 1 0 8H6z" }),
@@ -275,7 +412,8 @@ var DEFAULT_ICONS = {
275
412
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m4 20 8-9" }),
276
413
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m12 20-8-9" }),
277
414
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M19 11h-3.5c0-1.6 3.5-1.9 3.5-3.8a1.8 1.8 0 0 0-3.3-1" })
278
- ] })
415
+ ] }),
416
+ languageIcons: DEFAULT_LANGUAGE_ICONS
279
417
  };
280
418
 
281
419
  // src/rte-toolbar.tsx
@@ -1566,8 +1704,305 @@ function TwitterEmbedControl({ className }) {
1566
1704
  ] });
1567
1705
  }
1568
1706
 
1569
- // src/rte-text-editor.tsx
1707
+ // src/bubble-menu/index.tsx
1708
+ var import_react21 = require("react");
1709
+ var import_react22 = require("@tiptap/react");
1710
+ var import_core3 = require("@tiptap/core");
1711
+
1712
+ // src/bubble-menu/language-selector.tsx
1713
+ var import_react18 = require("react");
1714
+ var import_react19 = require("@tiptap/react");
1715
+
1716
+ // src/bubble-menu/utils.ts
1717
+ var import_react16 = require("react");
1718
+ var import_react17 = require("@tiptap/react");
1719
+ function useEditorState5(editor, selector) {
1720
+ const selectorRef = (0, import_react16.useRef)(selector);
1721
+ selectorRef.current = selector;
1722
+ const [state, setState] = (0, import_react16.useState)(
1723
+ () => editor ? selector(editor) : void 0
1724
+ );
1725
+ (0, import_react16.useEffect)(() => {
1726
+ if (!editor) return;
1727
+ const update = () => setState(selectorRef.current(editor));
1728
+ update();
1729
+ editor.on("selectionUpdate", update);
1730
+ editor.on("transaction", update);
1731
+ return () => {
1732
+ editor.off("selectionUpdate", update);
1733
+ editor.off("transaction", update);
1734
+ };
1735
+ }, [editor]);
1736
+ return state;
1737
+ }
1738
+ var CODE_BLOCK_LANGUAGES = [
1739
+ "javascript",
1740
+ "typescript",
1741
+ "html",
1742
+ "css",
1743
+ "json",
1744
+ "python",
1745
+ "rust",
1746
+ "go",
1747
+ "java",
1748
+ "c",
1749
+ "cpp",
1750
+ "ruby",
1751
+ "php",
1752
+ "swift",
1753
+ "kotlin",
1754
+ "sql",
1755
+ "bash",
1756
+ "markdown",
1757
+ "yaml",
1758
+ "xml",
1759
+ "plaintext"
1760
+ ];
1761
+
1762
+ // src/bubble-menu/language-selector.tsx
1570
1763
  var import_jsx_runtime16 = require("react/jsx-runtime");
1764
+ function FallbackIcon() {
1765
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
1766
+ "svg",
1767
+ {
1768
+ xmlns: "http://www.w3.org/2000/svg",
1769
+ viewBox: "0 0 24 24",
1770
+ fill: "none",
1771
+ stroke: "currentColor",
1772
+ strokeWidth: 2,
1773
+ strokeLinecap: "round",
1774
+ strokeLinejoin: "round",
1775
+ className: "rte-editor-icon",
1776
+ children: [
1777
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("polyline", { points: "16 18 22 12 16 6" }),
1778
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("polyline", { points: "8 6 2 12 8 18" })
1779
+ ]
1780
+ }
1781
+ );
1782
+ }
1783
+ function LanguageSelector({ editor }) {
1784
+ const [open, setOpen] = (0, import_react18.useState)(false);
1785
+ const { icons } = useRichTextEditorContext();
1786
+ const { currentLanguage } = useEditorState5(editor, (ed) => ({
1787
+ currentLanguage: ed.getAttributes("codeBlock").language || "javascript"
1788
+ }));
1789
+ const langIcon = icons.languageIcons[currentLanguage] ?? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(FallbackIcon, {});
1790
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { style: { position: "relative" }, children: [
1791
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
1792
+ "button",
1793
+ {
1794
+ type: "button",
1795
+ className: "rte-bubble-btn",
1796
+ onMouseDown: (e) => e.preventDefault(),
1797
+ onClick: () => setOpen(!open),
1798
+ children: [
1799
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "rte-bubble-btn-icon", children: langIcon }),
1800
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "rte-bubble-btn-text", children: currentLanguage }),
1801
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "rte-bubble-btn-icon", style: { width: 12, height: 12 }, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1802
+ "svg",
1803
+ {
1804
+ xmlns: "http://www.w3.org/2000/svg",
1805
+ viewBox: "0 0 24 24",
1806
+ fill: "none",
1807
+ stroke: "currentColor",
1808
+ strokeWidth: 2,
1809
+ strokeLinecap: "round",
1810
+ strokeLinejoin: "round",
1811
+ children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("path", { d: "m6 9 6 6 6-6" })
1812
+ }
1813
+ ) })
1814
+ ]
1815
+ }
1816
+ ),
1817
+ open && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
1818
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "rte-bubble-overlay", onClick: () => setOpen(false) }),
1819
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1820
+ "div",
1821
+ {
1822
+ className: "rte-bubble-dropdown rte-bubble-dropdown--language",
1823
+ children: CODE_BLOCK_LANGUAGES.map((lang) => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
1824
+ "button",
1825
+ {
1826
+ type: "button",
1827
+ className: `rte-bubble-dropdown-item${currentLanguage === lang ? " rte-bubble-dropdown-item--active" : ""}`,
1828
+ onMouseDown: (e) => e.preventDefault(),
1829
+ onClick: () => {
1830
+ editor.chain().focus().updateAttributes("codeBlock", { language: lang }).run();
1831
+ setOpen(false);
1832
+ },
1833
+ children: [
1834
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "rte-bubble-dropdown-icon", children: icons.languageIcons[lang] ?? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(FallbackIcon, {}) }),
1835
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { children: lang }),
1836
+ currentLanguage === lang && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "rte-bubble-dropdown-icon", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1837
+ "svg",
1838
+ {
1839
+ xmlns: "http://www.w3.org/2000/svg",
1840
+ viewBox: "0 0 24 24",
1841
+ fill: "none",
1842
+ stroke: "currentColor",
1843
+ strokeWidth: 2,
1844
+ strokeLinecap: "round",
1845
+ strokeLinejoin: "round",
1846
+ children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("polyline", { points: "20 6 9 17 4 12" })
1847
+ }
1848
+ ) })
1849
+ ]
1850
+ },
1851
+ lang
1852
+ ))
1853
+ }
1854
+ )
1855
+ ] })
1856
+ ] });
1857
+ }
1858
+
1859
+ // src/bubble-menu/text-buttons.tsx
1860
+ var import_react20 = require("@tiptap/react");
1861
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1862
+ function Svg2({ children, strokeWidth = 2 }) {
1863
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1864
+ "svg",
1865
+ {
1866
+ xmlns: "http://www.w3.org/2000/svg",
1867
+ viewBox: "0 0 24 24",
1868
+ fill: "none",
1869
+ stroke: "currentColor",
1870
+ strokeWidth,
1871
+ strokeLinecap: "round",
1872
+ strokeLinejoin: "round",
1873
+ className: "rte-editor-icon",
1874
+ children
1875
+ }
1876
+ );
1877
+ }
1878
+ var textItems = [
1879
+ {
1880
+ icon: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Svg2, { children: [
1881
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { d: "M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" }),
1882
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { d: "M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" })
1883
+ ] }),
1884
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- extension commands not in base ChainedCommands
1885
+ command: (e) => e.chain().focus().toggleBold().run(),
1886
+ isActive: (s) => s.isBold
1887
+ },
1888
+ {
1889
+ icon: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Svg2, { children: [
1890
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("line", { x1: "19", y1: "4", x2: "10", y2: "4" }),
1891
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("line", { x1: "14", y1: "20", x2: "5", y2: "20" }),
1892
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("line", { x1: "15", y1: "4", x2: "9", y2: "20" })
1893
+ ] }),
1894
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1895
+ command: (e) => e.chain().focus().toggleItalic().run(),
1896
+ isActive: (s) => s.isItalic
1897
+ },
1898
+ {
1899
+ icon: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Svg2, { children: [
1900
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }),
1901
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("line", { x1: "4", y1: "20", x2: "20", y2: "20" })
1902
+ ] }),
1903
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1904
+ command: (e) => e.chain().focus().toggleUnderline().run(),
1905
+ isActive: (s) => s.isUnderline
1906
+ },
1907
+ {
1908
+ icon: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Svg2, { children: [
1909
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { d: "M16 4H9.5a3.5 3.5 0 0 0-2.9 5.4" }),
1910
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { d: "M14.5 14.6a3.5 3.5 0 0 1-2.9 5.4H8" }),
1911
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("line", { x1: "4", y1: "12", x2: "20", y2: "12" })
1912
+ ] }),
1913
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1914
+ command: (e) => e.chain().focus().toggleStrike().run(),
1915
+ isActive: (s) => s.isStrike
1916
+ },
1917
+ {
1918
+ icon: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Svg2, { children: [
1919
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("polyline", { points: "16 18 22 12 16 6" }),
1920
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("polyline", { points: "8 6 2 12 8 18" })
1921
+ ] }),
1922
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1923
+ command: (e) => e.chain().focus().toggleCode().run(),
1924
+ isActive: (s) => s.isCode
1925
+ }
1926
+ ];
1927
+ function TextButtons({ editor }) {
1928
+ const editorState = useEditorState5(editor, (ed) => ({
1929
+ isBold: ed.isActive("bold"),
1930
+ isItalic: ed.isActive("italic"),
1931
+ isUnderline: ed.isActive("underline"),
1932
+ isStrike: ed.isActive("strike"),
1933
+ isCode: ed.isActive("code")
1934
+ }));
1935
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "rte-bubble-group", children: textItems.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1936
+ "button",
1937
+ {
1938
+ type: "button",
1939
+ className: `rte-bubble-btn${item.isActive(editorState) ? " rte-bubble-btn--active" : ""}`,
1940
+ onMouseDown: (e) => e.preventDefault(),
1941
+ onClick: () => item.command(editor),
1942
+ children: item.icon
1943
+ },
1944
+ i
1945
+ )) });
1946
+ }
1947
+
1948
+ // src/bubble-menu/index.tsx
1949
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1950
+ var BubbleMenuComponent = null;
1951
+ var bubbleMenuPromise = (async () => {
1952
+ try {
1953
+ const mod = await import("@tiptap/react/menus");
1954
+ BubbleMenuComponent = mod.BubbleMenu;
1955
+ } catch {
1956
+ try {
1957
+ const mod = await import("@tiptap/react");
1958
+ BubbleMenuComponent = mod.BubbleMenu;
1959
+ } catch {
1960
+ }
1961
+ }
1962
+ })();
1963
+ function BubbleMenu({ editor }) {
1964
+ const [loaded, setLoaded] = (0, import_react21.useState)(BubbleMenuComponent !== null);
1965
+ const editorState = useEditorState5(editor, (ed) => ({
1966
+ isCodeBlock: ed.isActive("codeBlock")
1967
+ }));
1968
+ (0, import_react21.useEffect)(() => {
1969
+ if (BubbleMenuComponent !== null) {
1970
+ setLoaded(true);
1971
+ return;
1972
+ }
1973
+ let active = true;
1974
+ bubbleMenuPromise.then(() => {
1975
+ if (active) setLoaded(true);
1976
+ });
1977
+ return () => {
1978
+ active = false;
1979
+ };
1980
+ }, []);
1981
+ const shouldShow = (0, import_react21.useCallback)(
1982
+ ({ editor: ed, state }) => {
1983
+ const { selection } = state;
1984
+ if (!ed.isEditable) return false;
1985
+ if (selection.empty && !ed.isActive("codeBlock")) return false;
1986
+ if (!selection.empty && !(0, import_core3.isTextSelection)(selection)) return false;
1987
+ return true;
1988
+ },
1989
+ []
1990
+ );
1991
+ if (!editor || !BubbleMenuComponent || !loaded) return null;
1992
+ const isCodeBlockActive = editorState?.isCodeBlock ?? false;
1993
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1994
+ BubbleMenuComponent,
1995
+ {
1996
+ editor,
1997
+ tippyOptions: { placement: "top", offset: [0, 8], hideOnClick: false },
1998
+ shouldShow,
1999
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "rte-bubble-menu", children: isCodeBlockActive ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(LanguageSelector, { editor }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TextButtons, { editor }) })
2000
+ }
2001
+ );
2002
+ }
2003
+
2004
+ // src/rte-text-editor.tsx
2005
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1571
2006
  function RichTextEditorRoot({
1572
2007
  editor,
1573
2008
  children,
@@ -1577,20 +2012,20 @@ function RichTextEditorRoot({
1577
2012
  variant = "default",
1578
2013
  editable = true
1579
2014
  }) {
1580
- const mergedLabels = (0, import_react16.useMemo)(
2015
+ const mergedLabels = (0, import_react23.useMemo)(
1581
2016
  () => ({ ...DEFAULT_LABELS, ...labels }),
1582
2017
  [labels]
1583
2018
  );
1584
- const mergedIcons = (0, import_react16.useMemo)(
2019
+ const mergedIcons = (0, import_react23.useMemo)(
1585
2020
  () => ({ ...DEFAULT_ICONS, ...icons }),
1586
2021
  [icons]
1587
2022
  );
1588
- (0, import_react16.useEffect)(() => {
2023
+ (0, import_react23.useEffect)(() => {
1589
2024
  if (editor && editor.isEditable !== editable) {
1590
2025
  editor.setEditable(editable);
1591
2026
  }
1592
2027
  }, [editor, editable]);
1593
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(RichTextEditorContext.Provider, { value: { editor, labels: mergedLabels, icons: mergedIcons, variant, editable }, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2028
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(RichTextEditorContext.Provider, { value: { editor, labels: mergedLabels, icons: mergedIcons, variant, editable }, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1594
2029
  "div",
1595
2030
  {
1596
2031
  className: cn(
@@ -1608,6 +2043,7 @@ var RichTextEditor = Object.assign(RichTextEditorRoot, {
1608
2043
  Footer,
1609
2044
  ControlsGroup,
1610
2045
  Content,
2046
+ BubbleMenu,
1611
2047
  Control: RichTextEditorControl,
1612
2048
  Link: LinkControl,
1613
2049
  YouTubeEmbed: YouTubeEmbedControl,
@@ -1653,10 +2089,22 @@ var Link = import_extension_link.default.extend({
1653
2089
  };
1654
2090
  }
1655
2091
  }).configure({ openOnClick: false });
2092
+
2093
+ // src/extensions/code-block.ts
2094
+ var import_extension_code_block_lowlight = __toESM(require("@tiptap/extension-code-block-lowlight"), 1);
2095
+ var import_lowlight = require("lowlight");
2096
+ var lowlight = (0, import_lowlight.createLowlight)(import_lowlight.common);
2097
+ var CodeBlock = import_extension_code_block_lowlight.default.configure({
2098
+ lowlight,
2099
+ defaultLanguage: "javascript"
2100
+ });
1656
2101
  // Annotate the CommonJS export names for ESM import in node:
1657
2102
  0 && (module.exports = {
2103
+ BubbleMenu,
2104
+ CodeBlock,
1658
2105
  DEFAULT_ICONS,
1659
2106
  DEFAULT_LABELS,
2107
+ DEFAULT_LANGUAGE_ICONS,
1660
2108
  Link,
1661
2109
  RichTextEditor,
1662
2110
  TwitterEmbed,