@editorcn/editor 0.1.2 → 0.3.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.js CHANGED
@@ -1,18 +1,18 @@
1
1
  // src/rte-text-editor.tsx
2
2
  import { useMemo as useMemo2, useEffect as useEffect5 } from "react";
3
3
 
4
- // src/ui/utils.ts
5
- import { clsx } from "clsx";
6
- import { twMerge } from "tailwind-merge";
7
- function cn(...inputs) {
8
- return twMerge(clsx(inputs));
9
- }
4
+ // src/bubble-menu/index.tsx
5
+ import { isTextSelection } from "@tiptap/core";
6
+ import { BubbleMenu as TiptapBubbleMenu } from "@tiptap/react/menus";
7
+ import { useCallback as useCallback2 } from "react";
8
+
9
+ // src/bubble-menu/language-selector.tsx
10
+ import { useState } from "react";
10
11
 
11
12
  // src/rte-context.ts
12
- import "@tiptap/react";
13
13
  import { createContext, useContext } from "react";
14
14
  var RichTextEditorContext = createContext(null);
15
- function useRichTextEditorContext() {
15
+ var useRichTextEditorContext = () => {
16
16
  const context = useContext(RichTextEditorContext);
17
17
  if (!context) {
18
18
  throw new Error(
@@ -20,975 +20,818 @@ function useRichTextEditorContext() {
20
20
  );
21
21
  }
22
22
  return context;
23
- }
24
-
25
- // src/labels.ts
26
- var DEFAULT_LABELS = {
27
- boldControlLabel: "Bold",
28
- italicControlLabel: "Italic",
29
- underlineControlLabel: "Underline",
30
- strikeControlLabel: "Strikethrough",
31
- clearFormattingControlLabel: "Clear formatting",
32
- codeControlLabel: "Code",
33
- codeBlockControlLabel: "Code block",
34
- h1ControlLabel: "Heading 1",
35
- h2ControlLabel: "Heading 2",
36
- h3ControlLabel: "Heading 3",
37
- h4ControlLabel: "Heading 4",
38
- h5ControlLabel: "Heading 5",
39
- h6ControlLabel: "Heading 6",
40
- bulletListControlLabel: "Bullet list",
41
- orderedListControlLabel: "Ordered list",
42
- blockquoteControlLabel: "Blockquote",
43
- hrControlLabel: "Horizontal rule",
44
- linkControlLabel: "Link",
45
- unlinkControlLabel: "Remove link",
46
- undoControlLabel: "Undo",
47
- redoControlLabel: "Redo",
48
- alignLeftControlLabel: "Align left",
49
- alignCenterControlLabel: "Align center",
50
- alignRightControlLabel: "Align right",
51
- alignJustifyControlLabel: "Align justify",
52
- highlightControlLabel: "Highlight",
53
- subscriptControlLabel: "Subscript",
54
- superscriptControlLabel: "Superscript",
55
- tasksControlLabel: "Task list",
56
- tasksSinkLabel: "Decrease task level",
57
- tasksLiftLabel: "Increase task level",
58
- sourceCodeControlLabel: "Source code",
59
- linkEditorInputLabel: "Enter URL",
60
- linkEditorInputPlaceholder: "https://example.com",
61
- linkEditorExternalLink: "Open in new tab",
62
- linkEditorInternalLink: "Open in same tab",
63
- linkEditorSave: "Save"
64
23
  };
65
24
 
66
- // src/icons.tsx
67
- import "react";
68
- import { jsx, jsxs } from "react/jsx-runtime";
69
- function Svg({
70
- children,
71
- className
72
- }) {
73
- return /* @__PURE__ */ jsx(
74
- "svg",
75
- {
76
- xmlns: "http://www.w3.org/2000/svg",
77
- viewBox: "0 0 24 24",
78
- fill: "none",
79
- stroke: "currentColor",
80
- strokeWidth: 2,
81
- strokeLinecap: "round",
82
- strokeLinejoin: "round",
83
- className,
84
- children
25
+ // src/bubble-menu/utils.ts
26
+ import { useCallback, useRef, useSyncExternalStore } from "react";
27
+ var defaultEqual = (a, b) => a === b;
28
+ var shallowEqual = (a, b) => {
29
+ if (a === b) return true;
30
+ if (!a || !b) return false;
31
+ const ak = Object.keys(a);
32
+ const bk = Object.keys(b);
33
+ if (ak.length !== bk.length) return false;
34
+ return ak.every((k) => a[k] === b[k]);
35
+ };
36
+ var useEditorState = (editor, selector, isEqual = defaultEqual) => {
37
+ const selectorRef = useRef(selector);
38
+ selectorRef.current = selector;
39
+ const isEqualRef = useRef(isEqual);
40
+ isEqualRef.current = isEqual;
41
+ const snapshotRef = useRef({
42
+ value: editor ? selector(editor) : void 0
43
+ });
44
+ const updateSnapshot = useCallback(() => {
45
+ if (!editor) return;
46
+ const next = selectorRef.current(editor);
47
+ if (snapshotRef.current && isEqualRef.current(snapshotRef.current.value, next)) {
48
+ return;
85
49
  }
50
+ snapshotRef.current = { value: next };
51
+ }, [editor]);
52
+ const subscribe = useCallback(
53
+ (onStoreChange) => {
54
+ if (!editor) {
55
+ return () => {
56
+ };
57
+ }
58
+ const update = () => {
59
+ updateSnapshot();
60
+ onStoreChange();
61
+ };
62
+ editor.on("selectionUpdate", update);
63
+ editor.on("transaction", update);
64
+ return () => {
65
+ editor.off("selectionUpdate", update);
66
+ editor.off("transaction", update);
67
+ };
68
+ },
69
+ [editor, updateSnapshot]
86
70
  );
87
- }
88
- var iconProps = { className: "rte-editor-icon" };
89
- var DEFAULT_ICONS = {
90
- boldControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
91
- /* @__PURE__ */ jsx("path", { d: "M6 4h7a4 4 0 0 1 0 8H6z" }),
92
- /* @__PURE__ */ jsx("path", { d: "M6 12h9a4 4 0 0 1 0 8H6z" })
93
- ] }),
94
- italicControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
95
- /* @__PURE__ */ jsx("line", { x1: "19", y1: "4", x2: "10", y2: "4" }),
96
- /* @__PURE__ */ jsx("line", { x1: "14", y1: "20", x2: "5", y2: "20" }),
97
- /* @__PURE__ */ jsx("line", { x1: "15", y1: "4", x2: "9", y2: "20" })
98
- ] }),
99
- underlineControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
100
- /* @__PURE__ */ jsx("path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }),
101
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "20", x2: "20", y2: "20" })
102
- ] }),
103
- strikeControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
104
- /* @__PURE__ */ jsx("path", { d: "M16 4H9.5a3.5 3.5 0 0 0-2.9 5.4" }),
105
- /* @__PURE__ */ jsx("path", { d: "M14.5 14.6a3.5 3.5 0 0 1-2.9 5.4H8" }),
106
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "12", x2: "20", y2: "12" })
107
- ] }),
108
- clearFormattingControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
109
- /* @__PURE__ */ jsx("path", { d: "M4 7V4h16v3" }),
110
- /* @__PURE__ */ jsx("path", { d: "M5 20h6" }),
111
- /* @__PURE__ */ jsx("path", { d: "M13 4 8 20" }),
112
- /* @__PURE__ */ jsx("path", { d: "m16 16 5 5" }),
113
- /* @__PURE__ */ jsx("path", { d: "m21 16-5 5" })
114
- ] }),
115
- codeControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
116
- /* @__PURE__ */ jsx("polyline", { points: "16 18 22 12 16 6" }),
117
- /* @__PURE__ */ jsx("polyline", { points: "8 6 2 12 8 18" })
118
- ] }),
119
- codeBlockControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
120
- /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2" }),
121
- /* @__PURE__ */ jsx("polyline", { points: "10 9 8 12 10 15" }),
122
- /* @__PURE__ */ jsx("polyline", { points: "14 9 16 12 14 15" })
123
- ] }),
124
- h1ControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
125
- /* @__PURE__ */ jsx("path", { d: "M4 6v12" }),
126
- /* @__PURE__ */ jsx("path", { d: "M12 6v12" }),
127
- /* @__PURE__ */ jsx("path", { d: "M4 12h8" }),
128
- /* @__PURE__ */ jsx("path", { d: "m17 10 3-2v8" })
129
- ] }),
130
- h2ControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
131
- /* @__PURE__ */ jsx("path", { d: "M4 6v12" }),
132
- /* @__PURE__ */ jsx("path", { d: "M12 6v12" }),
133
- /* @__PURE__ */ jsx("path", { d: "M4 12h8" }),
134
- /* @__PURE__ */ jsx("path", { d: "M17 9.5a2.5 2.5 0 0 1 4.8-1c0 2-4.8 2.5-4.8 5.5h5" })
135
- ] }),
136
- h3ControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
137
- /* @__PURE__ */ jsx("path", { d: "M4 6v12" }),
138
- /* @__PURE__ */ jsx("path", { d: "M12 6v12" }),
139
- /* @__PURE__ */ jsx("path", { d: "M4 12h8" }),
140
- /* @__PURE__ */ jsx("path", { d: "M17.5 9.5c1.5-1 3.5-.2 3.5 1.3a1.8 1.8 0 0 1-1.8 1.7" }),
141
- /* @__PURE__ */ jsx("path", { d: "M19.2 12.5a1.8 1.8 0 0 1 1.8 1.7c0 1.5-2 2.3-3.5 1.3" })
142
- ] }),
143
- h4ControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
144
- /* @__PURE__ */ jsx("path", { d: "M4 6v12" }),
145
- /* @__PURE__ */ jsx("path", { d: "M12 6v12" }),
146
- /* @__PURE__ */ jsx("path", { d: "M4 12h8" }),
147
- /* @__PURE__ */ jsx("path", { d: "M20 9v5h-4l3.5-5.5" }),
148
- /* @__PURE__ */ jsx("path", { d: "M20 14v3" })
149
- ] }),
150
- h5ControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
151
- /* @__PURE__ */ jsx("path", { d: "M4 6v12" }),
152
- /* @__PURE__ */ jsx("path", { d: "M12 6v12" }),
153
- /* @__PURE__ */ jsx("path", { d: "M4 12h8" }),
154
- /* @__PURE__ */ jsx("path", { d: "M21 9h-4v3.5c2.5-.7 4.5.3 4.5 2a2.3 2.3 0 0 1-4.3 1.3" })
155
- ] }),
156
- h6ControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
157
- /* @__PURE__ */ jsx("path", { d: "M4 6v12" }),
158
- /* @__PURE__ */ jsx("path", { d: "M12 6v12" }),
159
- /* @__PURE__ */ jsx("path", { d: "M4 12h8" }),
160
- /* @__PURE__ */ jsx("path", { d: "M20.5 9.5c-3 1-3.5 4-3.5 5.5a2.5 2.5 0 1 0 2.5-2.5c-1 0-2 .4-2.5 1" })
161
- ] }),
162
- bulletListControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
163
- /* @__PURE__ */ jsx("line", { x1: "9", y1: "6", x2: "21", y2: "6" }),
164
- /* @__PURE__ */ jsx("line", { x1: "9", y1: "12", x2: "21", y2: "12" }),
165
- /* @__PURE__ */ jsx("line", { x1: "9", y1: "18", x2: "21", y2: "18" }),
166
- /* @__PURE__ */ jsx("circle", { cx: "4", cy: "6", r: "1.2", fill: "currentColor", stroke: "none" }),
167
- /* @__PURE__ */ jsx("circle", { cx: "4", cy: "12", r: "1.2", fill: "currentColor", stroke: "none" }),
168
- /* @__PURE__ */ jsx("circle", { cx: "4", cy: "18", r: "1.2", fill: "currentColor", stroke: "none" })
169
- ] }),
170
- orderedListControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
171
- /* @__PURE__ */ jsx("line", { x1: "10", y1: "6", x2: "21", y2: "6" }),
172
- /* @__PURE__ */ jsx("line", { x1: "10", y1: "12", x2: "21", y2: "12" }),
173
- /* @__PURE__ */ jsx("line", { x1: "10", y1: "18", x2: "21", y2: "18" }),
174
- /* @__PURE__ */ jsx("path", { d: "M4 5h2v4" }),
175
- /* @__PURE__ */ jsx("path", { d: "M4 9h2" }),
176
- /* @__PURE__ */ jsx("path", { d: "M4 13h2.5L4 16h2.5" }),
177
- /* @__PURE__ */ jsx("path", { d: "M4 19h2.5" })
178
- ] }),
179
- blockquoteControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
180
- /* @__PURE__ */ jsx("path", { d: "M7 8a3 3 0 0 0-3 3v2a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1H6a3 3 0 0 1 2-3" }),
181
- /* @__PURE__ */ jsx("path", { d: "M16 8a3 3 0 0 0-3 3v2a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1h-1a3 3 0 0 1 2-3" })
182
- ] }),
183
- hrControlIcon: /* @__PURE__ */ jsx(Svg, { ...iconProps, children: /* @__PURE__ */ jsx("line", { x1: "4", y1: "12", x2: "20", y2: "12" }) }),
184
- linkControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
185
- /* @__PURE__ */ jsx("path", { d: "M9 17H7a5 5 0 0 1 0-10h2" }),
186
- /* @__PURE__ */ jsx("path", { d: "M15 7h2a5 5 0 0 1 0 10h-2" }),
187
- /* @__PURE__ */ jsx("line", { x1: "8", y1: "12", x2: "16", y2: "12" })
188
- ] }),
189
- unlinkControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
190
- /* @__PURE__ */ jsx("path", { d: "M9 17H7a5 5 0 0 1-1.7-9.7" }),
191
- /* @__PURE__ */ jsx("path", { d: "M15 7h2a5 5 0 0 1 1.7 9.7" }),
192
- /* @__PURE__ */ jsx("line", { x1: "3", y1: "3", x2: "21", y2: "21" })
193
- ] }),
194
- undoControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
195
- /* @__PURE__ */ jsx("path", { d: "M9 14 4 9l5-5" }),
196
- /* @__PURE__ */ jsx("path", { d: "M4 9h10.5a5.5 5.5 0 0 1 0 11H11" })
197
- ] }),
198
- redoControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
199
- /* @__PURE__ */ jsx("path", { d: "m15 14 5-5-5-5" }),
200
- /* @__PURE__ */ jsx("path", { d: "M20 9H9.5a5.5 5.5 0 0 0 0 11H13" })
201
- ] }),
202
- alignLeftControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
203
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
204
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "12", x2: "14", y2: "12" }),
205
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "18", x2: "17", y2: "18" })
206
- ] }),
207
- alignCenterControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
208
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
209
- /* @__PURE__ */ jsx("line", { x1: "7", y1: "12", x2: "17", y2: "12" }),
210
- /* @__PURE__ */ jsx("line", { x1: "5.5", y1: "18", x2: "18.5", y2: "18" })
211
- ] }),
212
- alignRightControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
213
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
214
- /* @__PURE__ */ jsx("line", { x1: "10", y1: "12", x2: "20", y2: "12" }),
215
- /* @__PURE__ */ jsx("line", { x1: "7", y1: "18", x2: "20", y2: "18" })
216
- ] }),
217
- alignJustifyControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
218
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
219
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "12", x2: "20", y2: "12" }),
220
- /* @__PURE__ */ jsx("line", { x1: "4", y1: "18", x2: "20", y2: "18" })
221
- ] }),
222
- highlightControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
223
- /* @__PURE__ */ jsx("path", { d: "M9 11 3 17v3h3l6-6" }),
224
- /* @__PURE__ */ jsx("path", { d: "M14 6l4-4 4 4-4 4" }),
225
- /* @__PURE__ */ jsx("path", { d: "m9 11 4-4 5 5-4 4" })
226
- ] }),
227
- subscriptControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
228
- /* @__PURE__ */ jsx("path", { d: "m4 4 8 9" }),
229
- /* @__PURE__ */ jsx("path", { d: "m12 4-8 9" }),
230
- /* @__PURE__ */ jsx("path", { d: "M19 16h-3.5c0-1.6 3.5-1.9 3.5-3.8a1.8 1.8 0 0 0-3.3-1" })
231
- ] }),
232
- superscriptControlIcon: /* @__PURE__ */ jsxs(Svg, { ...iconProps, children: [
233
- /* @__PURE__ */ jsx("path", { d: "m4 20 8-9" }),
234
- /* @__PURE__ */ jsx("path", { d: "m12 20-8-9" }),
235
- /* @__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
- ] })
71
+ const getSnapshot = useCallback(() => snapshotRef.current.value, []);
72
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
237
73
  };
74
+ var CODE_BLOCK_LANGUAGES = [
75
+ "javascript",
76
+ "typescript",
77
+ "html",
78
+ "css",
79
+ "json",
80
+ "python",
81
+ "rust",
82
+ "go",
83
+ "java",
84
+ "c",
85
+ "cpp",
86
+ "ruby",
87
+ "php",
88
+ "swift",
89
+ "kotlin",
90
+ "sql",
91
+ "bash",
92
+ "markdown",
93
+ "yaml",
94
+ "xml",
95
+ "plaintext"
96
+ ];
238
97
 
239
- // src/rte-toolbar.tsx
240
- import { jsx as jsx2 } from "react/jsx-runtime";
241
- function Toolbar({
242
- children,
243
- className,
244
- sticky,
245
- stickyOffset = 0
246
- }) {
247
- const { variant, editable } = useRichTextEditorContext();
248
- if (!editable) return null;
249
- return /* @__PURE__ */ jsx2(
250
- "div",
251
- {
252
- className: cn(
253
- "rte-toolbar",
254
- variant !== "default" && `rte-toolbar--${variant}`,
255
- sticky && "sticky z-10",
256
- className
257
- ),
258
- "data-sticky": sticky ? "" : void 0,
259
- style: sticky ? { top: stickyOffset } : void 0,
260
- children
261
- }
98
+ // src/bubble-menu/language-selector.tsx
99
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
100
+ var FallbackIcon = () => /* @__PURE__ */ jsxs(
101
+ "svg",
102
+ {
103
+ xmlns: "http://www.w3.org/2000/svg",
104
+ viewBox: "0 0 24 24",
105
+ fill: "none",
106
+ stroke: "currentColor",
107
+ strokeWidth: 2,
108
+ strokeLinecap: "round",
109
+ strokeLinejoin: "round",
110
+ className: "rte-editor-icon",
111
+ children: [
112
+ /* @__PURE__ */ jsx("polyline", { points: "16 18 22 12 16 6" }),
113
+ /* @__PURE__ */ jsx("polyline", { points: "8 6 2 12 8 18" })
114
+ ]
115
+ }
116
+ );
117
+ var LanguageSelector = ({ editor }) => {
118
+ const [open, setOpen] = useState(false);
119
+ const { icons } = useRichTextEditorContext();
120
+ const { currentLanguage } = useEditorState(
121
+ editor,
122
+ (ed) => ({
123
+ currentLanguage: ed.getAttributes("codeBlock").language || "javascript"
124
+ }),
125
+ shallowEqual
262
126
  );
263
- }
127
+ const langIcon = icons.languageIcons[currentLanguage] ?? /* @__PURE__ */ jsx(FallbackIcon, {});
128
+ return /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
129
+ /* @__PURE__ */ jsxs(
130
+ "button",
131
+ {
132
+ type: "button",
133
+ className: "rte-bubble-btn",
134
+ onMouseDown: (e) => e.preventDefault(),
135
+ onClick: () => setOpen(!open),
136
+ children: [
137
+ /* @__PURE__ */ jsx("span", { className: "rte-bubble-btn-icon", children: langIcon }),
138
+ /* @__PURE__ */ jsx("span", { className: "rte-bubble-btn-text", children: currentLanguage }),
139
+ /* @__PURE__ */ jsx("span", { className: "rte-bubble-btn-icon", style: { height: 12, width: 12 }, children: /* @__PURE__ */ jsx(
140
+ "svg",
141
+ {
142
+ xmlns: "http://www.w3.org/2000/svg",
143
+ viewBox: "0 0 24 24",
144
+ fill: "none",
145
+ stroke: "currentColor",
146
+ strokeWidth: 2,
147
+ strokeLinecap: "round",
148
+ strokeLinejoin: "round",
149
+ children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
150
+ }
151
+ ) })
152
+ ]
153
+ }
154
+ ),
155
+ open && /* @__PURE__ */ jsxs(Fragment, { children: [
156
+ /* @__PURE__ */ jsx(
157
+ "div",
158
+ {
159
+ className: "rte-bubble-overlay",
160
+ role: "presentation",
161
+ onClick: () => setOpen(false),
162
+ onKeyDown: (e) => {
163
+ if (e.key === "Escape") {
164
+ setOpen(false);
165
+ }
166
+ }
167
+ }
168
+ ),
169
+ /* @__PURE__ */ jsx("div", { className: "rte-bubble-dropdown rte-bubble-dropdown--language", children: CODE_BLOCK_LANGUAGES.map((lang) => /* @__PURE__ */ jsxs(
170
+ "button",
171
+ {
172
+ type: "button",
173
+ className: `rte-bubble-dropdown-item${currentLanguage === lang ? " rte-bubble-dropdown-item--active" : ""}`,
174
+ onMouseDown: (e) => e.preventDefault(),
175
+ onClick: () => {
176
+ editor.chain().focus().updateAttributes("codeBlock", { language: lang }).run();
177
+ setOpen(false);
178
+ },
179
+ children: [
180
+ /* @__PURE__ */ jsx("span", { className: "rte-bubble-dropdown-icon", children: icons.languageIcons[lang] ?? /* @__PURE__ */ jsx(FallbackIcon, {}) }),
181
+ /* @__PURE__ */ jsx("span", { children: lang }),
182
+ currentLanguage === lang && /* @__PURE__ */ jsx("span", { className: "rte-bubble-dropdown-icon", children: /* @__PURE__ */ jsx(
183
+ "svg",
184
+ {
185
+ xmlns: "http://www.w3.org/2000/svg",
186
+ viewBox: "0 0 24 24",
187
+ fill: "none",
188
+ stroke: "currentColor",
189
+ strokeWidth: 2,
190
+ strokeLinecap: "round",
191
+ strokeLinejoin: "round",
192
+ children: /* @__PURE__ */ jsx("polyline", { points: "20 6 9 17 4 12" })
193
+ }
194
+ ) })
195
+ ]
196
+ },
197
+ lang
198
+ )) })
199
+ ] })
200
+ ] });
201
+ };
264
202
 
