@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.d.cts CHANGED
@@ -4,6 +4,7 @@ import { Editor } from '@tiptap/react';
4
4
  import * as _tiptap_core from '@tiptap/core';
5
5
  import { Node } from '@tiptap/core';
6
6
  import * as _tiptap_extension_link from '@tiptap/extension-link';
7
+ import * as _tiptap_extension_code_block_lowlight from '@tiptap/extension-code-block-lowlight';
7
8
 
8
9
  interface RichTextEditorLabels {
9
10
  boldControlLabel: string;
@@ -75,7 +76,9 @@ interface RichTextEditorIcons {
75
76
  highlightControlIcon: react__default.ReactNode;
76
77
  subscriptControlIcon: react__default.ReactNode;
77
78
  superscriptControlIcon: react__default.ReactNode;
79
+ languageIcons: Record<string, react__default.ReactNode>;
78
80
  }
81
+ declare const DEFAULT_LANGUAGE_ICONS: Record<string, react__default.ReactNode>;
79
82
  declare const DEFAULT_ICONS: RichTextEditorIcons;
80
83
 
81
84
  type RichTextEditorVariant = "default" | "subtle" | "compact";
@@ -142,12 +145,18 @@ declare function TwitterEmbedControl({ className }: {
142
145
  className?: string;
143
146
  }): react.JSX.Element;
144
147
 
148
+ interface BubbleMenuProps {
149
+ editor: Editor | null;
150
+ }
151
+ declare function BubbleMenu({ editor }: BubbleMenuProps): react.JSX.Element | null;
152
+
145
153
  declare function RichTextEditorRoot({ editor, children, className, labels, icons, variant, editable, }: RichTextEditorProps): react.JSX.Element;
146
154
  declare const RichTextEditor: typeof RichTextEditorRoot & {
147
155
  Toolbar: typeof Toolbar;
148
156
  Footer: typeof Footer;
149
157
  ControlsGroup: typeof ControlsGroup;
150
158
  Content: typeof Content;
159
+ BubbleMenu: typeof BubbleMenu;
151
160
  Control: typeof RichTextEditorControl;
152
161
  Link: typeof LinkControl;
153
162
  YouTubeEmbed: typeof YouTubeEmbedControl;
@@ -327,4 +336,6 @@ declare function useRichTextEditorContext(): RichTextEditorContextValue;
327
336
 
328
337
  declare const Link: _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any>;
329
338
 
330
- export { DEFAULT_ICONS, DEFAULT_LABELS, Link, RichTextEditor, type RichTextEditorFooterProps, type RichTextEditorIcons, type RichTextEditorLabels, type RichTextEditorProps, type RichTextEditorVariant, TwitterEmbed, type WordCountInfo, YouTubeEmbed, useRichTextEditorContext };
339
+ declare const CodeBlock: _tiptap_core.Node<_tiptap_extension_code_block_lowlight.CodeBlockLowlightOptions, any>;
340
+
341
+ export { BubbleMenu, CodeBlock, DEFAULT_ICONS, DEFAULT_LABELS, DEFAULT_LANGUAGE_ICONS, Link, RichTextEditor, type RichTextEditorFooterProps, type RichTextEditorIcons, type RichTextEditorLabels, type RichTextEditorProps, type RichTextEditorVariant, TwitterEmbed, type WordCountInfo, YouTubeEmbed, useRichTextEditorContext };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { Editor } from '@tiptap/react';
4
4
  import * as _tiptap_core from '@tiptap/core';
5
5
  import { Node } from '@tiptap/core';
6
6
  import * as _tiptap_extension_link from '@tiptap/extension-link';
7
+ import * as _tiptap_extension_code_block_lowlight from '@tiptap/extension-code-block-lowlight';
7
8
 
8
9
  interface RichTextEditorLabels {
9
10
  boldControlLabel: string;
@@ -75,7 +76,9 @@ interface RichTextEditorIcons {
75
76
  highlightControlIcon: react__default.ReactNode;
76
77
  subscriptControlIcon: react__default.ReactNode;
77
78
  superscriptControlIcon: react__default.ReactNode;
79
+ languageIcons: Record<string, react__default.ReactNode>;
78
80
  }
81
+ declare const DEFAULT_LANGUAGE_ICONS: Record<string, react__default.ReactNode>;
79
82
  declare const DEFAULT_ICONS: RichTextEditorIcons;
80
83
 
81
84
  type RichTextEditorVariant = "default" | "subtle" | "compact";
@@ -142,12 +145,18 @@ declare function TwitterEmbedControl({ className }: {
142
145
  className?: string;
143
146
  }): react.JSX.Element;
144
147
 
148
+ interface BubbleMenuProps {
149
+ editor: Editor | null;
150
+ }
151
+ declare function BubbleMenu({ editor }: BubbleMenuProps): react.JSX.Element | null;
152
+
145
153
  declare function RichTextEditorRoot({ editor, children, className, labels, icons, variant, editable, }: RichTextEditorProps): react.JSX.Element;
146
154
  declare const RichTextEditor: typeof RichTextEditorRoot & {
147
155
  Toolbar: typeof Toolbar;
148
156
  Footer: typeof Footer;
149
157
  ControlsGroup: typeof ControlsGroup;
150
158
  Content: typeof Content;
159
+ BubbleMenu: typeof BubbleMenu;
151
160
  Control: typeof RichTextEditorControl;
152
161
  Link: typeof LinkControl;
153
162
  YouTubeEmbed: typeof YouTubeEmbedControl;
@@ -327,4 +336,6 @@ declare function useRichTextEditorContext(): RichTextEditorContextValue;
327
336
 
328
337
  declare const Link: _tiptap_core.Mark<_tiptap_extension_link.LinkOptions, any>;
329
338
 
330
- export { DEFAULT_ICONS, DEFAULT_LABELS, Link, RichTextEditor, type RichTextEditorFooterProps, type RichTextEditorIcons, type RichTextEditorLabels, type RichTextEditorProps, type RichTextEditorVariant, TwitterEmbed, type WordCountInfo, YouTubeEmbed, useRichTextEditorContext };
339
+ declare const CodeBlock: _tiptap_core.Node<_tiptap_extension_code_block_lowlight.CodeBlockLowlightOptions, any>;
340
+
341
+ export { BubbleMenu, CodeBlock, DEFAULT_ICONS, DEFAULT_LABELS, DEFAULT_LANGUAGE_ICONS, Link, RichTextEditor, type RichTextEditorFooterProps, type RichTextEditorIcons, type RichTextEditorLabels, type RichTextEditorProps, type RichTextEditorVariant, TwitterEmbed, type WordCountInfo, YouTubeEmbed, useRichTextEditorContext };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/rte-text-editor.tsx
2
- import { useMemo as useMemo2, useEffect as useEffect5 } from "react";
2
+ import { useMemo as useMemo2, useEffect as useEffect7 } from "react";
3
3
 
4
4
  // src/ui/utils.ts
5
5
  import { clsx } from "clsx";
@@ -66,7 +66,28 @@ var DEFAULT_LABELS = {
66
66
  // src/icons.tsx
67
67
  import "react";
68
68
  import { jsx, jsxs } from "react/jsx-runtime";
69
+ var iconProps = { className: "rte-editor-icon" };
69
70
  function Svg({
71
+ children,
72
+ className,
73
+ strokeWidth = 2
74
+ }) {
75
+ return /* @__PURE__ */ jsx(
76
+ "svg",
77
+ {
78
+ xmlns: "http://www.w3.org/2000/svg",
79
+ viewBox: "0 0 24 24",
80
+ fill: "none",
81
+ stroke: "currentColor",
82
+ strokeWidth,
83
+ strokeLinecap: "round",
84
+ strokeLinejoin: "round",
85
+ className,
86
+ children
87
+ }
88
+ );
89
+ }
90
+ function LangIcon({
70
91
  children,
71
92
  className
72
93
  }) {
@@ -77,7 +98,7 @@ function Svg({
77
98
  viewBox: "0 0 24 24",
78
99
  fill: "none",
79
100
  stroke: "currentColor",
80
- strokeWidth: 2,
101
+ strokeWidth: 1.5,
81
102
  strokeLinecap: "round",
82
103
  strokeLinejoin: "round",
83
104
  className,
@@ -85,7 +106,120 @@ function Svg({
85
106
  }
86
107
  );
87
108
  }
88
- var iconProps = { className: "rte-editor-icon" };
109
+ var DEFAULT_LANGUAGE_ICONS = {
110
+ javascript: /* @__PURE__ */ jsxs(LangIcon, { children: [
111
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
112
+ /* @__PURE__ */ jsx("path", { d: "M10.5 8v6.5a2 2 0 0 1-3.5 1.3" }),
113
+ /* @__PURE__ */ 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" })
114
+ ] }),
115
+ typescript: /* @__PURE__ */ jsxs(LangIcon, { children: [
116
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
117
+ /* @__PURE__ */ jsx("path", { d: "M7.3 8.2h5M9.8 8.2v7.6" }),
118
+ /* @__PURE__ */ 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" })
119
+ ] }),
120
+ html: /* @__PURE__ */ jsxs(LangIcon, { children: [
121
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
122
+ /* @__PURE__ */ jsx("path", { d: "M9.5 8.5L6.5 12l3 3.5" }),
123
+ /* @__PURE__ */ jsx("path", { d: "M14.5 8.5L17.5 12l-3 3.5" }),
124
+ /* @__PURE__ */ jsx("path", { d: "M13 7.3l-2 9.4" })
125
+ ] }),
126
+ css: /* @__PURE__ */ jsxs(LangIcon, { children: [
127
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
128
+ /* @__PURE__ */ jsx("path", { d: "M9.7 7.5l-1 9" }),
129
+ /* @__PURE__ */ jsx("path", { d: "M15.3 7.5l-1 9" }),
130
+ /* @__PURE__ */ jsx("path", { d: "M7 10.3h11" }),
131
+ /* @__PURE__ */ jsx("path", { d: "M6.5 14.3h11" })
132
+ ] }),
133
+ json: /* @__PURE__ */ jsxs(LangIcon, { children: [
134
+ /* @__PURE__ */ 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" }),
135
+ /* @__PURE__ */ 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" })
136
+ ] }),
137
+ python: /* @__PURE__ */ jsxs(LangIcon, { children: [
138
+ /* @__PURE__ */ jsx("path", { d: "M4.5 15c0-3 2.5-4.7 5.7-4.7h1.6c2.8 0 5-2 5-4.5" }),
139
+ /* @__PURE__ */ jsx("path", { d: "M9.5 3.3c1.3-.3 2.6 0 3.3 1-.7 1-2 1.3-3.3 1" }),
140
+ /* @__PURE__ */ jsx("circle", { cx: "15.5", cy: "4.3", r: ".55", fill: "currentColor", stroke: "none" }),
141
+ /* @__PURE__ */ jsx("path", { d: "M17.8 4.5l1.4-.6M17.8 4.9l1.4.6" })
142
+ ] }),
143
+ rust: /* @__PURE__ */ jsxs(LangIcon, { children: [
144
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "7" }),
145
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "2.3" }),
146
+ /* @__PURE__ */ jsx("path", { d: "M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3" }),
147
+ /* @__PURE__ */ 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" })
148
+ ] }),
149
+ go: /* @__PURE__ */ jsxs(LangIcon, { children: [
150
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
151
+ /* @__PURE__ */ jsx("path", { d: "M12.6 9.7A3.3 3.3 0 1 0 12.6 14.3" }),
152
+ /* @__PURE__ */ jsx("path", { d: "M12.6 12h-1.9" }),
153
+ /* @__PURE__ */ jsx("circle", { cx: "17", cy: "12", r: "2.9" })
154
+ ] }),
155
+ java: /* @__PURE__ */ jsxs(LangIcon, { children: [
156
+ /* @__PURE__ */ jsx("path", { d: "M6 10h10v5a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-5z" }),
157
+ /* @__PURE__ */ jsx("path", { d: "M16 12h1.3a1.8 1.8 0 0 1 0 3.6H16" }),
158
+ /* @__PURE__ */ 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" }),
159
+ /* @__PURE__ */ jsx("path", { d: "M6 19.3h10" })
160
+ ] }),
161
+ c: /* @__PURE__ */ jsxs(LangIcon, { children: [
162
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "8.5" }),
163
+ /* @__PURE__ */ jsx("path", { d: "M15.6 9.3a4.5 4.5 0 1 0 0 5.4" })
164
+ ] }),
165
+ cpp: /* @__PURE__ */ jsxs(LangIcon, { children: [
166
+ /* @__PURE__ */ jsx("circle", { cx: "9.5", cy: "12", r: "6.5" }),
167
+ /* @__PURE__ */ jsx("path", { d: "M12.3 9.7a3.3 3.3 0 1 0 0 4.6" }),
168
+ /* @__PURE__ */ jsx("path", { d: "M15.7 10.5v3M14.2 12h3" }),
169
+ /* @__PURE__ */ jsx("path", { d: "M19.3 10.5v3M17.8 12h3" })
170
+ ] }),
171
+ ruby: /* @__PURE__ */ jsxs(LangIcon, { children: [
172
+ /* @__PURE__ */ jsx("polygon", { points: "12 2.5 19.5 8 12 21.5 4.5 8" }),
173
+ /* @__PURE__ */ jsx("path", { d: "M4.5 8h15" }),
174
+ /* @__PURE__ */ jsx("path", { d: "M12 2.5v19" })
175
+ ] }),
176
+ php: /* @__PURE__ */ jsxs(LangIcon, { children: [
177
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
178
+ /* @__PURE__ */ jsx("path", { d: "M11.5 8.5L7.5 12l4 3.5" }),
179
+ /* @__PURE__ */ 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" }),
180
+ /* @__PURE__ */ jsx("circle", { cx: "14.3", cy: "16.2", r: ".5", fill: "currentColor", stroke: "none" })
181
+ ] }),
182
+ swift: /* @__PURE__ */ jsx(LangIcon, { children: /* @__PURE__ */ 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" }) }),
183
+ kotlin: /* @__PURE__ */ jsxs(LangIcon, { children: [
184
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
185
+ /* @__PURE__ */ jsx("path", { d: "M9 7.5v9" }),
186
+ /* @__PURE__ */ jsx("path", { d: "M9 12l6-4.5" }),
187
+ /* @__PURE__ */ jsx("path", { d: "M9 12l6 4.5" })
188
+ ] }),
189
+ sql: /* @__PURE__ */ jsxs(LangIcon, { children: [
190
+ /* @__PURE__ */ jsx("ellipse", { cx: "12", cy: "6", rx: "8", ry: "3" }),
191
+ /* @__PURE__ */ jsx("path", { d: "M4 6v6c0 1.7 3.6 3 8 3s8-1.3 8-3V6" }),
192
+ /* @__PURE__ */ jsx("path", { d: "M4 12v6c0 1.7 3.6 3 8 3s8-1.3 8-3v-6" })
193
+ ] }),
194
+ bash: /* @__PURE__ */ jsxs(LangIcon, { children: [
195
+ /* @__PURE__ */ jsx("rect", { x: "2.5", y: "4", width: "19", height: "16", rx: "2" }),
196
+ /* @__PURE__ */ jsx("path", { d: "M6.5 9.5l3.5 3-3.5 3" }),
197
+ /* @__PURE__ */ jsx("path", { d: "M12 15.5h5.5" })
198
+ ] }),
199
+ markdown: /* @__PURE__ */ jsxs(LangIcon, { children: [
200
+ /* @__PURE__ */ jsx("rect", { x: "2", y: "5", width: "20", height: "14", rx: "2" }),
201
+ /* @__PURE__ */ jsx("path", { d: "M6 15V9l3 4 3-4v6" }),
202
+ /* @__PURE__ */ jsx("path", { d: "M16.5 9v6" }),
203
+ /* @__PURE__ */ jsx("path", { d: "M14.5 13l2 2 2-2" })
204
+ ] }),
205
+ yaml: /* @__PURE__ */ jsxs(LangIcon, { children: [
206
+ /* @__PURE__ */ jsx("rect", { x: "2.5", y: "3", width: "19", height: "18", rx: "2" }),
207
+ /* @__PURE__ */ jsx("path", { d: "M6.5 8h2M9.5 8h8" }),
208
+ /* @__PURE__ */ jsx("path", { d: "M6.5 12h2M9.5 12h6" }),
209
+ /* @__PURE__ */ jsx("path", { d: "M6.5 16h2M9.5 16h7" })
210
+ ] }),
211
+ xml: /* @__PURE__ */ jsxs(LangIcon, { children: [
212
+ /* @__PURE__ */ jsx("path", { d: "M8 7l-4.5 5 4.5 5" }),
213
+ /* @__PURE__ */ jsx("path", { d: "M16 7l4.5 5-4.5 5" }),
214
+ /* @__PURE__ */ jsx("path", { d: "M12 8v8" })
215
+ ] }),
216
+ plaintext: /* @__PURE__ */ jsxs(LangIcon, { children: [
217
+ /* @__PURE__ */ jsx("rect", { x: "4", y: "2.5", width: "16", height: "19", rx: "2" }),
218
+ /* @__PURE__ */ jsx("line", { x1: "7.5", y1: "7.5", x2: "16.5", y2: "7.5" }),
219
+ /* @__PURE__ */ jsx("line", { x1: "7.5", y1: "11.5", x2: "16.5", y2: "11.5" }),
220
+ /* @__PURE__ */ jsx("line", { x1: "7.5", y1: "15.5", x2: "13.5", y2: "15.5" })
221
+ ] })
222
+ };
89
223
  var DEFAULT_ICONS = {
90
224
  boldControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
91
225
  /* @__PURE__ */ jsx("path", { d: "M6 4h7a4 4 0 0 1 0 8H6z" }),
@@ -233,7 +367,8 @@ var DEFAULT_ICONS = {
233
367
  /* @__PURE__ */ jsx("path", { d: "m4 20 8-9" }),
234
368
  /* @__PURE__ */ jsx("path", { d: "m12 20-8-9" }),
235
369
  /* @__PURE__ */ 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" })
236
- ] })
370
+ ] }),
371
+ languageIcons: DEFAULT_LANGUAGE_ICONS
237
372
  };
