@editorcn/editor 0.2.0 → 0.3.0

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