265
- // src/rte-footer.tsx
266
- import { useEffect, useMemo, useRef, useState } from "react";
267
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
268
- function Footer({
203
+ // src/bubble-menu/text-buttons.tsx
204
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
205
+ var Svg = ({
269
206
  children,
270
- className,
271
- sticky = false,
272
- stickyOffset = 0,
273
- showWordCount = false,
274
- wordCountClassName,
275
- wordCountFormatter
276
- }) {
277
- const { editor, variant } = useRichTextEditorContext();
278
- const [, forceUpdate] = useState(0);
279
- const rafRef = useRef(null);
280
- useEffect(() => {
281
- if (!editor || !showWordCount) return;
282
- const scheduleUpdate = () => {
283
- if (rafRef.current != null) return;
284
- rafRef.current = requestAnimationFrame(() => {
285
- rafRef.current = null;
286
- forceUpdate((t) => t + 1);
287
- });
288
- };
289
- const handleTransaction = ({
290
- transaction
291
- }) => {
292
- if (transaction.docChanged) scheduleUpdate();
293
- };
294
- editor.on("transaction", handleTransaction);
295
- scheduleUpdate();
296
- return () => {
297
- editor.off("transaction", handleTransaction);
298
- if (rafRef.current != null) cancelAnimationFrame(rafRef.current);
299
- };
300
- }, [editor, showWordCount]);
301
- const wordCount = useMemo(() => {
302
- if (!editor || !showWordCount) return null;
303
- const words = editor.storage.characterCount?.words() ?? 0;
304
- const characters = editor.storage.characterCount?.characters() ?? 0;
305
- return wordCountFormatter ? wordCountFormatter({ words, characters }) : `${words} words | ${characters} characters`;
306
- }, [
207
+ strokeWidth = 2
208
+ }) => /* @__PURE__ */ jsx2(
209
+ "svg",
210
+ {
211
+ xmlns: "http://www.w3.org/2000/svg",
212
+ viewBox: "0 0 24 24",
213
+ fill: "none",
214
+ stroke: "currentColor",
215
+ strokeWidth,
216
+ strokeLinecap: "round",
217
+ strokeLinejoin: "round",
218
+ className: "rte-editor-icon",
219
+ children
220
+ }
221
+ );
222
+ var textItems = [
223
+ {
224
+ command: (e) => e.chain().focus().toggleBold().run(),
225
+ icon: /* @__PURE__ */ jsxs2(Svg, { children: [
226
+ /* @__PURE__ */ jsx2("path", { d: "M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" }),
227
+ /* @__PURE__ */ jsx2("path", { d: "M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" })
228
+ ] }),
229
+ isActive: (s) => s.isBold
230
+ },
231
+ {
232
+ command: (e) => e.chain().focus().toggleItalic().run(),
233
+ icon: /* @__PURE__ */ jsxs2(Svg, { children: [
234
+ /* @__PURE__ */ jsx2("line", { x1: "19", y1: "4", x2: "10", y2: "4" }),
235
+ /* @__PURE__ */ jsx2("line", { x1: "14", y1: "20", x2: "5", y2: "20" }),
236
+ /* @__PURE__ */ jsx2("line", { x1: "15", y1: "4", x2: "9", y2: "20" })
237
+ ] }),
238
+ isActive: (s) => s.isItalic
239
+ },
240
+ {
241
+ command: (e) => e.chain().focus().toggleUnderline().run(),
242
+ icon: /* @__PURE__ */ jsxs2(Svg, { children: [
243
+ /* @__PURE__ */ jsx2("path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }),
244
+ /* @__PURE__ */ jsx2("line", { x1: "4", y1: "20", x2: "20", y2: "20" })
245
+ ] }),
246
+ isActive: (s) => s.isUnderline
247
+ },
248
+ {
249
+ command: (e) => e.chain().focus().toggleStrike().run(),
250
+ icon: /* @__PURE__ */ jsxs2(Svg, { children: [
251
+ /* @__PURE__ */ jsx2("path", { d: "M16 4H9.5a3.5 3.5 0 0 0-2.9 5.4" }),
252
+ /* @__PURE__ */ jsx2("path", { d: "M14.5 14.6a3.5 3.5 0 0 1-2.9 5.4H8" }),
253
+ /* @__PURE__ */ jsx2("line", { x1: "4", y1: "12", x2: "20", y2: "12" })
254
+ ] }),
255
+ isActive: (s) => s.isStrike
256
+ },
257
+ {
258
+ command: (e) => e.chain().focus().toggleCode().run(),
259
+ icon: /* @__PURE__ */ jsxs2(Svg, { children: [
260
+ /* @__PURE__ */ jsx2("polyline", { points: "16 18 22 12 16 6" }),
261
+ /* @__PURE__ */ jsx2("polyline", { points: "8 6 2 12 8 18" })
262
+ ] }),
263
+ isActive: (s) => s.isCode
264
+ }
265
+ ];
266
+ var TextButtons = ({ editor }) => {
267
+ const editorState = useEditorState(
307
268
  editor,
308
- showWordCount,
309
- wordCountFormatter,
310
- editor?.state.doc.content.size
311
- ]);
312
- if (!showWordCount && !children) return null;
313
- return /* @__PURE__ */ jsxs2(
314
- "div",
315
- {
316
- className: cn(
317
- "rte-footer",
318
- variant !== "default" && `rte-footer--${variant}`,
319
- sticky && "sticky z-10",
320
- className
321
- ),
322
- "data-sticky": sticky ? "" : void 0,
323
- style: sticky ? { bottom: stickyOffset } : void 0,
324
- children: [
325
- showWordCount && wordCount && /* @__PURE__ */ jsx3("span", { className: cn("rte-footer-word-count", wordCountClassName), children: wordCount }),
326
- children
327
- ]
328
- }
269
+ (ed) => ({
270
+ isBold: ed.isActive("bold"),
271
+ isCode: ed.isActive("code"),
272
+ isItalic: ed.isActive("italic"),
273
+ isStrike: ed.isActive("strike"),
274
+ isUnderline: ed.isActive("underline")
275
+ }),
276
+ shallowEqual
329
277
  );
330
- }
278
+ return /* @__PURE__ */ jsx2("div", { className: "rte-bubble-group", children: textItems.map((item, i) => /* @__PURE__ */ jsx2(
279
+ "button",
280
+ {
281
+ type: "button",
282
+ className: `rte-bubble-btn${item.isActive(editorState) ? " rte-bubble-btn--active" : ""}`,
283
+ onMouseDown: (e) => e.preventDefault(),
284
+ onClick: () => item.command(editor),
285
+ children: item.icon
286
+ },
287
+ i
288
+ )) });
289
+ };
331
290
 
332
- // src/rte-controls-group.tsx
333
- import { jsx as jsx4 } from "react/jsx-runtime";
334
- function ControlsGroup({
335
- children,
336
- className
337
- }) {
338
- return /* @__PURE__ */ jsx4(
339
- "div",
291
+ // src/bubble-menu/index.tsx
292
+ import { jsx as jsx3 } from "react/jsx-runtime";
293
+ var BubbleMenu = ({ editor }) => {
294
+ const editorState = useEditorState(
295
+ editor,
296
+ (ed) => ({
297
+ isCodeBlock: ed.isActive("codeBlock")
298
+ }),
299
+ shallowEqual
300
+ );
301
+ const shouldShow = useCallback2(
302
+ ({
303
+ editor: ed,
304
+ state
305
+ }) => {
306
+ const { selection } = state;
307
+ if (!ed.isEditable) {
308
+ return false;
309
+ }
310
+ if (selection.empty && !ed.isActive("codeBlock")) {
311
+ return false;
312
+ }
313
+ if (!selection.empty && !isTextSelection(selection)) {
314
+ return false;
315
+ }
316
+ return true;
317
+ },
318
+ []
319
+ );
320
+ if (!editor) {
321
+ return null;
322
+ }
323
+ const isCodeBlockActive = editorState?.isCodeBlock ?? false;
324
+ return /* @__PURE__ */ jsx3(
325
+ TiptapBubbleMenu,
340
326
  {
341
- className: cn("rte-controls-group", className),
342
- children
327
+ editor,
328
+ options: { offset: 8, placement: "top" },
329
+ shouldShow,
330
+ children: /* @__PURE__ */ jsx3("div", { className: "rte-bubble-menu", children: isCodeBlockActive ? /* @__PURE__ */ jsx3(LanguageSelector, { editor }) : /* @__PURE__ */ jsx3(TextButtons, { editor }) })
343
331
  }
344
332
  );
345
- }
346
-
347
- // src/rte-content.tsx
348
- import { EditorContent } from "@tiptap/react";
349
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
350
- function Content({ children, className }) {
351
- const { editor } = useRichTextEditorContext();
352
- return /* @__PURE__ */ jsxs3("div", { className: "relative", children: [
353
- /* @__PURE__ */ jsx5(
354
- EditorContent,
355
- {
356
- editor,
357
- className: cn("rte-content w-full", className)
358
- }
359
- ),
360
- children
361
- ] });
362
- }
333
+ };
363
334
 
364
335
  // src/controls/rte-control.tsx
365
- import { useEditorState } from "@tiptap/react";
336
+ import { useEditorState as useEditorState2 } from "@tiptap/react";
366
337
  import "react";
367
338
 
368
339
  // src/ui/toggle.tsx
369
340
  import { Toggle as TogglePrimitive } from "@base-ui/react/toggle";
370
341
  import { cva } from "class-variance-authority";
371
- import { jsx as jsx6 } from "react/jsx-runtime";
342
+
343
+ // src/ui/utils.ts
344
+ import { clsx } from "clsx";
345
+ import { twMerge } from "tailwind-merge";
346
+ var cn = (...inputs) => twMerge(clsx(inputs));
347
+
348
+ // src/ui/toggle.tsx
349
+ import { jsx as jsx4 } from "react/jsx-runtime";
372
350
  var toggleVariants = cva(
373
351
  "group/toggle inline-flex items-center justify-center gap-1 rounded-none text-xs font-medium whitespace-nowrap transition-all outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-pressed:bg-muted data-[state=on]:bg-muted dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
374
352
  {
353
+ defaultVariants: {
354
+ size: "default",
355
+ variant: "default"
356
+ },
375
357
  variants: {
358
+ size: {
359
+ default: "h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
360
+ lg: "h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
361
+ sm: "h-7 min-w-7 rounded-none px-2.5 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5"
362
+ },
376
363
  variant: {
377
364
  default: "bg-transparent",
378
365
  outline: "border border-input bg-transparent hover:bg-muted"
379
- },
380
- size: {
381
- default: "h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
382
- sm: "h-7 min-w-7 rounded-none px-2.5 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
383
- lg: "h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2"
384
366
  }
385
- },
386
- defaultVariants: {
387
- variant: "default",
388
- size: "default"
389
367
  }
390
368
  }
391
369
  );
392
- function Toggle({
370
+ var Toggle = ({
393
371
  className,
394
372
  variant = "default",
395
373
  size = "default",
396
374
  ...props
397
- }) {
398
- return /* @__PURE__ */ jsx6(
399
- TogglePrimitive,
400
- {
401
- "data-slot": "toggle",
402
- className: cn(toggleVariants({ variant, size, className })),
403
- ...props
404
- }
405
- );
406
- }
375
+ }) => /* @__PURE__ */ jsx4(
376
+ TogglePrimitive,
377
+ {
378
+ "data-slot": "toggle",
379
+ className: cn(toggleVariants({ className, size, variant })),
380
+ ...props
381
+ }
382
+ );
407
383
 
408
384
  // src/controls/rte-control.tsx
409
- import { jsx as jsx7 } from "react/jsx-runtime";
410
- function RichTextEditorControl({
385
+ import { jsx as jsx5 } from "react/jsx-runtime";
386
+ var RichTextEditorControl = ({
411
387
  active,
412
- interactive = true,
388
+ interactive: _interactive = true,
413
389
  className,
414
390
  children,
415
391
  onMouseDown,
416
392
  onClick,
417
393
  disabled,
418
394
  ...props
419
- }) {
420
- return /* @__PURE__ */ jsx7(
421
- Toggle,
422
- {
423
- size: "sm",
424
- pressed: active,
425
- disabled,
426
- "aria-label": props["aria-label"],
427
- title: props.title,
428
- className: cn("rte-control-button", className),
429
- onMouseDown: (e) => {
430
- e.preventDefault();
431
- onMouseDown?.(e);
432
- },
433
- onPressedChange: () => onClick?.({}),
434
- children
435
- }
436
- );
437
- }
438
- function createControl({
439
- label,
440
- iconKey,
441
- isActive,
442
- isDisabled,
443
- operation
444
- }) {
445
- function Control({ className }) {
446
- const { editor, labels, icons } = useRichTextEditorContext();
447
- const ariaLabel = labels[label];
448
- const editorState = useEditorState({
449
- editor: editor ?? null,
450
- selector: (ctx) => {
451
- const safeEditor = ctx.editor && !ctx.editor.isDestroyed ? ctx.editor : null;
452
- const checkIsActive = () => {
453
- if (!safeEditor || !isActive) return false;
454
- if ("attrs" in isActive) return safeEditor.isActive(isActive.attrs);
455
- return safeEditor.isActive(isActive.name, isActive.attributes);
456
- };
457
- return {
458
- active: checkIsActive(),
459
- disabled: safeEditor ? isDisabled?.(safeEditor) ?? false : true
460
- };
461
- }
462
- });
463
- const active = editorState?.active ?? false;
464
- const disabled = editorState?.disabled ?? true;
465
- return /* @__PURE__ */ jsx7(
466
- RichTextEditorControl,
467
- {
468
- active,
469
- disabled,
470
- "aria-label": ariaLabel,
471
- title: ariaLabel,
472
- className,
473
- onClick: () => {
474
- if (!editor || editor.isDestroyed) {
475
- return;
476
- }
477
- editor.chain().focus()[operation.name](operation.attributes).run();
478
- },
479
- children: icons[iconKey]
480
- }
481
- );
482
- }
483
- Control.displayName = `RichTextEditor.${String(label)}`;
484
- return Control;
485
- }
486
-
487
- // src/controls/rte-link-control.tsx
488
- import * as React5 from "react";
489
- import { useState as useState2 } from "react";
490
- import { useEditorState as useEditorState2 } from "@tiptap/react";
491
-
492
- // src/ui/popover.tsx
493
- import "react";
494
- import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
495
- import { jsx as jsx8 } from "react/jsx-runtime";
496
- function Popover({ ...props }) {
497
- return /* @__PURE__ */ jsx8(PopoverPrimitive.Root, { "data-slot": "popover", ...props });
498
- }
499
- function PopoverTrigger({ ...props }) {
500
- return /* @__PURE__ */ jsx8(PopoverPrimitive.Trigger, { "data-slot": "popover-trigger", ...props });
501
- }
502
- function PopoverContent({
503
- className,
504
- align = "center",
505
- alignOffset = 0,
506
- side = "bottom",
507
- sideOffset = 4,
508
- ...props
509
- }) {
510
- return /* @__PURE__ */ jsx8(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx8(
511
- PopoverPrimitive.Positioner,
512
- {
513
- align,
514
- alignOffset,
515
- side,
516
- sideOffset,
517
- className: "isolate z-50",
518
- children: /* @__PURE__ */ jsx8(
519
- PopoverPrimitive.Popup,
520
- {
521
- "data-slot": "popover-content",
522
- className: cn(
523
- "z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 rounded-none bg-popover p-2.5 text-xs text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
524
- className
525
- ),
526
- ...props
527
- }
528
- )
529
- }
530
- ) });
531
- }
532
-
533
- // src/ui/input.tsx
534
- import "react";
535
- import { Input as InputPrimitive } from "@base-ui/react/input";
536
- import { jsx as jsx9 } from "react/jsx-runtime";
537
- function Input({ className, type, ...props }) {
538
- return /* @__PURE__ */ jsx9(
539
- InputPrimitive,
540
- {
541
- type,
542
- "data-slot": "input",
543
- className: cn(
544
- "h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
545
- className
546
- ),
547
- ...props
548
- }
549
- );
550
- }
551
-
552
- // src/ui/button.tsx
553
- import { Button as ButtonPrimitive } from "@base-ui/react/button";
554
- import { cva as cva2 } from "class-variance-authority";
555
- import { jsx as jsx10 } from "react/jsx-runtime";
556
- var buttonVariants = cva2(
557
- "group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
395
+ }) => /* @__PURE__ */ jsx5(
396
+ Toggle,
558
397
  {
559
- variants: {
560
- variant: {
561
- default: "bg-primary text-primary-foreground hover:bg-primary/80",
562
- outline: "border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
563
- secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
564
- ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
565
- destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
566
- link: "text-primary underline-offset-4 hover:underline"
567
- },
568
- size: {
569
- default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
570
- xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
571
- sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
572
- lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
573
- icon: "size-8",
574
- "icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
575
- "icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
576
- "icon-lg": "size-9"
577
- }
578
- },
579
- defaultVariants: {
580
- variant: "default",
581
- size: "default"
582
- }
583
- }
584
- );
585
- function Button({
586
- className,
587
- variant = "default",
588
- size = "default",
589
- ...props
590
- }) {
591
- return /* @__PURE__ */ jsx10(
592
- ButtonPrimitive,
593
- {
594
- "data-slot": "button",
595
- className: cn(buttonVariants({ variant, size, className })),
596
- ...props
597
- }
598
- );
599
- }
600
-
601
- // src/controls/rte-link-control.tsx
602
- import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
603
- function LinkControl() {
604
- const { editor, labels, icons } = useRichTextEditorContext();
605
- const [url, setUrl] = useState2("");
606
- const [open, setOpen] = useState2(false);
607
- const active = useEditorState2({
608
- editor: editor ?? null,
609
- selector: (ctx) => ctx.editor && !ctx.editor.isDestroyed ? ctx.editor.isActive("link") : false
610
- });
611
- const handleOpen = (isOpen) => {
612
- if (isOpen) {
613
- const linkData = editor?.getAttributes("link");
614
- setUrl(linkData?.href || "");
615
- } else {
616
- setUrl("");
617
- }
618
- setOpen(isOpen);
619
- };
620
- const handleSave = () => {
621
- if (!editor || editor.isDestroyed) return;
622
- if (url === "") {
623
- editor.chain().focus().extendMarkRange("link").unsetLink().run();
624
- } else {
625
- editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
626
- }
627
- setOpen(false);
628
- setUrl("");
629
- };
630
- const handleKeyDown = (e) => {
631
- if (e.key === "Enter") {
398
+ size: "sm",
399
+ pressed: active,
400
+ disabled,
401
+ "aria-label": props["aria-label"],
402
+ title: props.title,
403
+ className: cn("rte-control-button", className),
404
+ onMouseDown: (e) => {
632
405
  e.preventDefault();
633
- handleSave();
634
- }
406
+ onMouseDown?.(e);
407
+ },
408
+ onPressedChange: () => onClick?.({}),
409
+ children
410
+ }
411
+ );
412
+ var resolveIsActive = (editor, config) => {
413
+ if (!editor || !config) {
414
+ return false;
415
+ }
416
+ if ("attrs" in config) {
417
+ return editor.isActive(config.attrs);
418
+ }
419
+ return editor.isActive(config.name, config.attributes);
420
+ };
421
+ var createSelector = (isActive, isDisabled) => (ctx) => {
422
+ const safeEditor = ctx.editor && !ctx.editor.isDestroyed ? ctx.editor : null;
423
+ return {
424
+ active: resolveIsActive(safeEditor, isActive),
425
+ disabled: safeEditor ? isDisabled?.(safeEditor) ?? false : true
635
426
  };
636
- React5.useEffect(() => {
637
- const handler = () => handleOpen(true);
638
- window.addEventListener("edit-link", handler);
639
- return () => window.removeEventListener("edit-link", handler);
640
- }, [editor]);
641
- return /* @__PURE__ */ jsxs4(Popover, { open, onOpenChange: handleOpen, children: [
642
- /* @__PURE__ */ jsx11(
643
- PopoverTrigger,
427
+ };
428
+ var createControl = ({
429
+ label,
430
+ iconKey,
431
+ isActive,
432
+ isDisabled,
433
+ operation
434
+ }) => {
435
+ const Control = ({ className }) => {
436
+ const { editor, labels, icons } = useRichTextEditorContext();
437
+ const ariaLabel = labels[label];
438
+ const editorState = useEditorState2({
439
+ editor: editor ?? null,
440
+ selector: createSelector(isActive, isDisabled)
441
+ });
442
+ const active = editorState?.active ?? false;
443
+ const disabled = editorState?.disabled ?? true;
444
+ return /* @__PURE__ */ jsx5(
445
+ RichTextEditorControl,
644
446
  {
645
- onMouseDown: (e) => e.preventDefault(),
646
- children: /* @__PURE__ */ jsx11(
647
- Toggle,
648
- {
649
- size: "sm",
650
- pressed: active ?? false,
651
- "aria-label": labels.linkControlLabel,
652
- title: labels.linkControlLabel,
653
- className: "p-0",
654
- children: icons.linkControlIcon
447
+ active,
448
+ disabled,
449
+ "aria-label": ariaLabel,
450
+ title: ariaLabel,
451
+ className,
452
+ onClick: () => {
453
+ if (!editor || editor.isDestroyed) {
454
+ return;
655
455
  }
656
- )
456
+ const commands = editor.chain().focus();
457
+ commands[operation.name]?.(operation.attributes).run();
458
+ },
459
+ children: icons[iconKey]
657
460
  }
658
- ),
659
- /* @__PURE__ */ jsx11(PopoverContent, { className: "w-72 p-3", children: /* @__PURE__ */ jsxs4("div", { className: "rte-link-editor", children: [
660
- /* @__PURE__ */ jsx11(
661
- Input,
662
- {
663
- type: "url",
664
- placeholder: labels.linkEditorInputPlaceholder,
665
- "aria-label": labels.linkEditorInputLabel,
666
- value: url,
667
- onChange: (e) => setUrl(e.target.value),
668
- onKeyDown: handleKeyDown,
669
- className: "rte-link-editor-input h-8 text-sm"
670
- }
671
- ),
672
- /* @__PURE__ */ jsx11(
673
- Button,
674
- {
675
- size: "sm",
676
- variant: "default",
677
- onClick: handleSave,
678
- className: "rte-link-editor-save h-8",
679
- children: labels.linkEditorSave
680
- }
681
- )
682
- ] }) })
683
- ] });
684
- }
461
+ );
462
+ };
463
+ Control.displayName = `RichTextEditor.${String(label)}`;
464
+ return Control;
465
+ };
685
466
 
686
467
  // src/controls/rte-controls.tsx
687
468
  var BoldControl = createControl({
688
- label: "boldControlLabel",
689
469
  iconKey: "boldControlIcon",
690
470
  isActive: { name: "bold" },
471
+ label: "boldControlLabel",
691
472
  operation: { name: "toggleBold" }
692
473
  });
693
474
  var ItalicControl = createControl({
694
- label: "italicControlLabel",
695
475
  iconKey: "italicControlIcon",
696
476
  isActive: { name: "italic" },
477
+ label: "italicControlLabel",
697
478
  operation: { name: "toggleItalic" }
698
479
  });
699
480
  var UnderlineControl = createControl({
700
- label: "underlineControlLabel",
701
481
  iconKey: "underlineControlIcon",
702
482
  isActive: { name: "underline" },
483
+ label: "underlineControlLabel",
703
484
  operation: { name: "toggleUnderline" }
704
485
  });
705
486
  var StrikethroughControl = createControl({
706
- label: "strikeControlLabel",
707
487
  iconKey: "strikeControlIcon",
708
488
  isActive: { name: "strike" },
489
+ label: "strikeControlLabel",
709
490
  operation: { name: "toggleStrike" }
710
491
  });
711
492
  var ClearFormattingControl = createControl({
712
- label: "clearFormattingControlLabel",
713
493
  iconKey: "clearFormattingControlIcon",
494
+ label: "clearFormattingControlLabel",
714
495
  operation: { name: "unsetAllMarks" }
715
496
  });
716
497
  var CodeControl = createControl({
717
- label: "codeControlLabel",
718
498
  iconKey: "codeControlIcon",
719
499
  isActive: { name: "code" },
500
+ label: "codeControlLabel",
720
501
  operation: { name: "toggleCode" }
721
502
  });
722
503
  var CodeBlockControl = createControl({
723
- label: "codeBlockControlLabel",
724
504
  iconKey: "codeBlockControlIcon",
725
505
  isActive: { name: "codeBlock" },
506
+ label: "codeBlockControlLabel",
726
507
  operation: { name: "toggleCodeBlock" }
727
508
  });
728
509
  var H1Control = createControl({
729
- label: "h1ControlLabel",
730
510
  iconKey: "h1ControlIcon",
731
- isActive: { name: "heading", attributes: { level: 1 } },
732
- operation: { name: "toggleHeading", attributes: { level: 1 } }
511
+ isActive: { attributes: { level: 1 }, name: "heading" },
512
+ label: "h1ControlLabel",
513
+ operation: { attributes: { level: 1 }, name: "toggleHeading" }
733
514
  });
734
515
  var H2Control = createControl({
735
- label: "h2ControlLabel",
736
516
  iconKey: "h2ControlIcon",
737
- isActive: { name: "heading", attributes: { level: 2 } },
738
- operation: { name: "toggleHeading", attributes: { level: 2 } }
517
+ isActive: { attributes: { level: 2 }, name: "heading" },
518
+ label: "h2ControlLabel",
519
+ operation: { attributes: { level: 2 }, name: "toggleHeading" }
739
520
  });
740
521
  var H3Control = createControl({
741
- label: "h3ControlLabel",
742
522
  iconKey: "h3ControlIcon",
743
- isActive: { name: "heading", attributes: { level: 3 } },
744
- operation: { name: "toggleHeading", attributes: { level: 3 } }
523
+ isActive: { attributes: { level: 3 }, name: "heading" },
524
+ label: "h3ControlLabel",
525
+ operation: { attributes: { level: 3 }, name: "toggleHeading" }
745
526
  });
746
527
  var H4Control = createControl({
747
- label: "h4ControlLabel",
748
528
  iconKey: "h4ControlIcon",
749
- isActive: { name: "heading", attributes: { level: 4 } },
750
- operation: { name: "toggleHeading", attributes: { level: 4 } }
529
+ isActive: { attributes: { level: 4 }, name: "heading" },
530
+ label: "h4ControlLabel",
531
+ operation: { attributes: { level: 4 }, name: "toggleHeading" }
751
532
  });
752
533
  var BulletListControl = createControl({
753
- label: "bulletListControlLabel",
754
534
  iconKey: "bulletListControlIcon",
755
535
  isActive: { name: "bulletList" },
536
+ label: "bulletListControlLabel",
756
537
  operation: { name: "toggleBulletList" }
757
538
  });
758
539
  var OrderedListControl = createControl({
759
- label: "orderedListControlLabel",
760
540
  iconKey: "orderedListControlIcon",
761
541
  isActive: { name: "orderedList" },
542
+ label: "orderedListControlLabel",
762
543
  operation: { name: "toggleOrderedList" }
763
544
  });
764
545
  var BlockquoteControl = createControl({
765
- label: "blockquoteControlLabel",
766
546
  iconKey: "blockquoteControlIcon",
767
547
  isActive: { name: "blockquote" },
548
+ label: "blockquoteControlLabel",
768
549
  operation: { name: "toggleBlockquote" }
769
550
  });
770
551
  var HrControl = createControl({
771
- label: "hrControlLabel",
772
552
  iconKey: "hrControlIcon",
553
+ label: "hrControlLabel",
773
554
  operation: { name: "setHorizontalRule" }
774
555
  });
775
556
  var UnlinkControl = createControl({
776
- label: "unlinkControlLabel",
777
557
  iconKey: "unlinkControlIcon",
558
+ label: "unlinkControlLabel",
778
559
  operation: { name: "unsetLink" }
779
560
  });
780
561
  var UndoControl = createControl({
781
- label: "undoControlLabel",
782
562
  iconKey: "undoControlIcon",
783
563
  isDisabled: (editor) => !editor.can().undo(),
564
+ label: "undoControlLabel",
784
565
  operation: { name: "undo" }
785
566
  });
786
567
  var RedoControl = createControl({
787
- label: "redoControlLabel",
788
568
  iconKey: "redoControlIcon",
789
569
  isDisabled: (editor) => !editor.can().redo(),
570
+ label: "redoControlLabel",
790
571
  operation: { name: "redo" }
791
572
  });
792
573
  var H5Control = createControl({
793
- label: "h5ControlLabel",
794
574
  iconKey: "h5ControlIcon",
795
- isActive: { name: "heading", attributes: { level: 5 } },
796
- operation: { name: "toggleHeading", attributes: { level: 5 } }
575
+ isActive: { attributes: { level: 5 }, name: "heading" },
576
+ label: "h5ControlLabel",
577
+ operation: { attributes: { level: 5 }, name: "toggleHeading" }
797
578
  });
798
579
  var H6Control = createControl({
799
- label: "h6ControlLabel",
800
580
  iconKey: "h6ControlIcon",
801
- isActive: { name: "heading", attributes: { level: 6 } },
802
- operation: { name: "toggleHeading", attributes: { level: 6 } }
581
+ isActive: { attributes: { level: 6 }, name: "heading" },
582
+ label: "h6ControlLabel",
583
+ operation: { attributes: { level: 6 }, name: "toggleHeading" }
803
584
  });
804
585
  var AlignLeftControl = createControl({
805
- label: "alignLeftControlLabel",
806
586
  iconKey: "alignLeftControlIcon",
807
- operation: { name: "setTextAlign", attributes: "left" }
587
+ label: "alignLeftControlLabel",
588
+ operation: { attributes: "left", name: "setTextAlign" }
808
589
  });
809
590
  var AlignCenterControl = createControl({
810
- label: "alignCenterControlLabel",
811
591
  iconKey: "alignCenterControlIcon",
812
592
  isActive: { attrs: { textAlign: "center" } },
813
- operation: { name: "setTextAlign", attributes: "center" }
593
+ label: "alignCenterControlLabel",
594
+ operation: { attributes: "center", name: "setTextAlign" }
814
595
  });
815
596
  var AlignRightControl = createControl({
816
- label: "alignRightControlLabel",
817
597
  iconKey: "alignRightControlIcon",
818
598
  isActive: { attrs: { textAlign: "right" } },
819
- operation: { name: "setTextAlign", attributes: "right" }
599
+ label: "alignRightControlLabel",
600
+ operation: { attributes: "right", name: "setTextAlign" }
820
601
  });
821
602
  var AlignJustifyControl = createControl({
822
- label: "alignJustifyControlLabel",
823
603
  iconKey: "alignJustifyControlIcon",
824
604
  isActive: { attrs: { textAlign: "justify" } },
825
- operation: { name: "setTextAlign", attributes: "justify" }
605
+ label: "alignJustifyControlLabel",
606
+ operation: { attributes: "justify", name: "setTextAlign" }
826
607
  });
827
608
  var HighlightControl = createControl({
828
- label: "highlightControlLabel",
829
609
  iconKey: "highlightControlIcon",
830
610
  isActive: { name: "highlight" },
611
+ label: "highlightControlLabel",
831
612
  operation: { name: "toggleHighlight" }
832
613
  });
833
614
  var SubscriptControl = createControl({
834
- label: "subscriptControlLabel",
835
615
  iconKey: "subscriptControlIcon",
836
616
  isActive: { name: "subscript" },
617
+ label: "subscriptControlLabel",
837
618
  operation: { name: "toggleSubscript" }
838
619
  });
839
620
  var SuperscriptControl = createControl({
840
- label: "superscriptControlLabel",
841
621
  iconKey: "superscriptControlIcon",
842
622
  isActive: { name: "superscript" },
623
+ label: "superscriptControlLabel",
843
624
  operation: { name: "toggleSuperscript" }
844
625
  });
845
626
 
846
- // src/controls/rte-youtube-control.tsx
847
- import { useState as useState3, useCallback as useCallback2 } from "react";
848
- import { Node, nodeInputRule } from "@tiptap/core";
849
- import {
850
- ReactNodeViewRenderer,
851
- useEditorState as useEditorState3
852
- } from "@tiptap/react";
627
+ // src/controls/rte-link-control.tsx
628
+ import { useEditorState as useEditorState3 } from "@tiptap/react";
629
+ import * as React4 from "react";
630
+ import { useCallback as useCallback3, useState as useState2 } from "react";
853
631
 
854
- // src/ui/dialog.tsx
632
+ // src/ui/button.tsx
633
+ import { Button as ButtonPrimitive } from "@base-ui/react/button";
634
+ import { cva as cva2 } from "class-variance-authority";
635
+ import { jsx as jsx6 } from "react/jsx-runtime";
636
+ var buttonVariants = cva2(
637
+ "group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
638
+ {
639
+ defaultVariants: {
640
+ size: "default",
641
+ variant: "default"
642
+ },
643
+ variants: {
644
+ size: {
645
+ default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
646
+ icon: "size-8",
647
+ "icon-lg": "size-9",
648
+ "icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
649
+ "icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
650
+ lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
651
+ sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
652
+ xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3"
653
+ },
654
+ variant: {
655
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
656
+ destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
657
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
658
+ link: "text-primary underline-offset-4 hover:underline",
659
+ outline: "border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
660
+ secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground"
661
+ }
662
+ }
663
+ }
664
+ );
665
+ var Button = ({
666
+ className,
667
+ variant = "default",
668
+ size = "default",
669
+ ...props
670
+ }) => /* @__PURE__ */ jsx6(
671
+ ButtonPrimitive,
672
+ {
673
+ "data-slot": "button",
674
+ className: cn(buttonVariants({ className, size, variant })),
675
+ ...props
676
+ }
677
+ );
678
+
679
+ // src/ui/input.tsx
680
+ import { Input as InputPrimitive } from "@base-ui/react/input";
855
681
  import "react";
856
- import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
857
- import { jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
858
- function Dialog({ ...props }) {
859
- return /* @__PURE__ */ jsx12(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
860
- }
861
- function DialogTrigger({ ...props }) {
862
- return /* @__PURE__ */ jsx12(DialogPrimitive.Trigger, { "data-slot": "dialog-trigger", ...props });
863
- }
864
- function DialogPortal({ ...props }) {
865
- return /* @__PURE__ */ jsx12(DialogPrimitive.Portal, { "data-slot": "dialog-portal", ...props });
866
- }
867
- function DialogClose({ ...props }) {
868
- return /* @__PURE__ */ jsx12(DialogPrimitive.Close, { "data-slot": "dialog-close", ...props });
869
- }
870
- function DialogOverlay({
682
+ import { jsx as jsx7 } from "react/jsx-runtime";
683
+ var Input = ({
871
684
  className,
685
+ type,
872
686
  ...props
873
- }) {
874
- return /* @__PURE__ */ jsx12(
875
- DialogPrimitive.Backdrop,
876
- {
877
- "data-slot": "dialog-overlay",
878
- className: cn(
879
- "fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
880
- className
881
- ),
882
- ...props
883
- }
884
- );
885
- }
886
- function DialogContent({
687
+ }) => /* @__PURE__ */ jsx7(
688
+ InputPrimitive,
689
+ {
690
+ type,
691
+ "data-slot": "input",
692
+ className: cn(
693
+ "h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
694
+ className
695
+ ),
696
+ ...props
697
+ }
698
+ );
699
+
700
+ // src/ui/popover.tsx
701
+ import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
702
+ import "react";
703
+ import { jsx as jsx8 } from "react/jsx-runtime";
704
+ var Popover = ({ ...props }) => /* @__PURE__ */ jsx8(PopoverPrimitive.Root, { "data-slot": "popover", ...props });
705
+ var PopoverTrigger = ({ ...props }) => /* @__PURE__ */ jsx8(PopoverPrimitive.Trigger, { "data-slot": "popover-trigger", ...props });
706
+ var PopoverContent = ({
887
707
  className,
888
- children,
889
- showCloseButton = true,
708
+ align = "center",
709
+ alignOffset = 0,
710
+ side = "bottom",
711
+ sideOffset = 4,
890
712
  ...props
891
- }) {
892
- return /* @__PURE__ */ jsxs5(DialogPortal, { children: [
893
- /* @__PURE__ */ jsx12(DialogOverlay, {}),
894
- /* @__PURE__ */ jsxs5(
895
- DialogPrimitive.Popup,
713
+ }) => /* @__PURE__ */ jsx8(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx8(
714
+ PopoverPrimitive.Positioner,
715
+ {
716
+ align,
717
+ alignOffset,
718
+ side,
719
+ sideOffset,
720
+ className: "isolate z-50",
721
+ children: /* @__PURE__ */ jsx8(
722
+ PopoverPrimitive.Popup,
896
723
  {
897
- "data-slot": "dialog-content",
724
+ "data-slot": "popover-content",
898
725
  className: cn(
899
- "fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-none bg-popover p-4 text-xs/relaxed text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
726
+ "z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 rounded-none bg-popover p-2.5 text-xs text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
900
727
  className
901
728
  ),
902
- ...props,
903
- children: [
904
- children,
905
- showCloseButton && /* @__PURE__ */ jsxs5(
906
- DialogPrimitive.Close,
907
- {
908
- "data-slot": "dialog-close",
909
- render: /* @__PURE__ */ jsx12(
910
- Button,
911
- {
912
- variant: "ghost",
913
- className: "absolute top-2 right-2",
914
- size: "icon-sm"
915
- }
916
- ),
917
- children: [
918
- "X",
919
- /* @__PURE__ */ jsx12("span", { className: "sr-only", children: "Close" })
920
- ]
921
- }
922
- )
923
- ]
729
+ ...props
924
730
  }
925
731
  )
926
- ] });
927
- }
928
- function DialogHeader({ className, ...props }) {
929
- return /* @__PURE__ */ jsx12(
930
- "div",
931
- {
932
- "data-slot": "dialog-header",
933
- className: cn("flex flex-col gap-1 text-left", className),
934
- ...props
935
- }
732
+ }
733
+ ) });
734
+
735
+ // src/controls/rte-link-control.tsx
736
+ import { jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
737
+ var LinkControl = () => {
738
+ const { editor, labels, icons } = useRichTextEditorContext();
739
+ const [url, setUrl] = useState2("");
740
+ const [open, setOpen] = useState2(false);
741
+ const active = useEditorState3({
742
+ editor: editor ?? null,
743
+ selector: (ctx) => ctx.editor && !ctx.editor.isDestroyed ? ctx.editor.isActive("link") : false
744
+ });
745
+ const handleOpen = useCallback3(
746
+ (isOpen) => {
747
+ if (isOpen) {
748
+ const linkData = editor?.getAttributes("link");
749
+ setUrl(linkData?.href || "");
750
+ } else {
751
+ setUrl("");
752
+ }
753
+ setOpen(isOpen);
754
+ },
755
+ [editor]
936
756
  );
937
- }
938
- function DialogFooter({
939
- className,
940
- showCloseButton = false,
941
- children,
942
- ...props
943
- }) {
944
- return /* @__PURE__ */ jsxs5(
945
- "div",
946
- {
947
- "data-slot": "dialog-footer",
948
- className: cn(
949
- "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
950
- className
951
- ),
952
- ...props,
953
- children: [
954
- children,
955
- showCloseButton && /* @__PURE__ */ jsx12(DialogPrimitive.Close, { render: /* @__PURE__ */ jsx12(Button, { variant: "outline" }), children: "Close" })
956
- ]
757
+ const handleSave = () => {
758
+ if (!editor || editor.isDestroyed) {
759
+ return;
957
760
  }
958
- );
959
- }
960
- function DialogTitle({ className, ...props }) {
961
- return /* @__PURE__ */ jsx12(
962
- DialogPrimitive.Title,
963
- {
964
- "data-slot": "dialog-title",
965
- className: cn("text-sm font-medium", className),
966
- ...props
761
+ if (url === "") {
762
+ editor.chain().focus().extendMarkRange("link").unsetLink().run();
763
+ } else {
764
+ editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
967
765
  }
968
- );
969
- }
970
- function DialogDescription({
971
- className,
972
- ...props
973
- }) {
974
- return /* @__PURE__ */ jsx12(
975
- DialogPrimitive.Description,
976
- {
977
- "data-slot": "dialog-description",
978
- className: cn(
979
- "text-xs/relaxed text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
980
- className
766
+ setOpen(false);
767
+ setUrl("");
768
+ };
769
+ const handleKeyDown = (e) => {
770
+ if (e.key === "Enter") {
771
+ e.preventDefault();
772
+ handleSave();
773
+ }
774
+ };
775
+ React4.useEffect(() => {
776
+ const handler = () => handleOpen(true);
777
+ window.addEventListener("edit-link", handler);
778
+ return () => window.removeEventListener("edit-link", handler);
779
+ }, [handleOpen]);
780
+ return /* @__PURE__ */ jsxs3(Popover, { open, onOpenChange: handleOpen, children: [
781
+ /* @__PURE__ */ jsx9(
782
+ PopoverTrigger,
783
+ {
784
+ render: /* @__PURE__ */ jsx9(
785
+ Toggle,
786
+ {
787
+ size: "sm",
788
+ pressed: active ?? false,
789
+ "aria-label": labels.linkControlLabel,
790
+ title: labels.linkControlLabel,
791
+ className: "p-0"
792
+ }
793
+ ),
794
+ onMouseDown: (e) => e.preventDefault(),
795
+ children: icons.linkControlIcon
796
+ }
797
+ ),
798
+ /* @__PURE__ */ jsx9(PopoverContent, { className: "w-72 p-3", children: /* @__PURE__ */ jsxs3("div", { className: "rte-link-editor", children: [
799
+ /* @__PURE__ */ jsx9(
800
+ Input,
801
+ {
802
+ type: "url",
803
+ placeholder: labels.linkEditorInputPlaceholder,
804
+ "aria-label": labels.linkEditorInputLabel,
805
+ value: url,
806
+ onChange: (e) => setUrl(e.target.value),
807
+ onKeyDown: handleKeyDown,
808
+ className: "rte-link-editor-input h-8 text-sm"
809
+ }
981
810
  ),
982
- ...props
983
- }
984
- );
985
- }
811
+ /* @__PURE__ */ jsx9(
812
+ Button,
813
+ {
814
+ size: "sm",
815
+ variant: "default",
816
+ onClick: handleSave,
817
+ className: "rte-link-editor-save h-8",
818
+ children: labels.linkEditorSave
819
+ }
820
+ )
821
+ ] }) })
822
+ ] });
823
+ };
824
+
825
+ // src/controls/rte-twitter-control.tsx
826
+ import { Node, nodeInputRule } from "@tiptap/core";
827
+ import { ReactNodeViewRenderer, useEditorState as useEditorState4 } from "@tiptap/react";
828
+ import { useState as useState3, useCallback as useCallback5, useEffect as useEffect3, useRef as useRef3 } from "react";
986
829
 
987
830
  // src/extensions/resizable-node-view.tsx
988
- import { useCallback, useRef as useRef2, useEffect as useEffect3 } from "react";
989
831
  import { NodeViewWrapper } from "@tiptap/react";
990
- import { Fragment, jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
991
- function ResizableNodeView({
832
+ import { useCallback as useCallback4, useRef as useRef2, useEffect as useEffect2 } from "react";
833
+ import { Fragment as Fragment2, jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
834
+ var ResizableNodeView = ({
992
835
  node,
993
836
  selected,
994
837
  updateAttributes,
@@ -998,48 +841,32 @@ function ResizableNodeView({
998
841
  aspectRatio = 16 / 9,
999
842
  minWidth = 300,
1000
843
  maxWidth = 1200
1001
- }) {
844
+ }) => {
1002
845
  const containerRef = useRef2(null);
1003
846
  const resizingRef = useRef2(null);
1004
847
  const width = node.attrs.width;
1005
848
  const height = node.attrs.height;
1006
849
  const align = node.attrs.align || "center";
1007
- const getEditorWidth = useCallback(() => {
1008
- return view?.dom?.parentElement?.offsetWidth ?? 0;
1009
- }, [view]);
1010
- const handleMouseDown = useCallback(
1011
- (e, direction) => {
1012
- e.preventDefault();
1013
- e.stopPropagation();
1014
- const editorWidth = getEditorWidth();
1015
- const startWidth = containerRef.current?.offsetWidth ?? width ?? Math.min(560, editorWidth);
1016
- const startHeight = containerRef.current?.offsetHeight ?? height ?? 315;
1017
- resizingRef.current = {
1018
- direction,
1019
- startX: e.clientX,
1020
- startY: e.clientY,
1021
- startWidth,
1022
- startHeight,
1023
- editorWidth
1024
- };
1025
- document.addEventListener("mousemove", handleMouseMove);
1026
- document.addEventListener("mouseup", handleMouseUp);
1027
- document.body.style.cursor = direction === "right" ? "ew-resize" : direction === "bottom" ? "ns-resize" : "nwse-resize";
1028
- document.body.style.userSelect = "none";
1029
- },
1030
- [width, height, getEditorWidth]
850
+ const getEditorWidth = useCallback4(
851
+ () => view?.dom?.parentElement?.offsetWidth ?? 0,
852
+ [view]
1031
853
  );
1032
- const handleMouseMove = useCallback(
854
+ const handleMouseMove = useCallback4(
1033
855
  (e) => {
1034
856
  const resize = resizingRef.current;
1035
- if (!resize) return;
857
+ if (!resize) {
858
+ return;
859
+ }
1036
860
  const effectiveMax = Math.min(maxWidth, resize.editorWidth);
1037
861
  let newWidth = resize.startWidth;
1038
862
  let newHeight = resize.startHeight;
1039
863
  if (resize.direction === "right" || resize.direction === "corner") {
1040
864
  newWidth = Math.max(
1041
865
  minWidth,
1042
- Math.min(effectiveMax, resize.startWidth + (e.clientX - resize.startX))
866
+ Math.min(
867
+ effectiveMax,
868
+ resize.startWidth + (e.clientX - resize.startX)
869
+ )
1043
870
  );
1044
871
  }
1045
872
  if (resize.direction === "bottom" || resize.direction === "corner") {
@@ -1065,80 +892,459 @@ function ResizableNodeView({
1065
892
  },
1066
893
  [lockAspect, aspectRatio, minWidth, maxWidth]
1067
894
  );
1068
- const handleMouseUp = useCallback(() => {
1069
- const resize = resizingRef.current;
1070
- if (!resize) return;
1071
- document.removeEventListener("mousemove", handleMouseMove);
1072
- document.removeEventListener("mouseup", handleMouseUp);
1073
- document.body.style.cursor = "";
1074
- document.body.style.userSelect = "";
1075
- if (containerRef.current) {
1076
- const w = containerRef.current.offsetWidth;
1077
- const h = containerRef.current.offsetHeight;
1078
- updateAttributes({ width: w, height: h });
1079
- }
1080
- resizingRef.current = null;
1081
- }, [handleMouseMove, updateAttributes]);
1082
- useEffect3(() => {
1083
- return () => {
895
+ const handleMouseUp = useCallback4(
896
+ function handleMouseUp2() {
897
+ const resize = resizingRef.current;
898
+ if (!resize) {
899
+ return;
900
+ }
901
+ document.removeEventListener("mousemove", handleMouseMove);
902
+ document.removeEventListener("mouseup", handleMouseUp2);
903
+ document.body.style.cursor = "";
904
+ document.body.style.userSelect = "";
905
+ if (containerRef.current) {
906
+ const w = containerRef.current.offsetWidth;
907
+ const h = containerRef.current.offsetHeight;
908
+ updateAttributes({ height: h, width: w });
909
+ }
910
+ resizingRef.current = null;
911
+ },
912
+ [handleMouseMove, updateAttributes]
913
+ );
914
+ const handleMouseDown = useCallback4(
915
+ (e, direction) => {
916
+ e.preventDefault();
917
+ e.stopPropagation();
918
+ const editorWidth = getEditorWidth();
919
+ const startWidth = containerRef.current?.offsetWidth ?? width ?? Math.min(560, editorWidth);
920
+ const startHeight = containerRef.current?.offsetHeight ?? height ?? 315;
921
+ resizingRef.current = {
922
+ direction,
923
+ editorWidth,
924
+ startHeight,
925
+ startWidth,
926
+ startX: e.clientX,
927
+ startY: e.clientY
928
+ };
929
+ document.addEventListener("mousemove", handleMouseMove);
930
+ document.addEventListener("mouseup", handleMouseUp);
931
+ let cursor = "nwse-resize";
932
+ if (direction === "right") {
933
+ cursor = "ew-resize";
934
+ } else if (direction === "bottom") {
935
+ cursor = "ns-resize";
936
+ }
937
+ document.body.style.cursor = cursor;
938
+ document.body.style.userSelect = "none";
939
+ },
940
+ [width, height, getEditorWidth, handleMouseMove, handleMouseUp]
941
+ );
942
+ useEffect2(
943
+ () => () => {
1084
944
  document.removeEventListener("mousemove", handleMouseMove);
1085
945
  document.removeEventListener("mouseup", handleMouseUp);
1086
946
  document.body.style.cursor = "";
1087
947
  document.body.style.userSelect = "";
1088
- };
1089
- }, [handleMouseMove]);
1090
- return /* @__PURE__ */ jsx13(
948
+ },
949
+ [handleMouseMove, handleMouseUp]
950
+ );
951
+ return /* @__PURE__ */ jsx10(
1091
952
  NodeViewWrapper,
1092
953
  {
1093
954
  className: "rte-embed-wrapper",
1094
955
  "data-selected": selected || void 0,
1095
956
  "data-align": align,
1096
- children: /* @__PURE__ */ jsxs6(
957
+ children: /* @__PURE__ */ jsxs4(
1097
958
  "div",
1098
959
  {
1099
960
  ref: containerRef,
1100
961
  className: "rte-embed",
1101
962
  contentEditable: false,
1102
963
  style: {
1103
- width: width ? `${width}px` : "100%",
1104
964
  height: height ? `${height}px` : "auto",
1105
- minWidth: `${minWidth}px`
965
+ minWidth: `${minWidth}px`,
966
+ width: width ? `${width}px` : "100%"
1106
967
  },
1107
968
  children: [
1108
969
  children,
1109
- selected && /* @__PURE__ */ jsxs6(Fragment, { children: [
1110
- /* @__PURE__ */ jsx13(
970
+ selected && /* @__PURE__ */ jsxs4(Fragment2, { children: [
971
+ /* @__PURE__ */ jsx10(
1111
972
  "div",
1112
973
  {
1113
974
  className: "rte-resize-handle rte-resize-handle--right",
1114
- onMouseDown: (e) => handleMouseDown(e, "right")
975
+ onMouseDown: (e) => handleMouseDown(e, "right"),
976
+ role: "presentation"
1115
977
  }
1116
978
  ),
1117
- /* @__PURE__ */ jsx13(
979
+ /* @__PURE__ */ jsx10(
1118
980
  "div",
1119
981
  {
1120
982
  className: "rte-resize-handle rte-resize-handle--bottom",
1121
- onMouseDown: (e) => handleMouseDown(e, "bottom")
983
+ onMouseDown: (e) => handleMouseDown(e, "bottom"),
984
+ role: "presentation"
1122
985
  }
1123
986
  ),
1124
- /* @__PURE__ */ jsx13(
987
+ /* @__PURE__ */ jsx10(
1125
988
  "div",
1126
989
  {
1127
990
  className: "rte-resize-handle rte-resize-handle--corner",
1128
- onMouseDown: (e) => handleMouseDown(e, "corner")
991
+ onMouseDown: (e) => handleMouseDown(e, "corner"),
992
+ role: "presentation"
1129
993
  }
1130
994
  )
1131
995
  ] })
1132
996
  ]
1133
997
  }
1134
- )
1135
- }
1136
- );
1137
- }
998
+ )
999
+ }
1000
+ );
1001
+ };
1002
+
1003
+ // src/ui/dialog.tsx
1004
+ import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
1005
+ import "react";
1006
+ import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
1007
+ var Dialog = ({ ...props }) => /* @__PURE__ */ jsx11(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
1008
+ var DialogTrigger = ({ ...props }) => /* @__PURE__ */ jsx11(DialogPrimitive.Trigger, { "data-slot": "dialog-trigger", ...props });
1009
+ var DialogPortal = ({ ...props }) => /* @__PURE__ */ jsx11(DialogPrimitive.Portal, { "data-slot": "dialog-portal", ...props });
1010
+ var DialogClose = ({ ...props }) => /* @__PURE__ */ jsx11(DialogPrimitive.Close, { "data-slot": "dialog-close", ...props });
1011
+ var DialogOverlay = ({
1012
+ className,
1013
+ ...props
1014
+ }) => /* @__PURE__ */ jsx11(
1015
+ DialogPrimitive.Backdrop,
1016
+ {
1017
+ "data-slot": "dialog-overlay",
1018
+ className: cn(
1019
+ "fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
1020
+ className
1021
+ ),
1022
+ ...props
1023
+ }
1024
+ );
1025
+ var DialogContent = ({
1026
+ className,
1027
+ children,
1028
+ showCloseButton = true,
1029
+ ...props
1030
+ }) => /* @__PURE__ */ jsxs5(DialogPortal, { children: [
1031
+ /* @__PURE__ */ jsx11(DialogOverlay, {}),
1032
+ /* @__PURE__ */ jsxs5(
1033
+ DialogPrimitive.Popup,
1034
+ {
1035
+ "data-slot": "dialog-content",
1036
+ className: cn(
1037
+ "fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-none bg-popover p-4 text-xs/relaxed text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
1038
+ className
1039
+ ),
1040
+ ...props,
1041
+ children: [
1042
+ children,
1043
+ showCloseButton && /* @__PURE__ */ jsxs5(
1044
+ DialogPrimitive.Close,
1045
+ {
1046
+ "data-slot": "dialog-close",
1047
+ render: /* @__PURE__ */ jsx11(
1048
+ Button,
1049
+ {
1050
+ variant: "ghost",
1051
+ className: "absolute top-2 right-2",
1052
+ size: "icon-sm"
1053
+ }
1054
+ ),
1055
+ children: [
1056
+ "X",
1057
+ /* @__PURE__ */ jsx11("span", { className: "sr-only", children: "Close" })
1058
+ ]
1059
+ }
1060
+ )
1061
+ ]
1062
+ }
1063
+ )
1064
+ ] });
1065
+ var DialogHeader = ({ className, ...props }) => /* @__PURE__ */ jsx11(
1066
+ "div",
1067
+ {
1068
+ "data-slot": "dialog-header",
1069
+ className: cn("flex flex-col gap-1 text-left", className),
1070
+ ...props
1071
+ }
1072
+ );
1073
+ var DialogFooter = ({
1074
+ className,
1075
+ showCloseButton = false,
1076
+ children,
1077
+ ...props
1078
+ }) => /* @__PURE__ */ jsxs5(
1079
+ "div",
1080
+ {
1081
+ "data-slot": "dialog-footer",
1082
+ className: cn(
1083
+ "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
1084
+ className
1085
+ ),
1086
+ ...props,
1087
+ children: [
1088
+ children,
1089
+ showCloseButton && /* @__PURE__ */ jsx11(DialogPrimitive.Close, { render: /* @__PURE__ */ jsx11(Button, { variant: "outline" }), children: "Close" })
1090
+ ]
1091
+ }
1092
+ );
1093
+ var DialogTitle = ({ className, ...props }) => /* @__PURE__ */ jsx11(
1094
+ DialogPrimitive.Title,
1095
+ {
1096
+ "data-slot": "dialog-title",
1097
+ className: cn("text-sm font-medium", className),
1098
+ ...props
1099
+ }
1100
+ );
1101
+ var DialogDescription = ({
1102
+ className,
1103
+ ...props
1104
+ }) => /* @__PURE__ */ jsx11(
1105
+ DialogPrimitive.Description,
1106
+ {
1107
+ "data-slot": "dialog-description",
1108
+ className: cn(
1109
+ "text-xs/relaxed text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
1110
+ className
1111
+ ),
1112
+ ...props
1113
+ }
1114
+ );
1115
+
1116
+ // src/controls/rte-twitter-control.tsx
1117
+ import { jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime";
1118
+ var WIDGET_SCRIPT_URL = "https://platform.twitter.com/widgets.js";
1119
+ var TwitterNodeView = (props) => {
1120
+ const { node } = props;
1121
+ const containerRef = useRef3(null);
1122
+ const [loading, setLoading] = useState3(true);
1123
+ const { tweetId } = node.attrs;
1124
+ const w = node.attrs.width;
1125
+ const h = node.attrs.height;
1126
+ const renderTweet = useCallback5(async () => {
1127
+ if (!containerRef.current || !tweetId) {
1128
+ return;
1129
+ }
1130
+ containerRef.current.innerHTML = "";
1131
+ setLoading(true);
1132
+ const { twttr } = window;
1133
+ if (twttr?.widgets && containerRef.current) {
1134
+ try {
1135
+ await twttr.widgets.createTweet(tweetId, containerRef.current);
1136
+ setLoading(false);
1137
+ } catch {
1138
+ }
1139
+ }
1140
+ }, [tweetId]);
1141
+ useEffect3(() => {
1142
+ if (!containerRef.current || !tweetId) {
1143
+ return;
1144
+ }
1145
+ const load = async () => {
1146
+ if (window.twttr?.widgets && containerRef.current) {
1147
+ containerRef.current.innerHTML = "";
1148
+ setLoading(true);
1149
+ try {
1150
+ await window.twttr.widgets.createTweet(tweetId, containerRef.current);
1151
+ setLoading(false);
1152
+ } catch {
1153
+ }
1154
+ } else {
1155
+ const script = document.createElement("script");
1156
+ script.src = WIDGET_SCRIPT_URL;
1157
+ script.async = true;
1158
+ script.addEventListener("load", () => {
1159
+ void renderTweet();
1160
+ });
1161
+ document.body.append(script);
1162
+ }
1163
+ };
1164
+ void load();
1165
+ }, [tweetId, w, h, renderTweet]);
1166
+ return /* @__PURE__ */ jsxs6(
1167
+ ResizableNodeView,
1168
+ {
1169
+ ...props,
1170
+ lockAspect: false,
1171
+ minWidth: 300,
1172
+ maxWidth: 1200,
1173
+ children: [
1174
+ loading && /* @__PURE__ */ jsx12("div", { className: "rte-embed-loading", children: "Loading tweet..." }),
1175
+ /* @__PURE__ */ jsx12("div", { ref: containerRef })
1176
+ ]
1177
+ }
1178
+ );
1179
+ };
1180
+ var TwitterEmbed = Node.create({
1181
+ addAttributes() {
1182
+ return {
1183
+ align: {
1184
+ default: "center",
1185
+ parseHTML: (el) => el.dataset.align || "center",
1186
+ renderHTML: (attrs) => ({
1187
+ "data-align": attrs.align
1188
+ })
1189
+ },
1190
+ height: {
1191
+ default: 400,
1192
+ parseHTML: (el) => el.dataset.height ? Number(el.dataset.height) : 400,
1193
+ renderHTML: (attrs) => ({
1194
+ "data-height": attrs.height
1195
+ })
1196
+ },
1197
+ tweetId: {
1198
+ default: null,
1199
+ parseHTML: (el) => el.dataset.tweetId,
1200
+ renderHTML: (attrs) => ({
1201
+ "data-tweet-id": attrs.tweetId
1202
+ })
1203
+ },
1204
+ width: {
1205
+ default: 550,
1206
+ parseHTML: (el) => el.dataset.width ? Number(el.dataset.width) : 550,
1207
+ renderHTML: (attrs) => ({
1208
+ "data-width": attrs.width
1209
+ })
1210
+ }
1211
+ };
1212
+ },
1213
+ addCommands() {
1214
+ return {
1215
+ setTwitterEmbed: (tweetId) => ({ commands }) => commands.insertContent({
1216
+ attrs: { tweetId },
1217
+ type: "twitter"
1218
+ })
1219
+ };
1220
+ },
1221
+ addInputRules() {
1222
+ return [
1223
+ nodeInputRule({
1224
+ find: /https?:\/\/(?:www\.)?(?:twitter\.com|x\.com)\/\w+\/status\/(\d+)/,
1225
+ getAttributes: (match) => ({ tweetId: match[1] }),
1226
+ type: this.type
1227
+ })
1228
+ ];
1229
+ },
1230
+ addNodeView() {
1231
+ return ReactNodeViewRenderer(TwitterNodeView);
1232
+ },
1233
+ atom: true,
1234
+ draggable: true,
1235
+ group: "block",
1236
+ name: "twitter",
1237
+ parseHTML() {
1238
+ return [{ tag: 'div[data-type="twitter"]' }];
1239
+ },
1240
+ renderHTML({ node }) {
1241
+ return [
1242
+ "div",
1243
+ {
1244
+ "data-align": node.attrs.align,
1245
+ "data-height": node.attrs.height,
1246
+ "data-tweet-id": node.attrs.tweetId,
1247
+ "data-type": "twitter",
1248
+ "data-width": node.attrs.width
1249
+ }
1250
+ ];
1251
+ }
1252
+ });
1253
+ var extractTweetId = (input) => {
1254
+ const clean = input.trim();
1255
+ const match = clean.match(
1256
+ /(?:twitter\.com|x\.com)\/(?:\w+\/status\/|i\/web\/status\/)(\d+)/
1257
+ );
1258
+ if (match) {
1259
+ return match[1] ?? null;
1260
+ }
1261
+ return /^\d+$/.test(clean) ? clean : null;
1262
+ };
1263
+ var TwitterEmbedControl = ({ className }) => {
1264
+ const { editor } = useRichTextEditorContext();
1265
+ const [open, setOpen] = useState3(false);
1266
+ const [url, setUrl] = useState3("");
1267
+ const { active } = useEditorState4({
1268
+ editor: editor ?? null,
1269
+ selector: (ctx) => ({
1270
+ active: ctx.editor && !ctx.editor.isDestroyed ? ctx.editor.isActive("twitter") : false
1271
+ })
1272
+ }) ?? { active: false };
1273
+ const handleInsert = useCallback5(() => {
1274
+ if (url && editor) {
1275
+ const tweetId = extractTweetId(url);
1276
+ if (tweetId) {
1277
+ editor.chain().focus().setTwitterEmbed(tweetId).run();
1278
+ setUrl("");
1279
+ }
1280
+ }
1281
+ }, [url, editor]);
1282
+ return /* @__PURE__ */ jsxs6(Dialog, { open, onOpenChange: setOpen, children: [
1283
+ /* @__PURE__ */ jsx12(
1284
+ DialogTrigger,
1285
+ {
1286
+ render: /* @__PURE__ */ jsx12(
1287
+ RichTextEditorControl,
1288
+ {
1289
+ active,
1290
+ className,
1291
+ title: "Embed Tweet",
1292
+ "aria-label": "Embed Tweet",
1293
+ children: /* @__PURE__ */ jsx12(
1294
+ "svg",
1295
+ {
1296
+ xmlns: "http://www.w3.org/2000/svg",
1297
+ viewBox: "0 0 24 24",
1298
+ fill: "currentColor",
1299
+ className: "rte-editor-icon",
1300
+ children: /* @__PURE__ */ jsx12("path", { d: "M18.2 3.2h3.3l-7.2 8.2 8.5 11.2h-6.6l-5.2-6.8-6 6.8H2.7l7.7-8.8L2.3 3.2h6.8l4.7 6.2 5.4-6.2zm-1.2 17.3h1.8L7 4.8H5.1l11.9 15.7z" })
1301
+ }
1302
+ )
1303
+ }
1304
+ )
1305
+ }
1306
+ ),
1307
+ /* @__PURE__ */ jsxs6(DialogContent, { children: [
1308
+ /* @__PURE__ */ jsxs6(DialogHeader, { children: [
1309
+ /* @__PURE__ */ jsx12(DialogTitle, { children: "Embed Tweet" }),
1310
+ /* @__PURE__ */ jsx12(DialogDescription, { children: "Paste a tweet URL or ID." })
1311
+ ] }),
1312
+ /* @__PURE__ */ jsx12(
1313
+ Input,
1314
+ {
1315
+ value: url,
1316
+ onChange: (e) => setUrl(e.target.value),
1317
+ placeholder: "https://x.com/user/status/...",
1318
+ onKeyDown: (e) => {
1319
+ if (e.key === "Enter" && url) {
1320
+ handleInsert();
1321
+ setOpen(false);
1322
+ }
1323
+ }
1324
+ }
1325
+ ),
1326
+ /* @__PURE__ */ jsxs6(DialogFooter, { children: [
1327
+ /* @__PURE__ */ jsx12(DialogClose, { children: "Cancel" }),
1328
+ /* @__PURE__ */ jsx12(
1329
+ DialogClose,
1330
+ {
1331
+ disabled: !url,
1332
+ className: "rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-50",
1333
+ onClick: handleInsert,
1334
+ children: "Insert"
1335
+ }
1336
+ )
1337
+ ] })
1338
+ ] })
1339
+ ] });
1340
+ };
1138
1341
 
1139
1342
  // src/controls/rte-youtube-control.tsx
1140
- import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
1141
- function getYouTubeId(url) {
1343
+ import { Node as Node2, nodeInputRule as nodeInputRule2 } from "@tiptap/core";
1344
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer2, useEditorState as useEditorState5 } from "@tiptap/react";
1345
+ import { useState as useState4, useCallback as useCallback6 } from "react";
1346
+ import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
1347
+ var getYouTubeId = (url) => {
1142
1348
  const clean = url.trim();
1143
1349
  const patterns = [
1144
1350
  /(?:youtube\.com\/watch\?v=)([a-zA-Z0-9_-]{11})/,
@@ -1151,61 +1357,93 @@ function getYouTubeId(url) {
1151
1357
  ];
1152
1358
  for (const pattern of patterns) {
1153
1359
  const match = clean.match(pattern);
1154
- if (match) return match[1] ?? null;
1360
+ if (match) {
1361
+ return match[1] ?? null;
1362
+ }
1155
1363
  }
1156
1364
  return /^[a-zA-Z0-9_-]{11}$/.test(clean) ? clean : null;
1157
- }
1158
- function YouTubeNodeView(props) {
1365
+ };
1366
+ var YouTubeNodeView = (props) => {
1159
1367
  const { node } = props;
1160
1368
  const videoId = getYouTubeId(node.attrs.src) || node.attrs.src;
1161
- return /* @__PURE__ */ jsx14(ResizableNodeView, { ...props, lockAspect: true, aspectRatio: 16 / 9, minWidth: 320, maxWidth: 1200, children: /* @__PURE__ */ jsx14(
1162
- "iframe",
1369
+ return /* @__PURE__ */ jsx13(
1370
+ ResizableNodeView,
1163
1371
  {
1164
- src: `https://www.youtube-nocookie.com/embed/${videoId}`,
1165
- allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",
1166
- allowFullScreen: true,
1167
- title: "YouTube video",
1168
- className: "rte-embed-iframe"
1372
+ ...props,
1373
+ lockAspect: true,
1374
+ aspectRatio: 16 / 9,
1375
+ minWidth: 320,
1376
+ maxWidth: 1200,
1377
+ children: /* @__PURE__ */ jsx13(
1378
+ "iframe",
1379
+ {
1380
+ src: `https://www.youtube-nocookie.com/embed/${videoId}`,
1381
+ allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",
1382
+ allowFullScreen: true,
1383
+ title: "YouTube video",
1384
+ className: "rte-embed-iframe"
1385
+ }
1386
+ )
1169
1387
  }
1170
- ) });
1171
- }
1172
- var YouTubeEmbed = Node.create({
1173
- name: "youtube",
1174
- group: "block",
1175
- atom: true,
1176
- draggable: true,
1388
+ );
1389
+ };
1390
+ var YouTubeEmbed = Node2.create({
1177
1391
  addAttributes() {
1178
1392
  return {
1179
- src: {
1180
- default: null,
1181
- parseHTML: (el) => el.getAttribute("data-src"),
1182
- renderHTML: (attrs) => ({
1183
- "data-src": attrs.src
1184
- })
1185
- },
1186
- width: {
1187
- default: 560,
1188
- parseHTML: (el) => el.getAttribute("data-width") ? Number(el.getAttribute("data-width")) : 560,
1393
+ align: {
1394
+ default: "center",
1395
+ parseHTML: (el) => el.dataset.align || "center",
1189
1396
  renderHTML: (attrs) => ({
1190
- "data-width": attrs.width
1397
+ "data-align": attrs.align
1191
1398
  })
1192
1399
  },
1193
1400
  height: {
1194
1401
  default: 315,
1195
- parseHTML: (el) => el.getAttribute("data-height") ? Number(el.getAttribute("data-height")) : 315,
1402
+ parseHTML: (el) => el.dataset.height ? Number(el.dataset.height) : 315,
1196
1403
  renderHTML: (attrs) => ({
1197
1404
  "data-height": attrs.height
1198
1405
  })
1199
1406
  },
1200
- align: {
1201
- default: "center",
1202
- parseHTML: (el) => el.getAttribute("data-align") || "center",
1407
+ src: {
1408
+ default: null,
1409
+ parseHTML: (el) => el.dataset.src,
1203
1410
  renderHTML: (attrs) => ({
1204
- "data-align": attrs.align
1411
+ "data-src": attrs.src
1412
+ })
1413
+ },
1414
+ width: {
1415
+ default: 560,
1416
+ parseHTML: (el) => el.dataset.width ? Number(el.dataset.width) : 560,
1417
+ renderHTML: (attrs) => ({
1418
+ "data-width": attrs.width
1205
1419
  })
1206
1420
  }
1207
1421
  };
1208
1422
  },
1423
+ addCommands() {
1424
+ return {
1425
+ setYouTubeEmbed: (src) => ({ commands }) => commands.insertContent({
1426
+ attrs: { src },
1427
+ type: "youtube"
1428
+ })
1429
+ };
1430
+ },
1431
+ addInputRules() {
1432
+ return [
1433
+ nodeInputRule2({
1434
+ find: /https?:\/\/(?:www\.|m\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=|embed\/|shorts\/|live\/|v\/)?([a-zA-Z0-9_-]{11})/,
1435
+ getAttributes: (match) => ({ src: match[0] }),
1436
+ type: this.type
1437
+ })
1438
+ ];
1439
+ },
1440
+ addNodeView() {
1441
+ return ReactNodeViewRenderer2(YouTubeNodeView);
1442
+ },
1443
+ atom: true,
1444
+ draggable: true,
1445
+ group: "block",
1446
+ name: "youtube",
1209
1447
  parseHTML() {
1210
1448
  return [{ tag: 'div[data-type="youtube"]' }];
1211
1449
  },
@@ -1213,58 +1451,36 @@ var YouTubeEmbed = Node.create({
1213
1451
  return [
1214
1452
  "div",
1215
1453
  {
1216
- "data-type": "youtube",
1217
- "data-src": node.attrs.src,
1218
- "data-width": node.attrs.width,
1454
+ "data-align": node.attrs.align,
1219
1455
  "data-height": node.attrs.height,
1220
- "data-align": node.attrs.align
1221
- }
1222
- ];
1223
- },
1224
- addNodeView() {
1225
- return ReactNodeViewRenderer(YouTubeNodeView);
1226
- },
1227
- addCommands() {
1228
- return {
1229
- setYouTubeEmbed: (src) => ({ commands }) => {
1230
- return commands.insertContent({
1231
- type: "youtube",
1232
- attrs: { src }
1233
- });
1456
+ "data-src": node.attrs.src,
1457
+ "data-type": "youtube",
1458
+ "data-width": node.attrs.width
1234
1459
  }
1235
- };
1236
- },
1237
- addInputRules() {
1238
- return [
1239
- nodeInputRule({
1240
- find: /https?:\/\/(?:www\.|m\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=|embed\/|shorts\/|live\/|v\/)?([a-zA-Z0-9_-]{11})/,
1241
- type: this.type,
1242
- getAttributes: (match) => ({ src: match[0] })
1243
- })
1244
1460
  ];
1245
1461
  }
1246
1462
  });
1247
- function YouTubeEmbedControl({ className }) {
1463
+ var YouTubeEmbedControl = ({ className }) => {
1248
1464
  const { editor } = useRichTextEditorContext();
1249
- const [open, setOpen] = useState3(false);
1250
- const [url, setUrl] = useState3("");
1251
- const { active } = useEditorState3({
1465
+ const [open, setOpen] = useState4(false);
1466
+ const [url, setUrl] = useState4("");
1467
+ const { active } = useEditorState5({
1252
1468
  editor: editor ?? null,
1253
1469
  selector: (ctx) => ({
1254
1470
  active: ctx.editor && !ctx.editor.isDestroyed ? ctx.editor.isActive("youtube") : false
1255
1471
  })
1256
1472
  }) ?? { active: false };
1257
- const handleInsert = useCallback2(() => {
1473
+ const handleInsert = useCallback6(() => {
1258
1474
  if (url && editor) {
1259
1475
  editor.chain().focus().setYouTubeEmbed(url).run();
1260
1476
  setUrl("");
1261
1477
  }
1262
1478
  }, [url, editor]);
1263
1479
  return /* @__PURE__ */ jsxs7(Dialog, { open, onOpenChange: setOpen, children: [
1264
- /* @__PURE__ */ jsx14(
1480
+ /* @__PURE__ */ jsx13(
1265
1481
  DialogTrigger,
1266
1482
  {
1267
- render: /* @__PURE__ */ jsx14(
1483
+ render: /* @__PURE__ */ jsx13(
1268
1484
  RichTextEditorControl,
1269
1485
  {
1270
1486
  active,
@@ -1278,13 +1494,13 @@ function YouTubeEmbedControl({ className }) {
1278
1494
  viewBox: "0 0 24 24",
1279
1495
  fill: "none",
1280
1496
  stroke: "currentColor",
1281
- "stroke-width": "2",
1282
- "stroke-linecap": "round",
1283
- "stroke-linejoin": "round",
1497
+ strokeWidth: "2",
1498
+ strokeLinecap: "round",
1499
+ strokeLinejoin: "round",
1284
1500
  className: "rte-editor-icon",
1285
1501
  children: [
1286
- /* @__PURE__ */ jsx14("path", { d: "M23.5 6.2a3 3 0 0 0-2.1-2.1C19.5 3.5 12 3.5 12 3.5s-7.5 0-9.4.6a3 3 0 0 0-2.1 2.1C0 8.1 0 12 0 12s0 3.9.5 5.8a3 3 0 0 0 2.1 2.1c1.9.6 9.4.6 9.4.6s7.5 0 9.4-.6a3 3 0 0 0 2.1-2.1c.5-1.9.5-5.8.5-5.8s0-3.9-.5-5.8z" }),
1287
- /* @__PURE__ */ jsx14("path", { d: "M9.5 15.5V8.5l6.2 3.5z" })
1502
+ /* @__PURE__ */ jsx13("path", { d: "M23.5 6.2a3 3 0 0 0-2.1-2.1C19.5 3.5 12 3.5 12 3.5s-7.5 0-9.4.6a3 3 0 0 0-2.1 2.1C0 8.1 0 12 0 12s0 3.9.5 5.8a3 3 0 0 0 2.1 2.1c1.9.6 9.4.6 9.4.6s7.5 0 9.4-.6a3 3 0 0 0 2.1-2.1c.5-1.9.5-5.8.5-5.8s0-3.9-.5-5.8z" }),
1503
+ /* @__PURE__ */ jsx13("path", { d: "M9.5 15.5V8.5l6.2 3.5z" })
1288
1504
  ]
1289
1505
  }
1290
1506
  )
@@ -1294,10 +1510,10 @@ function YouTubeEmbedControl({ className }) {
1294
1510
  ),
1295
1511
  /* @__PURE__ */ jsxs7(DialogContent, { showCloseButton: false, children: [
1296
1512
  /* @__PURE__ */ jsxs7(DialogHeader, { children: [
1297
- /* @__PURE__ */ jsx14(DialogTitle, { children: "Embed YouTube video" }),
1298
- /* @__PURE__ */ jsx14(DialogDescription, { children: "Paste a YouTube video URL or ID." })
1513
+ /* @__PURE__ */ jsx13(DialogTitle, { children: "Embed YouTube video" }),
1514
+ /* @__PURE__ */ jsx13(DialogDescription, { children: "Paste a YouTube video URL or ID." })
1299
1515
  ] }),
1300
- /* @__PURE__ */ jsx14(
1516
+ /* @__PURE__ */ jsx13(
1301
1517
  Input,
1302
1518
  {
1303
1519
  value: url,
@@ -1312,8 +1528,8 @@ function YouTubeEmbedControl({ className }) {
1312
1528
  }
1313
1529
  ),
1314
1530
  /* @__PURE__ */ jsxs7(DialogFooter, { children: [
1315
- /* @__PURE__ */ jsx14(DialogClose, { children: "Cancel" }),
1316
- /* @__PURE__ */ jsx14(
1531
+ /* @__PURE__ */ jsx13(DialogClose, { children: "Cancel" }),
1532
+ /* @__PURE__ */ jsx13(
1317
1533
  DialogClose,
1318
1534
  {
1319
1535
  disabled: !url,
@@ -1325,214 +1541,491 @@ function YouTubeEmbedControl({ className }) {
1325
1541
  ] })
1326
1542
  ] })
1327
1543
  ] });
1328
- }
1544
+ };
1329
1545
 
1330
- // src/controls/rte-twitter-control.tsx
1331
- import { useState as useState4, useCallback as useCallback3, useEffect as useEffect4, useRef as useRef3 } from "react";
1332
- import { Node as Node2, nodeInputRule as nodeInputRule2 } from "@tiptap/core";
1333
- import {
1334
- ReactNodeViewRenderer as ReactNodeViewRenderer2,
1335
- useEditorState as useEditorState4
1336
- } from "@tiptap/react";
1337
- import { jsx as jsx15, jsxs as jsxs8 } from "react/jsx-runtime";
1338
- var WIDGET_SCRIPT_URL = "https://platform.twitter.com/widgets.js";
1339
- function TwitterNodeView(props) {
1340
- const { node } = props;
1341
- const containerRef = useRef3(null);
1342
- const [loading, setLoading] = useState4(true);
1343
- const tweetId = node.attrs.tweetId;
1344
- const w = node.attrs.width;
1345
- const h = node.attrs.height;
1346
- const renderTweet = useCallback3(() => {
1347
- if (!containerRef.current || !tweetId) return;
1348
- containerRef.current.innerHTML = "";
1349
- setLoading(true);
1350
- const twttr = window.twttr;
1351
- if (twttr?.widgets) {
1352
- twttr.widgets.createTweet(tweetId, containerRef.current).then(() => {
1353
- setLoading(false);
1354
- });
1355
- }
1356
- }, [tweetId]);
1546
+ // src/icons.tsx
1547
+ import "react";
1548
+ import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
1549
+ var iconProps = { className: "rte-editor-icon" };
1550
+ var Svg2 = ({
1551
+ children,
1552
+ className,
1553
+ strokeWidth = 2
1554
+ }) => /* @__PURE__ */ jsx14(
1555
+ "svg",
1556
+ {
1557
+ xmlns: "http://www.w3.org/2000/svg",
1558
+ viewBox: "0 0 24 24",
1559
+ fill: "none",
1560
+ stroke: "currentColor",
1561
+ strokeWidth,
1562
+ strokeLinecap: "round",
1563
+ strokeLinejoin: "round",
1564
+ className,
1565
+ children
1566
+ }
1567
+ );
1568
+ var LangIcon = ({
1569
+ children,
1570
+ className
1571
+ }) => /* @__PURE__ */ jsx14(
1572
+ "svg",
1573
+ {
1574
+ xmlns: "http://www.w3.org/2000/svg",
1575
+ viewBox: "0 0 24 24",
1576
+ fill: "none",
1577
+ stroke: "currentColor",
1578
+ strokeWidth: 1.5,
1579
+ strokeLinecap: "round",
1580
+ strokeLinejoin: "round",
1581
+ className,
1582
+ children
1583
+ }
1584
+ );
1585
+ var DEFAULT_LANGUAGE_ICONS = {
1586
+ bash: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1587
+ /* @__PURE__ */ jsx14("rect", { x: "2.5", y: "4", width: "19", height: "16", rx: "2" }),
1588
+ /* @__PURE__ */ jsx14("path", { d: "M6.5 9.5l3.5 3-3.5 3" }),
1589
+ /* @__PURE__ */ jsx14("path", { d: "M12 15.5h5.5" })
1590
+ ] }),
1591
+ c: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1592
+ /* @__PURE__ */ jsx14("circle", { cx: "12", cy: "12", r: "8.5" }),
1593
+ /* @__PURE__ */ jsx14("path", { d: "M15.6 9.3a4.5 4.5 0 1 0 0 5.4" })
1594
+ ] }),
1595
+ cpp: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1596
+ /* @__PURE__ */ jsx14("circle", { cx: "9.5", cy: "12", r: "6.5" }),
1597
+ /* @__PURE__ */ jsx14("path", { d: "M12.3 9.7a3.3 3.3 0 1 0 0 4.6" }),
1598
+ /* @__PURE__ */ jsx14("path", { d: "M15.7 10.5v3M14.2 12h3" }),
1599
+ /* @__PURE__ */ jsx14("path", { d: "M19.3 10.5v3M17.8 12h3" })
1600
+ ] }),
1601
+ css: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1602
+ /* @__PURE__ */ jsx14("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
1603
+ /* @__PURE__ */ jsx14("path", { d: "M9.7 7.5l-1 9" }),
1604
+ /* @__PURE__ */ jsx14("path", { d: "M15.3 7.5l-1 9" }),
1605
+ /* @__PURE__ */ jsx14("path", { d: "M7 10.3h11" }),
1606
+ /* @__PURE__ */ jsx14("path", { d: "M6.5 14.3h11" })
1607
+ ] }),
1608
+ go: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1609
+ /* @__PURE__ */ jsx14("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
1610
+ /* @__PURE__ */ jsx14("path", { d: "M12.6 9.7A3.3 3.3 0 1 0 12.6 14.3" }),
1611
+ /* @__PURE__ */ jsx14("path", { d: "M12.6 12h-1.9" }),
1612
+ /* @__PURE__ */ jsx14("circle", { cx: "17", cy: "12", r: "2.9" })
1613
+ ] }),
1614
+ html: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1615
+ /* @__PURE__ */ jsx14("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
1616
+ /* @__PURE__ */ jsx14("path", { d: "M9.5 8.5L6.5 12l3 3.5" }),
1617
+ /* @__PURE__ */ jsx14("path", { d: "M14.5 8.5L17.5 12l-3 3.5" }),
1618
+ /* @__PURE__ */ jsx14("path", { d: "M13 7.3l-2 9.4" })
1619
+ ] }),
1620
+ java: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1621
+ /* @__PURE__ */ jsx14("path", { d: "M6 10h10v5a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-5z" }),
1622
+ /* @__PURE__ */ jsx14("path", { d: "M16 12h1.3a1.8 1.8 0 0 1 0 3.6H16" }),
1623
+ /* @__PURE__ */ jsx14("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" }),
1624
+ /* @__PURE__ */ jsx14("path", { d: "M6 19.3h10" })
1625
+ ] }),
1626
+ javascript: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1627
+ /* @__PURE__ */ jsx14("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
1628
+ /* @__PURE__ */ jsx14("path", { d: "M10.5 8v6.5a2 2 0 0 1-3.5 1.3" }),
1629
+ /* @__PURE__ */ jsx14("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" })
1630
+ ] }),
1631
+ json: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1632
+ /* @__PURE__ */ jsx14("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" }),
1633
+ /* @__PURE__ */ jsx14("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" })
1634
+ ] }),
1635
+ kotlin: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1636
+ /* @__PURE__ */ jsx14("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
1637
+ /* @__PURE__ */ jsx14("path", { d: "M9 7.5v9" }),
1638
+ /* @__PURE__ */ jsx14("path", { d: "M9 12l6-4.5" }),
1639
+ /* @__PURE__ */ jsx14("path", { d: "M9 12l6 4.5" })
1640
+ ] }),
1641
+ markdown: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1642
+ /* @__PURE__ */ jsx14("rect", { x: "2", y: "5", width: "20", height: "14", rx: "2" }),
1643
+ /* @__PURE__ */ jsx14("path", { d: "M6 15V9l3 4 3-4v6" }),
1644
+ /* @__PURE__ */ jsx14("path", { d: "M16.5 9v6" }),
1645
+ /* @__PURE__ */ jsx14("path", { d: "M14.5 13l2 2 2-2" })
1646
+ ] }),
1647
+ php: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1648
+ /* @__PURE__ */ jsx14("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
1649
+ /* @__PURE__ */ jsx14("path", { d: "M11.5 8.5L7.5 12l4 3.5" }),
1650
+ /* @__PURE__ */ jsx14("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" }),
1651
+ /* @__PURE__ */ jsx14("circle", { cx: "14.3", cy: "16.2", r: ".5", fill: "currentColor", stroke: "none" })
1652
+ ] }),
1653
+ plaintext: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1654
+ /* @__PURE__ */ jsx14("rect", { x: "4", y: "2.5", width: "16", height: "19", rx: "2" }),
1655
+ /* @__PURE__ */ jsx14("line", { x1: "7.5", y1: "7.5", x2: "16.5", y2: "7.5" }),
1656
+ /* @__PURE__ */ jsx14("line", { x1: "7.5", y1: "11.5", x2: "16.5", y2: "11.5" }),
1657
+ /* @__PURE__ */ jsx14("line", { x1: "7.5", y1: "15.5", x2: "13.5", y2: "15.5" })
1658
+ ] }),
1659
+ python: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1660
+ /* @__PURE__ */ jsx14("path", { d: "M4.5 15c0-3 2.5-4.7 5.7-4.7h1.6c2.8 0 5-2 5-4.5" }),
1661
+ /* @__PURE__ */ jsx14("path", { d: "M9.5 3.3c1.3-.3 2.6 0 3.3 1-.7 1-2 1.3-3.3 1" }),
1662
+ /* @__PURE__ */ jsx14("circle", { cx: "15.5", cy: "4.3", r: ".55", fill: "currentColor", stroke: "none" }),
1663
+ /* @__PURE__ */ jsx14("path", { d: "M17.8 4.5l1.4-.6M17.8 4.9l1.4.6" })
1664
+ ] }),
1665
+ ruby: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1666
+ /* @__PURE__ */ jsx14("polygon", { points: "12 2.5 19.5 8 12 21.5 4.5 8" }),
1667
+ /* @__PURE__ */ jsx14("path", { d: "M4.5 8h15" }),
1668
+ /* @__PURE__ */ jsx14("path", { d: "M12 2.5v19" })
1669
+ ] }),
1670
+ rust: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1671
+ /* @__PURE__ */ jsx14("circle", { cx: "12", cy: "12", r: "7" }),
1672
+ /* @__PURE__ */ jsx14("circle", { cx: "12", cy: "12", r: "2.3" }),
1673
+ /* @__PURE__ */ jsx14("path", { d: "M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3" }),
1674
+ /* @__PURE__ */ jsx14("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" })
1675
+ ] }),
1676
+ sql: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1677
+ /* @__PURE__ */ jsx14("ellipse", { cx: "12", cy: "6", rx: "8", ry: "3" }),
1678
+ /* @__PURE__ */ jsx14("path", { d: "M4 6v6c0 1.7 3.6 3 8 3s8-1.3 8-3V6" }),
1679
+ /* @__PURE__ */ jsx14("path", { d: "M4 12v6c0 1.7 3.6 3 8 3s8-1.3 8-3v-6" })
1680
+ ] }),
1681
+ swift: /* @__PURE__ */ jsx14(LangIcon, { children: /* @__PURE__ */ jsx14("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" }) }),
1682
+ typescript: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1683
+ /* @__PURE__ */ jsx14("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4" }),
1684
+ /* @__PURE__ */ jsx14("path", { d: "M7.3 8.2h5M9.8 8.2v7.6" }),
1685
+ /* @__PURE__ */ jsx14("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" })
1686
+ ] }),
1687
+ xml: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1688
+ /* @__PURE__ */ jsx14("path", { d: "M8 7l-4.5 5 4.5 5" }),
1689
+ /* @__PURE__ */ jsx14("path", { d: "M16 7l4.5 5-4.5 5" }),
1690
+ /* @__PURE__ */ jsx14("path", { d: "M12 8v8" })
1691
+ ] }),
1692
+ yaml: /* @__PURE__ */ jsxs8(LangIcon, { children: [
1693
+ /* @__PURE__ */ jsx14("rect", { x: "2.5", y: "3", width: "19", height: "18", rx: "2" }),
1694
+ /* @__PURE__ */ jsx14("path", { d: "M6.5 8h2M9.5 8h8" }),
1695
+ /* @__PURE__ */ jsx14("path", { d: "M6.5 12h2M9.5 12h6" }),
1696
+ /* @__PURE__ */ jsx14("path", { d: "M6.5 16h2M9.5 16h7" })
1697
+ ] })
1698
+ };
1699
+ var DEFAULT_ICONS = {
1700
+ alignCenterControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1701
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
1702
+ /* @__PURE__ */ jsx14("line", { x1: "7", y1: "12", x2: "17", y2: "12" }),
1703
+ /* @__PURE__ */ jsx14("line", { x1: "5.5", y1: "18", x2: "18.5", y2: "18" })
1704
+ ] }),
1705
+ alignJustifyControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1706
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
1707
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "12", x2: "20", y2: "12" }),
1708
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "18", x2: "20", y2: "18" })
1709
+ ] }),
1710
+ alignLeftControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1711
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
1712
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "12", x2: "14", y2: "12" }),
1713
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "18", x2: "17", y2: "18" })
1714
+ ] }),
1715
+ alignRightControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1716
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
1717
+ /* @__PURE__ */ jsx14("line", { x1: "10", y1: "12", x2: "20", y2: "12" }),
1718
+ /* @__PURE__ */ jsx14("line", { x1: "7", y1: "18", x2: "20", y2: "18" })
1719
+ ] }),
1720
+ blockquoteControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1721
+ /* @__PURE__ */ jsx14("path", { d: "M7 8a3 3 0 0 0-3 3v2a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1H6a3 3 0 0 1 2-3" }),
1722
+ /* @__PURE__ */ jsx14("path", { d: "M16 8a3 3 0 0 0-3 3v2a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1h-1a3 3 0 0 1 2-3" })
1723
+ ] }),
1724
+ boldControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1725
+ /* @__PURE__ */ jsx14("path", { d: "M6 4h7a4 4 0 0 1 0 8H6z" }),
1726
+ /* @__PURE__ */ jsx14("path", { d: "M6 12h9a4 4 0 0 1 0 8H6z" })
1727
+ ] }),
1728
+ bulletListControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1729
+ /* @__PURE__ */ jsx14("line", { x1: "9", y1: "6", x2: "21", y2: "6" }),
1730
+ /* @__PURE__ */ jsx14("line", { x1: "9", y1: "12", x2: "21", y2: "12" }),
1731
+ /* @__PURE__ */ jsx14("line", { x1: "9", y1: "18", x2: "21", y2: "18" }),
1732
+ /* @__PURE__ */ jsx14("circle", { cx: "4", cy: "6", r: "1.2", fill: "currentColor", stroke: "none" }),
1733
+ /* @__PURE__ */ jsx14("circle", { cx: "4", cy: "12", r: "1.2", fill: "currentColor", stroke: "none" }),
1734
+ /* @__PURE__ */ jsx14("circle", { cx: "4", cy: "18", r: "1.2", fill: "currentColor", stroke: "none" })
1735
+ ] }),
1736
+ clearFormattingControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1737
+ /* @__PURE__ */ jsx14("path", { d: "M4 7V4h16v3" }),
1738
+ /* @__PURE__ */ jsx14("path", { d: "M5 20h6" }),
1739
+ /* @__PURE__ */ jsx14("path", { d: "M13 4 8 20" }),
1740
+ /* @__PURE__ */ jsx14("path", { d: "m16 16 5 5" }),
1741
+ /* @__PURE__ */ jsx14("path", { d: "m21 16-5 5" })
1742
+ ] }),
1743
+ codeBlockControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1744
+ /* @__PURE__ */ jsx14("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2" }),
1745
+ /* @__PURE__ */ jsx14("polyline", { points: "10 9 8 12 10 15" }),
1746
+ /* @__PURE__ */ jsx14("polyline", { points: "14 9 16 12 14 15" })
1747
+ ] }),
1748
+ codeControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1749
+ /* @__PURE__ */ jsx14("polyline", { points: "16 18 22 12 16 6" }),
1750
+ /* @__PURE__ */ jsx14("polyline", { points: "8 6 2 12 8 18" })
1751
+ ] }),
1752
+ h1ControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1753
+ /* @__PURE__ */ jsx14("path", { d: "M4 6v12" }),
1754
+ /* @__PURE__ */ jsx14("path", { d: "M12 6v12" }),
1755
+ /* @__PURE__ */ jsx14("path", { d: "M4 12h8" }),
1756
+ /* @__PURE__ */ jsx14("path", { d: "m17 10 3-2v8" })
1757
+ ] }),
1758
+ h2ControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1759
+ /* @__PURE__ */ jsx14("path", { d: "M4 6v12" }),
1760
+ /* @__PURE__ */ jsx14("path", { d: "M12 6v12" }),
1761
+ /* @__PURE__ */ jsx14("path", { d: "M4 12h8" }),
1762
+ /* @__PURE__ */ jsx14("path", { d: "M17 9.5a2.5 2.5 0 0 1 4.8-1c0 2-4.8 2.5-4.8 5.5h5" })
1763
+ ] }),
1764
+ h3ControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1765
+ /* @__PURE__ */ jsx14("path", { d: "M4 6v12" }),
1766
+ /* @__PURE__ */ jsx14("path", { d: "M12 6v12" }),
1767
+ /* @__PURE__ */ jsx14("path", { d: "M4 12h8" }),
1768
+ /* @__PURE__ */ jsx14("path", { d: "M17.5 9.5c1.5-1 3.5-.2 3.5 1.3a1.8 1.8 0 0 1-1.8 1.7" }),
1769
+ /* @__PURE__ */ jsx14("path", { d: "M19.2 12.5a1.8 1.8 0 0 1 1.8 1.7c0 1.5-2 2.3-3.5 1.3" })
1770
+ ] }),
1771
+ h4ControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1772
+ /* @__PURE__ */ jsx14("path", { d: "M4 6v12" }),
1773
+ /* @__PURE__ */ jsx14("path", { d: "M12 6v12" }),
1774
+ /* @__PURE__ */ jsx14("path", { d: "M4 12h8" }),
1775
+ /* @__PURE__ */ jsx14("path", { d: "M20 9v5h-4l3.5-5.5" }),
1776
+ /* @__PURE__ */ jsx14("path", { d: "M20 14v3" })
1777
+ ] }),
1778
+ h5ControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1779
+ /* @__PURE__ */ jsx14("path", { d: "M4 6v12" }),
1780
+ /* @__PURE__ */ jsx14("path", { d: "M12 6v12" }),
1781
+ /* @__PURE__ */ jsx14("path", { d: "M4 12h8" }),
1782
+ /* @__PURE__ */ jsx14("path", { d: "M21 9h-4v3.5c2.5-.7 4.5.3 4.5 2a2.3 2.3 0 0 1-4.3 1.3" })
1783
+ ] }),
1784
+ h6ControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1785
+ /* @__PURE__ */ jsx14("path", { d: "M4 6v12" }),
1786
+ /* @__PURE__ */ jsx14("path", { d: "M12 6v12" }),
1787
+ /* @__PURE__ */ jsx14("path", { d: "M4 12h8" }),
1788
+ /* @__PURE__ */ jsx14("path", { d: "M20.5 9.5c-3 1-3.5 4-3.5 5.5a2.5 2.5 0 1 0 2.5-2.5c-1 0-2 .4-2.5 1" })
1789
+ ] }),
1790
+ highlightControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1791
+ /* @__PURE__ */ jsx14("path", { d: "M9 11 3 17v3h3l6-6" }),
1792
+ /* @__PURE__ */ jsx14("path", { d: "M14 6l4-4 4 4-4 4" }),
1793
+ /* @__PURE__ */ jsx14("path", { d: "m9 11 4-4 5 5-4 4" })
1794
+ ] }),
1795
+ hrControlIcon: /* @__PURE__ */ jsx14(Svg2, { ...iconProps, children: /* @__PURE__ */ jsx14("line", { x1: "4", y1: "12", x2: "20", y2: "12" }) }),
1796
+ italicControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1797
+ /* @__PURE__ */ jsx14("line", { x1: "19", y1: "4", x2: "10", y2: "4" }),
1798
+ /* @__PURE__ */ jsx14("line", { x1: "14", y1: "20", x2: "5", y2: "20" }),
1799
+ /* @__PURE__ */ jsx14("line", { x1: "15", y1: "4", x2: "9", y2: "20" })
1800
+ ] }),
1801
+ languageIcons: DEFAULT_LANGUAGE_ICONS,
1802
+ linkControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1803
+ /* @__PURE__ */ jsx14("path", { d: "M9 17H7a5 5 0 0 1 0-10h2" }),
1804
+ /* @__PURE__ */ jsx14("path", { d: "M15 7h2a5 5 0 0 1 0 10h-2" }),
1805
+ /* @__PURE__ */ jsx14("line", { x1: "8", y1: "12", x2: "16", y2: "12" })
1806
+ ] }),
1807
+ orderedListControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1808
+ /* @__PURE__ */ jsx14("line", { x1: "10", y1: "6", x2: "21", y2: "6" }),
1809
+ /* @__PURE__ */ jsx14("line", { x1: "10", y1: "12", x2: "21", y2: "12" }),
1810
+ /* @__PURE__ */ jsx14("line", { x1: "10", y1: "18", x2: "21", y2: "18" }),
1811
+ /* @__PURE__ */ jsx14("path", { d: "M4 5h2v4" }),
1812
+ /* @__PURE__ */ jsx14("path", { d: "M4 9h2" }),
1813
+ /* @__PURE__ */ jsx14("path", { d: "M4 13h2.5L4 16h2.5" }),
1814
+ /* @__PURE__ */ jsx14("path", { d: "M4 19h2.5" })
1815
+ ] }),
1816
+ redoControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1817
+ /* @__PURE__ */ jsx14("path", { d: "m15 14 5-5-5-5" }),
1818
+ /* @__PURE__ */ jsx14("path", { d: "M20 9H9.5a5.5 5.5 0 0 0 0 11H13" })
1819
+ ] }),
1820
+ strikeControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1821
+ /* @__PURE__ */ jsx14("path", { d: "M16 4H9.5a3.5 3.5 0 0 0-2.9 5.4" }),
1822
+ /* @__PURE__ */ jsx14("path", { d: "M14.5 14.6a3.5 3.5 0 0 1-2.9 5.4H8" }),
1823
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "12", x2: "20", y2: "12" })
1824
+ ] }),
1825
+ subscriptControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1826
+ /* @__PURE__ */ jsx14("path", { d: "m4 4 8 9" }),
1827
+ /* @__PURE__ */ jsx14("path", { d: "m12 4-8 9" }),
1828
+ /* @__PURE__ */ jsx14("path", { d: "M19 16h-3.5c0-1.6 3.5-1.9 3.5-3.8a1.8 1.8 0 0 0-3.3-1" })
1829
+ ] }),
1830
+ superscriptControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1831
+ /* @__PURE__ */ jsx14("path", { d: "m4 20 8-9" }),
1832
+ /* @__PURE__ */ jsx14("path", { d: "m12 20-8-9" }),
1833
+ /* @__PURE__ */ jsx14("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" })
1834
+ ] }),
1835
+ underlineControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1836
+ /* @__PURE__ */ jsx14("path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }),
1837
+ /* @__PURE__ */ jsx14("line", { x1: "4", y1: "20", x2: "20", y2: "20" })
1838
+ ] }),
1839
+ undoControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1840
+ /* @__PURE__ */ jsx14("path", { d: "M9 14 4 9l5-5" }),
1841
+ /* @__PURE__ */ jsx14("path", { d: "M4 9h10.5a5.5 5.5 0 0 1 0 11H11" })
1842
+ ] }),
1843
+ unlinkControlIcon: /* @__PURE__ */ jsxs8(Svg2, { ...iconProps, children: [
1844
+ /* @__PURE__ */ jsx14("path", { d: "M9 17H7a5 5 0 0 1-1.7-9.7" }),
1845
+ /* @__PURE__ */ jsx14("path", { d: "M15 7h2a5 5 0 0 1 1.7 9.7" }),
1846
+ /* @__PURE__ */ jsx14("line", { x1: "3", y1: "3", x2: "21", y2: "21" })
1847
+ ] })
1848
+ };
1849
+
1850
+ // src/labels.ts
1851
+ var DEFAULT_LABELS = {
1852
+ alignCenterControlLabel: "Align center",
1853
+ alignJustifyControlLabel: "Align justify",
1854
+ alignLeftControlLabel: "Align left",
1855
+ alignRightControlLabel: "Align right",
1856
+ blockquoteControlLabel: "Blockquote",
1857
+ boldControlLabel: "Bold",
1858
+ bulletListControlLabel: "Bullet list",
1859
+ clearFormattingControlLabel: "Clear formatting",
1860
+ codeBlockControlLabel: "Code block",
1861
+ codeControlLabel: "Code",
1862
+ h1ControlLabel: "Heading 1",
1863
+ h2ControlLabel: "Heading 2",
1864
+ h3ControlLabel: "Heading 3",
1865
+ h4ControlLabel: "Heading 4",
1866
+ h5ControlLabel: "Heading 5",
1867
+ h6ControlLabel: "Heading 6",
1868
+ highlightControlLabel: "Highlight",
1869
+ hrControlLabel: "Horizontal rule",
1870
+ italicControlLabel: "Italic",
1871
+ linkControlLabel: "Link",
1872
+ linkEditorExternalLink: "Open in new tab",
1873
+ linkEditorInputLabel: "Enter URL",
1874
+ linkEditorInputPlaceholder: "https://example.com",
1875
+ linkEditorInternalLink: "Open in same tab",
1876
+ linkEditorSave: "Save",
1877
+ orderedListControlLabel: "Ordered list",
1878
+ redoControlLabel: "Redo",
1879
+ sourceCodeControlLabel: "Source code",
1880
+ strikeControlLabel: "Strikethrough",
1881
+ subscriptControlLabel: "Subscript",
1882
+ superscriptControlLabel: "Superscript",
1883
+ tasksControlLabel: "Task list",
1884
+ tasksLiftLabel: "Increase task level",
1885
+ tasksSinkLabel: "Decrease task level",
1886
+ underlineControlLabel: "Underline",
1887
+ undoControlLabel: "Undo",
1888
+ unlinkControlLabel: "Remove link"
1889
+ };
1890
+
1891
+ // src/rte-content.tsx
1892
+ import { EditorContent } from "@tiptap/react";
1893
+ import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
1894
+ var Content = ({
1895
+ children,
1896
+ className
1897
+ }) => {
1898
+ const { editor } = useRichTextEditorContext();
1899
+ return /* @__PURE__ */ jsxs9("div", { className: "relative", children: [
1900
+ /* @__PURE__ */ jsx15(
1901
+ EditorContent,
1902
+ {
1903
+ editor,
1904
+ className: cn("rte-content w-full", className)
1905
+ }
1906
+ ),
1907
+ children
1908
+ ] });
1909
+ };
1910
+
1911
+ // src/rte-controls-group.tsx
1912
+ import { jsx as jsx16 } from "react/jsx-runtime";
1913
+ var ControlsGroup = ({
1914
+ children,
1915
+ className
1916
+ }) => /* @__PURE__ */ jsx16("div", { className: cn("rte-controls-group", className), children });
1917
+
1918
+ // src/rte-footer.tsx
1919
+ import { useEffect as useEffect4, useMemo, useRef as useRef4, useState as useState5 } from "react";
1920
+ import { jsx as jsx17, jsxs as jsxs10 } from "react/jsx-runtime";
1921
+ var Footer = ({
1922
+ children,
1923
+ className,
1924
+ sticky = false,
1925
+ stickyOffset = 0,
1926
+ showWordCount = false,
1927
+ wordCountClassName,
1928
+ wordCountFormatter
1929
+ }) => {
1930
+ const { editor, variant } = useRichTextEditorContext();
1931
+ const [, forceUpdate] = useState5(0);
1932
+ const rafRef = useRef4(null);
1357
1933
  useEffect4(() => {
1358
- if (!containerRef.current || !tweetId) return;
1359
- if (window.twttr?.widgets) {
1360
- renderTweet();
1361
- } else {
1362
- const script = document.createElement("script");
1363
- script.src = WIDGET_SCRIPT_URL;
1364
- script.async = true;
1365
- script.onload = renderTweet;
1366
- document.body.appendChild(script);
1934
+ if (!editor || !showWordCount) {
1935
+ return;
1367
1936
  }
1368
- }, [tweetId, w, h, renderTweet]);
1369
- return /* @__PURE__ */ jsxs8(ResizableNodeView, { ...props, lockAspect: false, minWidth: 300, maxWidth: 1200, children: [
1370
- loading && /* @__PURE__ */ jsx15("div", { className: "rte-embed-loading", children: "Loading tweet..." }),
1371
- /* @__PURE__ */ jsx15("div", { ref: containerRef })
1372
- ] });
1373
- }
1374
- var TwitterEmbed = Node2.create({
1375
- name: "twitter",
1376
- group: "block",
1377
- atom: true,
1378
- draggable: true,
1379
- addAttributes() {
1380
- return {
1381
- tweetId: {
1382
- default: null,
1383
- parseHTML: (el) => el.getAttribute("data-tweet-id"),
1384
- renderHTML: (attrs) => ({
1385
- "data-tweet-id": attrs.tweetId
1386
- })
1387
- },
1388
- width: {
1389
- default: 550,
1390
- parseHTML: (el) => el.getAttribute("data-width") ? Number(el.getAttribute("data-width")) : 550,
1391
- renderHTML: (attrs) => ({
1392
- "data-width": attrs.width
1393
- })
1394
- },
1395
- height: {
1396
- default: 400,
1397
- parseHTML: (el) => el.getAttribute("data-height") ? Number(el.getAttribute("data-height")) : 400,
1398
- renderHTML: (attrs) => ({
1399
- "data-height": attrs.height
1400
- })
1401
- },
1402
- align: {
1403
- default: "center",
1404
- parseHTML: (el) => el.getAttribute("data-align") || "center",
1405
- renderHTML: (attrs) => ({
1406
- "data-align": attrs.align
1407
- })
1937
+ const scheduleUpdate = () => {
1938
+ if (rafRef.current !== null) {
1939
+ return;
1408
1940
  }
1941
+ rafRef.current = requestAnimationFrame(() => {
1942
+ rafRef.current = null;
1943
+ forceUpdate((t) => t + 1);
1944
+ });
1409
1945
  };
1410
- },
1411
- parseHTML() {
1412
- return [{ tag: 'div[data-type="twitter"]' }];
1413
- },
1414
- renderHTML({ node }) {
1415
- return [
1416
- "div",
1417
- {
1418
- "data-type": "twitter",
1419
- "data-tweet-id": node.attrs.tweetId,
1420
- "data-width": node.attrs.width,
1421
- "data-height": node.attrs.height,
1422
- "data-align": node.attrs.align
1946
+ const handleTransaction = ({
1947
+ transaction
1948
+ }) => {
1949
+ if (transaction.docChanged) {
1950
+ scheduleUpdate();
1423
1951
  }
1424
- ];
1425
- },
1426
- addNodeView() {
1427
- return ReactNodeViewRenderer2(TwitterNodeView);
1428
- },
1429
- addCommands() {
1430
- return {
1431
- setTwitterEmbed: (tweetId) => ({ commands }) => {
1432
- return commands.insertContent({
1433
- type: "twitter",
1434
- attrs: { tweetId }
1435
- });
1952
+ };
1953
+ editor.on("transaction", handleTransaction);
1954
+ scheduleUpdate();
1955
+ return () => {
1956
+ editor.off("transaction", handleTransaction);
1957
+ if (rafRef.current !== null) {
1958
+ cancelAnimationFrame(rafRef.current);
1436
1959
  }
1437
1960
  };
1438
- },
1439
- addInputRules() {
1440
- return [
1441
- nodeInputRule2({
1442
- find: /https?:\/\/(?:www\.)?(?:twitter\.com|x\.com)\/\w+\/status\/(\d+)/,
1443
- type: this.type,
1444
- getAttributes: (match) => ({ tweetId: match[1] })
1445
- })
1446
- ];
1961
+ }, [editor, showWordCount]);
1962
+ const wordCount = useMemo(() => {
1963
+ if (!editor || !showWordCount) {
1964
+ return null;
1965
+ }
1966
+ const count = editor.storage.characterCount;
1967
+ const words = count?.words() ?? 0;
1968
+ const characters = count?.characters() ?? 0;
1969
+ return wordCountFormatter ? wordCountFormatter({ characters, words }) : `${words} words | ${characters} characters`;
1970
+ }, [
1971
+ editor,
1972
+ showWordCount,
1973
+ wordCountFormatter,
1974
+ editor?.state.doc.content.size
1975
+ ]);
1976
+ if (!showWordCount && !children) {
1977
+ return null;
1447
1978
  }
1448
- });
1449
- function extractTweetId(input) {
1450
- const clean = input.trim();
1451
- const match = clean.match(/(?:twitter\.com|x\.com)\/(?:\w+\/status\/|i\/web\/status\/)(\d+)/);
1452
- return match ? match[1] ?? null : /^\d+$/.test(clean) ? clean : null;
1453
- }
1454
- function TwitterEmbedControl({ className }) {
1455
- const { editor } = useRichTextEditorContext();
1456
- const [open, setOpen] = useState4(false);
1457
- const [url, setUrl] = useState4("");
1458
- const { active } = useEditorState4({
1459
- editor: editor ?? null,
1460
- selector: (ctx) => ({
1461
- active: ctx.editor && !ctx.editor.isDestroyed ? ctx.editor.isActive("twitter") : false
1462
- })
1463
- }) ?? { active: false };
1464
- const handleInsert = useCallback3(() => {
1465
- if (url && editor) {
1466
- const tweetId = extractTweetId(url);
1467
- if (tweetId) {
1468
- editor.chain().focus().setTwitterEmbed(tweetId).run();
1469
- setUrl("");
1470
- }
1979
+ return /* @__PURE__ */ jsxs10(
1980
+ "div",
1981
+ {
1982
+ className: cn(
1983
+ "rte-footer",
1984
+ variant !== "default" && `rte-footer--${variant}`,
1985
+ sticky && "sticky z-10",
1986
+ className
1987
+ ),
1988
+ "data-sticky": sticky ? "" : void 0,
1989
+ style: sticky ? { bottom: stickyOffset } : void 0,
1990
+ children: [
1991
+ showWordCount && wordCount && /* @__PURE__ */ jsx17("span", { className: cn("rte-footer-word-count", wordCountClassName), children: wordCount }),
1992
+ children
1993
+ ]
1471
1994
  }
1472
- }, [url, editor]);
1473
- return /* @__PURE__ */ jsxs8(Dialog, { open, onOpenChange: setOpen, children: [
1474
- /* @__PURE__ */ jsx15(
1475
- DialogTrigger,
1476
- {
1477
- render: /* @__PURE__ */ jsx15(
1478
- RichTextEditorControl,
1479
- {
1480
- active,
1481
- className,
1482
- title: "Embed Tweet",
1483
- "aria-label": "Embed Tweet",
1484
- children: /* @__PURE__ */ jsx15(
1485
- "svg",
1486
- {
1487
- xmlns: "http://www.w3.org/2000/svg",
1488
- viewBox: "0 0 24 24",
1489
- fill: "currentColor",
1490
- className: "rte-editor-icon",
1491
- children: /* @__PURE__ */ jsx15("path", { d: "M18.2 3.2h3.3l-7.2 8.2 8.5 11.2h-6.6l-5.2-6.8-6 6.8H2.7l7.7-8.8L2.3 3.2h6.8l4.7 6.2 5.4-6.2zm-1.2 17.3h1.8L7 4.8H5.1l11.9 15.7z" })
1492
- }
1493
- )
1494
- }
1495
- )
1496
- }
1497
- ),
1498
- /* @__PURE__ */ jsxs8(DialogContent, { children: [
1499
- /* @__PURE__ */ jsxs8(DialogHeader, { children: [
1500
- /* @__PURE__ */ jsx15(DialogTitle, { children: "Embed Tweet" }),
1501
- /* @__PURE__ */ jsx15(DialogDescription, { children: "Paste a tweet URL or ID." })
1502
- ] }),
1503
- /* @__PURE__ */ jsx15(
1504
- Input,
1505
- {
1506
- value: url,
1507
- onChange: (e) => setUrl(e.target.value),
1508
- placeholder: "https://x.com/user/status/...",
1509
- onKeyDown: (e) => {
1510
- if (e.key === "Enter" && url) {
1511
- handleInsert();
1512
- setOpen(false);
1513
- }
1514
- }
1515
- }
1995
+ );
1996
+ };
1997
+
1998
+ // src/rte-toolbar.tsx
1999
+ import { jsx as jsx18 } from "react/jsx-runtime";
2000
+ var Toolbar = ({
2001
+ children,
2002
+ className,
2003
+ sticky,
2004
+ stickyOffset = 0
2005
+ }) => {
2006
+ const { variant, editable } = useRichTextEditorContext();
2007
+ if (!editable) {
2008
+ return null;
2009
+ }
2010
+ return /* @__PURE__ */ jsx18(
2011
+ "div",
2012
+ {
2013
+ className: cn(
2014
+ "rte-toolbar",
2015
+ variant !== "default" && `rte-toolbar--${variant}`,
2016
+ sticky && "sticky z-10",
2017
+ className
1516
2018
  ),
1517
- /* @__PURE__ */ jsxs8(DialogFooter, { children: [
1518
- /* @__PURE__ */ jsx15(DialogClose, { children: "Cancel" }),
1519
- /* @__PURE__ */ jsx15(
1520
- DialogClose,
1521
- {
1522
- disabled: !url,
1523
- className: "rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-50",
1524
- onClick: handleInsert,
1525
- children: "Insert"
1526
- }
1527
- )
1528
- ] })
1529
- ] })
1530
- ] });
1531
- }
2019
+ "data-sticky": sticky ? "" : void 0,
2020
+ style: sticky ? { top: stickyOffset } : void 0,
2021
+ children
2022
+ }
2023
+ );
2024
+ };
1532
2025
 
1533
2026
  // src/rte-text-editor.tsx
1534
- import { jsx as jsx16 } from "react/jsx-runtime";
1535
- function RichTextEditorRoot({
2027
+ import { jsx as jsx19 } from "react/jsx-runtime";
2028
+ var RichTextEditorRoot = ({
1536
2029
  editor,
1537
2030
  children,
1538
2031
  className,
@@ -1540,69 +2033,79 @@ function RichTextEditorRoot({
1540
2033
  icons,
1541
2034
  variant = "default",
1542
2035
  editable = true
1543
- }) {
2036
+ }) => {
1544
2037
  const mergedLabels = useMemo2(
1545
2038
  () => ({ ...DEFAULT_LABELS, ...labels }),
1546
2039
  [labels]
1547
2040
  );
1548
- const mergedIcons = useMemo2(
1549
- () => ({ ...DEFAULT_ICONS, ...icons }),
1550
- [icons]
1551
- );
2041
+ const mergedIcons = useMemo2(() => ({ ...DEFAULT_ICONS, ...icons }), [icons]);
1552
2042
  useEffect5(() => {
1553
2043
  if (editor && editor.isEditable !== editable) {
1554
2044
  editor.setEditable(editable);
1555
2045
  }
1556
2046
  }, [editor, editable]);
1557
- return /* @__PURE__ */ jsx16(RichTextEditorContext.Provider, { value: { editor, labels: mergedLabels, icons: mergedIcons, variant, editable }, children: /* @__PURE__ */ jsx16(
1558
- "div",
2047
+ return /* @__PURE__ */ jsx19(
2048
+ RichTextEditorContext.Provider,
1559
2049
  {
1560
- className: cn(
1561
- "rte-root",
1562
- variant !== "default" && `rte-root--${variant}`,
1563
- className
1564
- ),
1565
- "data-variant": variant,
1566
- children
2050
+ value: {
2051
+ editable,
2052
+ editor,
2053
+ icons: mergedIcons,
2054
+ labels: mergedLabels,
2055
+ variant
2056
+ },
2057
+ children: /* @__PURE__ */ jsx19(
2058
+ "div",
2059
+ {
2060
+ className: cn(
2061
+ "rte-root",
2062
+ variant !== "default" && `rte-root--${variant}`,
2063
+ className
2064
+ ),
2065
+ "data-variant": variant,
2066
+ children
2067
+ }
2068
+ )
1567
2069
  }
1568
- ) });
1569
- }
2070
+ );
2071
+ };
1570
2072
  var RichTextEditor = Object.assign(RichTextEditorRoot, {
1571
- Toolbar,
1572
- Footer,
1573
- ControlsGroup,
1574
- Content,
1575
- Control: RichTextEditorControl,
1576
- Link: LinkControl,
1577
- YouTubeEmbed: YouTubeEmbedControl,
1578
- TwitterEmbed: TwitterEmbedControl,
2073
+ AlignCenter: AlignCenterControl,
2074
+ AlignJustify: AlignJustifyControl,
2075
+ AlignLeft: AlignLeftControl,
2076
+ AlignRight: AlignRightControl,
2077
+ Blockquote: BlockquoteControl,
1579
2078
  Bold: BoldControl,
1580
- Italic: ItalicControl,
1581
- Underline: UnderlineControl,
1582
- Strikethrough: StrikethroughControl,
2079
+ BubbleMenu,
2080
+ BulletList: BulletListControl,
1583
2081
  ClearFormatting: ClearFormattingControl,
1584
2082
  Code: CodeControl,
1585
2083
  CodeBlock: CodeBlockControl,
2084
+ Content,
2085
+ Control: RichTextEditorControl,
2086
+ ControlsGroup,
2087
+ Footer,
1586
2088
  H1: H1Control,
1587
2089
  H2: H2Control,
1588
2090
  H3: H3Control,
1589
2091
  H4: H4Control,
1590
2092
  H5: H5Control,
1591
2093
  H6: H6Control,
1592
- BulletList: BulletListControl,
1593
- OrderedList: OrderedListControl,
1594
- Blockquote: BlockquoteControl,
2094
+ Highlight: HighlightControl,
1595
2095
  Hr: HrControl,
1596
- Unlink: UnlinkControl,
1597
- Undo: UndoControl,
2096
+ Italic: ItalicControl,
2097
+ Link: LinkControl,
2098
+ OrderedList: OrderedListControl,
1598
2099
  Redo: RedoControl,
1599
- AlignLeft: AlignLeftControl,
1600
- AlignCenter: AlignCenterControl,
1601
- AlignRight: AlignRightControl,
1602
- AlignJustify: AlignJustifyControl,
1603
- Highlight: HighlightControl,
2100
+ Strikethrough: StrikethroughControl,
1604
2101
  Subscript: SubscriptControl,
1605
- Superscript: SuperscriptControl
2102
+ Superscript: SuperscriptControl,
2103
+ Toolbar,
2104
+ TwitterEmbed: TwitterEmbedControl,
2105
+ Underline: UnderlineControl,
2106
+ Undo: UndoControl,
2107
+ Unlink: UnlinkControl,
2108
+ YouTubeEmbed: YouTubeEmbedControl
1606
2109
  });
1607
2110
 
1608
2111
  // src/extensions/link.ts
@@ -1617,9 +2120,21 @@ var Link = TipTapLink.extend({
1617
2120
  };
1618
2121
  }
1619
2122
  }).configure({ openOnClick: false });
2123
+
2124
+ // src/extensions/code-block.ts
2125
+ import LowlightCodeBlock from "@tiptap/extension-code-block-lowlight";
2126
+ import { common, createLowlight } from "lowlight";
2127
+ var lowlight = createLowlight(common);
2128
+ var CodeBlock = LowlightCodeBlock.configure({
2129
+ defaultLanguage: "javascript",
2130
+ lowlight
2131
+ });
1620
2132
  export {
2133
+ BubbleMenu,
2134
+ CodeBlock,
1621
2135
  DEFAULT_ICONS,
1622
2136
  DEFAULT_LABELS,
2137
+ DEFAULT_LANGUAGE_ICONS,
1623
2138
  Link,
1624
2139
  RichTextEditor,
1625
2140
  TwitterEmbed,