238
373
 
239
374
  // src/rte-toolbar.tsx
@@ -1530,8 +1665,305 @@ function TwitterEmbedControl({ className }) {
1530
1665
  ] });
1531
1666
  }
1532
1667
 
1668
+ // src/bubble-menu/index.tsx
1669
+ import { useState as useState7, useEffect as useEffect6, useCallback as useCallback4 } from "react";
1670
+ import "@tiptap/react";
1671
+ import { isTextSelection } from "@tiptap/core";
1672
+
1673
+ // src/bubble-menu/language-selector.tsx
1674
+ import { useState as useState6 } from "react";
1675
+ import "@tiptap/react";
1676
+
1677
+ // src/bubble-menu/utils.ts
1678
+ import { useState as useState5, useEffect as useEffect5, useRef as useRef4 } from "react";
1679
+ import "@tiptap/react";
1680
+ function useEditorState5(editor, selector) {
1681
+ const selectorRef = useRef4(selector);
1682
+ selectorRef.current = selector;
1683
+ const [state, setState] = useState5(
1684
+ () => editor ? selector(editor) : void 0
1685
+ );
1686
+ useEffect5(() => {
1687
+ if (!editor) return;
1688
+ const update = () => setState(selectorRef.current(editor));
1689
+ update();
1690
+ editor.on("selectionUpdate", update);
1691
+ editor.on("transaction", update);
1692
+ return () => {
1693
+ editor.off("selectionUpdate", update);
1694
+ editor.off("transaction", update);
1695
+ };
1696
+ }, [editor]);
1697
+ return state;
1698
+ }
1699
+ var CODE_BLOCK_LANGUAGES = [
1700
+ "javascript",
1701
+ "typescript",
1702
+ "html",
1703
+ "css",
1704
+ "json",
1705
+ "python",
1706
+ "rust",
1707
+ "go",
1708
+ "java",
1709
+ "c",
1710
+ "cpp",
1711
+ "ruby",
1712
+ "php",
1713
+ "swift",
1714
+ "kotlin",
1715
+ "sql",
1716
+ "bash",
1717
+ "markdown",
1718
+ "yaml",
1719
+ "xml",
1720
+ "plaintext"
1721
+ ];
1722
+
1723
+ // src/bubble-menu/language-selector.tsx
1724
+ import { Fragment as Fragment2, jsx as jsx16, jsxs as jsxs9 } from "react/jsx-runtime";
1725
+ function FallbackIcon() {
1726
+ return /* @__PURE__ */ jsxs9(
1727
+ "svg",
1728
+ {
1729
+ xmlns: "http://www.w3.org/2000/svg",
1730
+ viewBox: "0 0 24 24",
1731
+ fill: "none",
1732
+ stroke: "currentColor",
1733
+ strokeWidth: 2,
1734
+ strokeLinecap: "round",
1735
+ strokeLinejoin: "round",
1736
+ className: "rte-editor-icon",
1737
+ children: [
1738
+ /* @__PURE__ */ jsx16("polyline", { points: "16 18 22 12 16 6" }),
1739
+ /* @__PURE__ */ jsx16("polyline", { points: "8 6 2 12 8 18" })
1740
+ ]
1741
+ }
1742
+ );
1743
+ }
1744
+ function LanguageSelector({ editor }) {
1745
+ const [open, setOpen] = useState6(false);
1746
+ const { icons } = useRichTextEditorContext();
1747
+ const { currentLanguage } = useEditorState5(editor, (ed) => ({
1748
+ currentLanguage: ed.getAttributes("codeBlock").language || "javascript"
1749
+ }));
1750
+ const langIcon = icons.languageIcons[currentLanguage] ?? /* @__PURE__ */ jsx16(FallbackIcon, {});
1751
+ return /* @__PURE__ */ jsxs9("div", { style: { position: "relative" }, children: [
1752
+ /* @__PURE__ */ jsxs9(
1753
+ "button",
1754
+ {
1755
+ type: "button",
1756
+ className: "rte-bubble-btn",
1757
+ onMouseDown: (e) => e.preventDefault(),
1758
+ onClick: () => setOpen(!open),
1759
+ children: [
1760
+ /* @__PURE__ */ jsx16("span", { className: "rte-bubble-btn-icon", children: langIcon }),
1761
+ /* @__PURE__ */ jsx16("span", { className: "rte-bubble-btn-text", children: currentLanguage }),
1762
+ /* @__PURE__ */ jsx16("span", { className: "rte-bubble-btn-icon", style: { width: 12, height: 12 }, children: /* @__PURE__ */ jsx16(
1763
+ "svg",
1764
+ {
1765
+ xmlns: "http://www.w3.org/2000/svg",
1766
+ viewBox: "0 0 24 24",
1767
+ fill: "none",
1768
+ stroke: "currentColor",
1769
+ strokeWidth: 2,
1770
+ strokeLinecap: "round",
1771
+ strokeLinejoin: "round",
1772
+ children: /* @__PURE__ */ jsx16("path", { d: "m6 9 6 6 6-6" })
1773
+ }
1774
+ ) })
1775
+ ]
1776
+ }
1777
+ ),
1778
+ open && /* @__PURE__ */ jsxs9(Fragment2, { children: [
1779
+ /* @__PURE__ */ jsx16("div", { className: "rte-bubble-overlay", onClick: () => setOpen(false) }),
1780
+ /* @__PURE__ */ jsx16(
1781
+ "div",
1782
+ {
1783
+ className: "rte-bubble-dropdown rte-bubble-dropdown--language",
1784
+ children: CODE_BLOCK_LANGUAGES.map((lang) => /* @__PURE__ */ jsxs9(
1785
+ "button",
1786
+ {
1787
+ type: "button",
1788
+ className: `rte-bubble-dropdown-item${currentLanguage === lang ? " rte-bubble-dropdown-item--active" : ""}`,
1789
+ onMouseDown: (e) => e.preventDefault(),
1790
+ onClick: () => {
1791
+ editor.chain().focus().updateAttributes("codeBlock", { language: lang }).run();
1792
+ setOpen(false);
1793
+ },
1794
+ children: [
1795
+ /* @__PURE__ */ jsx16("span", { className: "rte-bubble-dropdown-icon", children: icons.languageIcons[lang] ?? /* @__PURE__ */ jsx16(FallbackIcon, {}) }),
1796
+ /* @__PURE__ */ jsx16("span", { children: lang }),
1797
+ currentLanguage === lang && /* @__PURE__ */ jsx16("span", { className: "rte-bubble-dropdown-icon", children: /* @__PURE__ */ jsx16(
1798
+ "svg",
1799
+ {
1800
+ xmlns: "http://www.w3.org/2000/svg",
1801
+ viewBox: "0 0 24 24",
1802
+ fill: "none",
1803
+ stroke: "currentColor",
1804
+ strokeWidth: 2,
1805
+ strokeLinecap: "round",
1806
+ strokeLinejoin: "round",
1807
+ children: /* @__PURE__ */ jsx16("polyline", { points: "20 6 9 17 4 12" })
1808
+ }
1809
+ ) })
1810
+ ]
1811
+ },
1812
+ lang
1813
+ ))
1814
+ }
1815
+ )
1816
+ ] })
1817
+ ] });
1818
+ }
1819
+
1820
+ // src/bubble-menu/text-buttons.tsx
1821
+ import "@tiptap/react";
1822
+ import { jsx as jsx17, jsxs as jsxs10 } from "react/jsx-runtime";
1823
+ function Svg2({ children, strokeWidth = 2 }) {
1824
+ return /* @__PURE__ */ jsx17(
1825
+ "svg",
1826
+ {
1827
+ xmlns: "http://www.w3.org/2000/svg",
1828
+ viewBox: "0 0 24 24",
1829
+ fill: "none",
1830
+ stroke: "currentColor",
1831
+ strokeWidth,
1832
+ strokeLinecap: "round",
1833
+ strokeLinejoin: "round",
1834
+ className: "rte-editor-icon",
1835
+ children
1836
+ }
1837
+ );
1838
+ }
1839
+ var textItems = [
1840
+ {
1841
+ icon: /* @__PURE__ */ jsxs10(Svg2, { children: [
1842
+ /* @__PURE__ */ jsx17("path", { d: "M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" }),
1843
+ /* @__PURE__ */ jsx17("path", { d: "M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" })
1844
+ ] }),
1845
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- extension commands not in base ChainedCommands
1846
+ command: (e) => e.chain().focus().toggleBold().run(),
1847
+ isActive: (s) => s.isBold
1848
+ },
1849
+ {
1850
+ icon: /* @__PURE__ */ jsxs10(Svg2, { children: [
1851
+ /* @__PURE__ */ jsx17("line", { x1: "19", y1: "4", x2: "10", y2: "4" }),
1852
+ /* @__PURE__ */ jsx17("line", { x1: "14", y1: "20", x2: "5", y2: "20" }),
1853
+ /* @__PURE__ */ jsx17("line", { x1: "15", y1: "4", x2: "9", y2: "20" })
1854
+ ] }),
1855
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1856
+ command: (e) => e.chain().focus().toggleItalic().run(),
1857
+ isActive: (s) => s.isItalic
1858
+ },
1859
+ {
1860
+ icon: /* @__PURE__ */ jsxs10(Svg2, { children: [
1861
+ /* @__PURE__ */ jsx17("path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }),
1862
+ /* @__PURE__ */ jsx17("line", { x1: "4", y1: "20", x2: "20", y2: "20" })
1863
+ ] }),
1864
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1865
+ command: (e) => e.chain().focus().toggleUnderline().run(),
1866
+ isActive: (s) => s.isUnderline
1867
+ },
1868
+ {
1869
+ icon: /* @__PURE__ */ jsxs10(Svg2, { children: [
1870
+ /* @__PURE__ */ jsx17("path", { d: "M16 4H9.5a3.5 3.5 0 0 0-2.9 5.4" }),
1871
+ /* @__PURE__ */ jsx17("path", { d: "M14.5 14.6a3.5 3.5 0 0 1-2.9 5.4H8" }),
1872
+ /* @__PURE__ */ jsx17("line", { x1: "4", y1: "12", x2: "20", y2: "12" })
1873
+ ] }),
1874
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1875
+ command: (e) => e.chain().focus().toggleStrike().run(),
1876
+ isActive: (s) => s.isStrike
1877
+ },
1878
+ {
1879
+ icon: /* @__PURE__ */ jsxs10(Svg2, { children: [
1880
+ /* @__PURE__ */ jsx17("polyline", { points: "16 18 22 12 16 6" }),
1881
+ /* @__PURE__ */ jsx17("polyline", { points: "8 6 2 12 8 18" })
1882
+ ] }),
1883
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1884
+ command: (e) => e.chain().focus().toggleCode().run(),
1885
+ isActive: (s) => s.isCode
1886
+ }
1887
+ ];
1888
+ function TextButtons({ editor }) {
1889
+ const editorState = useEditorState5(editor, (ed) => ({
1890
+ isBold: ed.isActive("bold"),
1891
+ isItalic: ed.isActive("italic"),
1892
+ isUnderline: ed.isActive("underline"),
1893
+ isStrike: ed.isActive("strike"),
1894
+ isCode: ed.isActive("code")
1895
+ }));
1896
+ return /* @__PURE__ */ jsx17("div", { className: "rte-bubble-group", children: textItems.map((item, i) => /* @__PURE__ */ jsx17(
1897
+ "button",
1898
+ {
1899
+ type: "button",
1900
+ className: `rte-bubble-btn${item.isActive(editorState) ? " rte-bubble-btn--active" : ""}`,
1901
+ onMouseDown: (e) => e.preventDefault(),
1902
+ onClick: () => item.command(editor),
1903
+ children: item.icon
1904
+ },
1905
+ i
1906
+ )) });
1907
+ }
1908
+
1909
+ // src/bubble-menu/index.tsx
1910
+ import { jsx as jsx18 } from "react/jsx-runtime";
1911
+ var BubbleMenuComponent = null;
1912
+ var bubbleMenuPromise = (async () => {
1913
+ try {
1914
+ const mod = await import("@tiptap/react/menus");
1915
+ BubbleMenuComponent = mod.BubbleMenu;
1916
+ } catch {
1917
+ try {
1918
+ const mod = await import("@tiptap/react");
1919
+ BubbleMenuComponent = mod.BubbleMenu;
1920
+ } catch {
1921
+ }
1922
+ }
1923
+ })();
1924
+ function BubbleMenu({ editor }) {
1925
+ const [loaded, setLoaded] = useState7(BubbleMenuComponent !== null);
1926
+ const editorState = useEditorState5(editor, (ed) => ({
1927
+ isCodeBlock: ed.isActive("codeBlock")
1928
+ }));
1929
+ useEffect6(() => {
1930
+ if (BubbleMenuComponent !== null) {
1931
+ setLoaded(true);
1932
+ return;
1933
+ }
1934
+ let active = true;
1935
+ bubbleMenuPromise.then(() => {
1936
+ if (active) setLoaded(true);
1937
+ });
1938
+ return () => {
1939
+ active = false;
1940
+ };
1941
+ }, []);
1942
+ const shouldShow = useCallback4(
1943
+ ({ editor: ed, state }) => {
1944
+ const { selection } = state;
1945
+ if (!ed.isEditable) return false;
1946
+ if (selection.empty && !ed.isActive("codeBlock")) return false;
1947
+ if (!selection.empty && !isTextSelection(selection)) return false;
1948
+ return true;
1949
+ },
1950
+ []
1951
+ );
1952
+ if (!editor || !BubbleMenuComponent || !loaded) return null;
1953
+ const isCodeBlockActive = editorState?.isCodeBlock ?? false;
1954
+ return /* @__PURE__ */ jsx18(
1955
+ BubbleMenuComponent,
1956
+ {
1957
+ editor,
1958
+ tippyOptions: { placement: "top", offset: [0, 8], hideOnClick: false },
1959
+ shouldShow,
1960
+ children: /* @__PURE__ */ jsx18("div", { className: "rte-bubble-menu", children: isCodeBlockActive ? /* @__PURE__ */ jsx18(LanguageSelector, { editor }) : /* @__PURE__ */ jsx18(TextButtons, { editor }) })
1961
+ }
1962
+ );
1963
+ }
1964
+
1533
1965
  // src/rte-text-editor.tsx
1534
- import { jsx as jsx16 } from "react/jsx-runtime";
1966
+ import { jsx as jsx19 } from "react/jsx-runtime";
1535
1967
  function RichTextEditorRoot({
1536
1968
  editor,
1537
1969
  children,
@@ -1549,12 +1981,12 @@ function RichTextEditorRoot({
1549
1981
  () => ({ ...DEFAULT_ICONS, ...icons }),
1550
1982
  [icons]
1551
1983
  );
1552
- useEffect5(() => {
1984
+ useEffect7(() => {
1553
1985
  if (editor && editor.isEditable !== editable) {
1554
1986
  editor.setEditable(editable);
1555
1987
  }
1556
1988
  }, [editor, editable]);
1557
- return /* @__PURE__ */ jsx16(RichTextEditorContext.Provider, { value: { editor, labels: mergedLabels, icons: mergedIcons, variant, editable }, children: /* @__PURE__ */ jsx16(
1989
+ return /* @__PURE__ */ jsx19(RichTextEditorContext.Provider, { value: { editor, labels: mergedLabels, icons: mergedIcons, variant, editable }, children: /* @__PURE__ */ jsx19(
1558
1990
  "div",
1559
1991
  {
1560
1992
  className: cn(
@@ -1572,6 +2004,7 @@ var RichTextEditor = Object.assign(RichTextEditorRoot, {
1572
2004
  Footer,
1573
2005
  ControlsGroup,
1574
2006
  Content,
2007
+ BubbleMenu,
1575
2008
  Control: RichTextEditorControl,
1576
2009
  Link: LinkControl,
1577
2010
  YouTubeEmbed: YouTubeEmbedControl,
@@ -1617,9 +2050,21 @@ var Link = TipTapLink.extend({
1617
2050
  };
1618
2051
  }
1619
2052
  }).configure({ openOnClick: false });
2053
+
2054
+ // src/extensions/code-block.ts
2055
+ import LowlightCodeBlock from "@tiptap/extension-code-block-lowlight";
2056
+ import { common, createLowlight } from "lowlight";
2057
+ var lowlight = createLowlight(common);
2058
+ var CodeBlock = LowlightCodeBlock.configure({
2059
+ lowlight,
2060
+ defaultLanguage: "javascript"
2061
+ });
1620
2062
  export {
2063
+ BubbleMenu,
2064
+ CodeBlock,
1621
2065
  DEFAULT_ICONS,
1622
2066
  DEFAULT_LABELS,
2067
+ DEFAULT_LANGUAGE_ICONS,
1623
2068
  Link,
1624
2069
  RichTextEditor,
1625
2070
  TwitterEmbed,