@editorcn/editor 0.2.0 → 0.3.1

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