@editorcn/editor 0.2.0 → 0.3.1

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