@editorcn/editor 0.1.2 → 0.3.0

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