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