@editorcn/editor 0.1.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 ADDED
@@ -0,0 +1,1598 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ DEFAULT_ICONS: () => DEFAULT_ICONS,
34
+ DEFAULT_LABELS: () => DEFAULT_LABELS,
35
+ Link: () => Link,
36
+ RichTextEditor: () => RichTextEditor,
37
+ TwitterEmbed: () => TwitterEmbed,
38
+ YouTubeEmbed: () => YouTubeEmbed,
39
+ useRichTextEditorContext: () => useRichTextEditorContext
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+
43
+ // src/rte-text-editor.tsx
44
+ var import_react15 = require("react");
45
+
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
+ }
52
+
53
+ // 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);
59
+ if (!context) {
60
+ throw new Error(
61
+ "useRichTextEditorContext must be used within RichTextEditor"
62
+ );
63
+ }
64
+ return context;
65
+ }
66
+
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"
106
+ };
107
+
108
+ // src/icons.tsx
109
+ var import_react3 = require("react");
110
+ 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
+ }
128
+ );
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
+ ] })
279
+ };
280
+
281
+ // src/rte-toolbar.tsx
282
+ var import_jsx_runtime2 = require("react/jsx-runtime");
283
+ function Toolbar({
284
+ 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
+ }
304
+ );
305
+ }
306
+
307
+ // src/rte-controls-group.tsx
308
+ var import_jsx_runtime3 = require("react/jsx-runtime");
309
+ function ControlsGroup({
310
+ children,
311
+ className
312
+ }) {
313
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
314
+ "div",
315
+ {
316
+ className: cn("rte-controls-group", className),
317
+ children
318
+ }
319
+ );
320
+ }
321
+
322
+ // src/rte-content.tsx
323
+ var import_react4 = require("@tiptap/react");
324
+ var import_jsx_runtime4 = require("react/jsx-runtime");
325
+ function Content({ children, className }) {
326
+ const { editor } = useRichTextEditorContext();
327
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "relative", children: [
328
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
329
+ import_react4.EditorContent,
330
+ {
331
+ editor,
332
+ className: cn("rte-content w-full", className)
333
+ }
334
+ ),
335
+ children
336
+ ] });
337
+ }
338
+
339
+ // src/controls/rte-control.tsx
340
+ var import_react5 = require("@tiptap/react");
341
+ var import_react6 = require("react");
342
+
343
+ // src/ui/toggle.tsx
344
+ var import_toggle = require("@base-ui/react/toggle");
345
+ var import_class_variance_authority = require("class-variance-authority");
346
+ var import_jsx_runtime5 = require("react/jsx-runtime");
347
+ var toggleVariants = (0, import_class_variance_authority.cva)(
348
+ "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",
349
+ {
350
+ variants: {
351
+ variant: {
352
+ default: "bg-transparent",
353
+ outline: "border border-input bg-transparent hover:bg-muted"
354
+ },
355
+ size: {
356
+ default: "h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
357
+ 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",
358
+ lg: "h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2"
359
+ }
360
+ },
361
+ defaultVariants: {
362
+ variant: "default",
363
+ size: "default"
364
+ }
365
+ }
366
+ );
367
+ function Toggle({
368
+ className,
369
+ variant = "default",
370
+ size = "default",
371
+ ...props
372
+ }) {
373
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
374
+ import_toggle.Toggle,
375
+ {
376
+ "data-slot": "toggle",
377
+ className: cn(toggleVariants({ variant, size, className })),
378
+ ...props
379
+ }
380
+ );
381
+ }
382
+
383
+ // src/controls/rte-control.tsx
384
+ var import_jsx_runtime6 = require("react/jsx-runtime");
385
+ function RichTextEditorControl({
386
+ active,
387
+ interactive = true,
388
+ className,
389
+ children,
390
+ onMouseDown,
391
+ onClick,
392
+ disabled,
393
+ ...props
394
+ }) {
395
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
396
+ Toggle,
397
+ {
398
+ size: "sm",
399
+ pressed: active,
400
+ disabled,
401
+ "aria-label": props["aria-label"],
402
+ title: props.title,
403
+ className: cn("rte-control-button", className),
404
+ onMouseDown: (e) => {
405
+ e.preventDefault();
406
+ onMouseDown?.(e);
407
+ },
408
+ onPressedChange: () => onClick?.({}),
409
+ children
410
+ }
411
+ );
412
+ }
413
+ function createControl({
414
+ label,
415
+ iconKey,
416
+ isActive,
417
+ isDisabled,
418
+ operation
419
+ }) {
420
+ function Control({ className }) {
421
+ const { editor, labels, icons } = useRichTextEditorContext();
422
+ const ariaLabel = labels[label];
423
+ const editorState = (0, import_react5.useEditorState)({
424
+ editor: editor ?? null,
425
+ selector: (ctx) => {
426
+ const safeEditor = ctx.editor && !ctx.editor.isDestroyed ? ctx.editor : null;
427
+ const checkIsActive = () => {
428
+ if (!safeEditor || !isActive) return false;
429
+ if ("attrs" in isActive) return safeEditor.isActive(isActive.attrs);
430
+ return safeEditor.isActive(isActive.name, isActive.attributes);
431
+ };
432
+ return {
433
+ active: checkIsActive(),
434
+ disabled: safeEditor ? isDisabled?.(safeEditor) ?? false : true
435
+ };
436
+ }
437
+ });
438
+ const active = editorState?.active ?? false;
439
+ const disabled = editorState?.disabled ?? true;
440
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
441
+ RichTextEditorControl,
442
+ {
443
+ active,
444
+ disabled,
445
+ "aria-label": ariaLabel,
446
+ title: ariaLabel,
447
+ className,
448
+ onClick: () => {
449
+ if (!editor || editor.isDestroyed) {
450
+ return;
451
+ }
452
+ editor.chain().focus()[operation.name](operation.attributes).run();
453
+ },
454
+ children: icons[iconKey]
455
+ }
456
+ );
457
+ }
458
+ Control.displayName = `RichTextEditor.${String(label)}`;
459
+ return Control;
460
+ }
461
+
462
+ // src/controls/rte-link-control.tsx
463
+ var React5 = __toESM(require("react"), 1);
464
+ var import_react7 = require("react");
465
+ var import_react8 = require("@tiptap/react");
466
+
467
+ // src/ui/popover.tsx
468
+ var React3 = require("react");
469
+ var import_popover = require("@base-ui/react/popover");
470
+ var import_jsx_runtime7 = require("react/jsx-runtime");
471
+ function Popover({ ...props }) {
472
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_popover.Popover.Root, { "data-slot": "popover", ...props });
473
+ }
474
+ function PopoverTrigger({ ...props }) {
475
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_popover.Popover.Trigger, { "data-slot": "popover-trigger", ...props });
476
+ }
477
+ function PopoverContent({
478
+ className,
479
+ align = "center",
480
+ alignOffset = 0,
481
+ side = "bottom",
482
+ sideOffset = 4,
483
+ ...props
484
+ }) {
485
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_popover.Popover.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
486
+ import_popover.Popover.Positioner,
487
+ {
488
+ align,
489
+ alignOffset,
490
+ side,
491
+ sideOffset,
492
+ className: "isolate z-50",
493
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
494
+ import_popover.Popover.Popup,
495
+ {
496
+ "data-slot": "popover-content",
497
+ className: cn(
498
+ "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",
499
+ className
500
+ ),
501
+ ...props
502
+ }
503
+ )
504
+ }
505
+ ) });
506
+ }
507
+
508
+ // src/ui/input.tsx
509
+ var React4 = require("react");
510
+ var import_input = require("@base-ui/react/input");
511
+ var import_jsx_runtime8 = require("react/jsx-runtime");
512
+ function Input({ className, type, ...props }) {
513
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
514
+ import_input.Input,
515
+ {
516
+ type,
517
+ "data-slot": "input",
518
+ className: cn(
519
+ "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",
520
+ className
521
+ ),
522
+ ...props
523
+ }
524
+ );
525
+ }
526
+
527
+ // src/ui/button.tsx
528
+ var import_button = require("@base-ui/react/button");
529
+ var import_class_variance_authority2 = require("class-variance-authority");
530
+ var import_jsx_runtime9 = require("react/jsx-runtime");
531
+ var buttonVariants = (0, import_class_variance_authority2.cva)(
532
+ "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",
533
+ {
534
+ variants: {
535
+ variant: {
536
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
537
+ 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",
538
+ 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",
539
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
540
+ 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",
541
+ link: "text-primary underline-offset-4 hover:underline"
542
+ },
543
+ size: {
544
+ default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
545
+ 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",
546
+ 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",
547
+ lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
548
+ icon: "size-8",
549
+ "icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
550
+ "icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
551
+ "icon-lg": "size-9"
552
+ }
553
+ },
554
+ defaultVariants: {
555
+ variant: "default",
556
+ size: "default"
557
+ }
558
+ }
559
+ );
560
+ function Button({
561
+ className,
562
+ variant = "default",
563
+ size = "default",
564
+ ...props
565
+ }) {
566
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
567
+ import_button.Button,
568
+ {
569
+ "data-slot": "button",
570
+ className: cn(buttonVariants({ variant, size, className })),
571
+ ...props
572
+ }
573
+ );
574
+ }
575
+
576
+ // src/controls/rte-link-control.tsx
577
+ var import_jsx_runtime10 = require("react/jsx-runtime");
578
+ function LinkControl() {
579
+ const { editor, labels, icons } = useRichTextEditorContext();
580
+ const [url, setUrl] = (0, import_react7.useState)("");
581
+ const [open, setOpen] = (0, import_react7.useState)(false);
582
+ const active = (0, import_react8.useEditorState)({
583
+ editor: editor ?? null,
584
+ selector: (ctx) => ctx.editor && !ctx.editor.isDestroyed ? ctx.editor.isActive("link") : false
585
+ });
586
+ const handleOpen = (isOpen) => {
587
+ if (isOpen) {
588
+ const linkData = editor?.getAttributes("link");
589
+ setUrl(linkData?.href || "");
590
+ } else {
591
+ setUrl("");
592
+ }
593
+ setOpen(isOpen);
594
+ };
595
+ const handleSave = () => {
596
+ if (!editor || editor.isDestroyed) return;
597
+ if (url === "") {
598
+ editor.chain().focus().extendMarkRange("link").unsetLink().run();
599
+ } else {
600
+ editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
601
+ }
602
+ setOpen(false);
603
+ setUrl("");
604
+ };
605
+ const handleKeyDown = (e) => {
606
+ if (e.key === "Enter") {
607
+ e.preventDefault();
608
+ handleSave();
609
+ }
610
+ };
611
+ React5.useEffect(() => {
612
+ const handler = () => handleOpen(true);
613
+ window.addEventListener("edit-link", handler);
614
+ return () => window.removeEventListener("edit-link", handler);
615
+ }, [editor]);
616
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Popover, { open, onOpenChange: handleOpen, children: [
617
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
618
+ PopoverTrigger,
619
+ {
620
+ onMouseDown: (e) => e.preventDefault(),
621
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
622
+ Toggle,
623
+ {
624
+ size: "sm",
625
+ pressed: active ?? false,
626
+ "aria-label": labels.linkControlLabel,
627
+ title: labels.linkControlLabel,
628
+ className: "p-0",
629
+ children: icons.linkControlIcon
630
+ }
631
+ )
632
+ }
633
+ ),
634
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PopoverContent, { className: "w-72 p-3", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "rte-link-editor", children: [
635
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
636
+ Input,
637
+ {
638
+ type: "url",
639
+ placeholder: labels.linkEditorInputPlaceholder,
640
+ "aria-label": labels.linkEditorInputLabel,
641
+ value: url,
642
+ onChange: (e) => setUrl(e.target.value),
643
+ onKeyDown: handleKeyDown,
644
+ className: "rte-link-editor-input h-8 text-sm"
645
+ }
646
+ ),
647
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
648
+ Button,
649
+ {
650
+ size: "sm",
651
+ variant: "default",
652
+ onClick: handleSave,
653
+ className: "rte-link-editor-save h-8",
654
+ children: labels.linkEditorSave
655
+ }
656
+ )
657
+ ] }) })
658
+ ] });
659
+ }
660
+
661
+ // src/controls/rte-controls.tsx
662
+ var BoldControl = createControl({
663
+ label: "boldControlLabel",
664
+ iconKey: "boldControlIcon",
665
+ isActive: { name: "bold" },
666
+ operation: { name: "toggleBold" }
667
+ });
668
+ var ItalicControl = createControl({
669
+ label: "italicControlLabel",
670
+ iconKey: "italicControlIcon",
671
+ isActive: { name: "italic" },
672
+ operation: { name: "toggleItalic" }
673
+ });
674
+ var UnderlineControl = createControl({
675
+ label: "underlineControlLabel",
676
+ iconKey: "underlineControlIcon",
677
+ isActive: { name: "underline" },
678
+ operation: { name: "toggleUnderline" }
679
+ });
680
+ var StrikethroughControl = createControl({
681
+ label: "strikeControlLabel",
682
+ iconKey: "strikeControlIcon",
683
+ isActive: { name: "strike" },
684
+ operation: { name: "toggleStrike" }
685
+ });
686
+ var ClearFormattingControl = createControl({
687
+ label: "clearFormattingControlLabel",
688
+ iconKey: "clearFormattingControlIcon",
689
+ operation: { name: "unsetAllMarks" }
690
+ });
691
+ var CodeControl = createControl({
692
+ label: "codeControlLabel",
693
+ iconKey: "codeControlIcon",
694
+ isActive: { name: "code" },
695
+ operation: { name: "toggleCode" }
696
+ });
697
+ var CodeBlockControl = createControl({
698
+ label: "codeBlockControlLabel",
699
+ iconKey: "codeBlockControlIcon",
700
+ isActive: { name: "codeBlock" },
701
+ operation: { name: "toggleCodeBlock" }
702
+ });
703
+ var H1Control = createControl({
704
+ label: "h1ControlLabel",
705
+ iconKey: "h1ControlIcon",
706
+ isActive: { name: "heading", attributes: { level: 1 } },
707
+ operation: { name: "toggleHeading", attributes: { level: 1 } }
708
+ });
709
+ var H2Control = createControl({
710
+ label: "h2ControlLabel",
711
+ iconKey: "h2ControlIcon",
712
+ isActive: { name: "heading", attributes: { level: 2 } },
713
+ operation: { name: "toggleHeading", attributes: { level: 2 } }
714
+ });
715
+ var H3Control = createControl({
716
+ label: "h3ControlLabel",
717
+ iconKey: "h3ControlIcon",
718
+ isActive: { name: "heading", attributes: { level: 3 } },
719
+ operation: { name: "toggleHeading", attributes: { level: 3 } }
720
+ });
721
+ var H4Control = createControl({
722
+ label: "h4ControlLabel",
723
+ iconKey: "h4ControlIcon",
724
+ isActive: { name: "heading", attributes: { level: 4 } },
725
+ operation: { name: "toggleHeading", attributes: { level: 4 } }
726
+ });
727
+ var BulletListControl = createControl({
728
+ label: "bulletListControlLabel",
729
+ iconKey: "bulletListControlIcon",
730
+ isActive: { name: "bulletList" },
731
+ operation: { name: "toggleBulletList" }
732
+ });
733
+ var OrderedListControl = createControl({
734
+ label: "orderedListControlLabel",
735
+ iconKey: "orderedListControlIcon",
736
+ isActive: { name: "orderedList" },
737
+ operation: { name: "toggleOrderedList" }
738
+ });
739
+ var BlockquoteControl = createControl({
740
+ label: "blockquoteControlLabel",
741
+ iconKey: "blockquoteControlIcon",
742
+ isActive: { name: "blockquote" },
743
+ operation: { name: "toggleBlockquote" }
744
+ });
745
+ var HrControl = createControl({
746
+ label: "hrControlLabel",
747
+ iconKey: "hrControlIcon",
748
+ operation: { name: "setHorizontalRule" }
749
+ });
750
+ var UnlinkControl = createControl({
751
+ label: "unlinkControlLabel",
752
+ iconKey: "unlinkControlIcon",
753
+ operation: { name: "unsetLink" }
754
+ });
755
+ var UndoControl = createControl({
756
+ label: "undoControlLabel",
757
+ iconKey: "undoControlIcon",
758
+ isDisabled: (editor) => !editor.can().undo(),
759
+ operation: { name: "undo" }
760
+ });
761
+ var RedoControl = createControl({
762
+ label: "redoControlLabel",
763
+ iconKey: "redoControlIcon",
764
+ isDisabled: (editor) => !editor.can().redo(),
765
+ operation: { name: "redo" }
766
+ });
767
+ var H5Control = createControl({
768
+ label: "h5ControlLabel",
769
+ iconKey: "h5ControlIcon",
770
+ isActive: { name: "heading", attributes: { level: 5 } },
771
+ operation: { name: "toggleHeading", attributes: { level: 5 } }
772
+ });
773
+ var H6Control = createControl({
774
+ label: "h6ControlLabel",
775
+ iconKey: "h6ControlIcon",
776
+ isActive: { name: "heading", attributes: { level: 6 } },
777
+ operation: { name: "toggleHeading", attributes: { level: 6 } }
778
+ });
779
+ var AlignLeftControl = createControl({
780
+ label: "alignLeftControlLabel",
781
+ iconKey: "alignLeftControlIcon",
782
+ operation: { name: "setTextAlign", attributes: "left" }
783
+ });
784
+ var AlignCenterControl = createControl({
785
+ label: "alignCenterControlLabel",
786
+ iconKey: "alignCenterControlIcon",
787
+ isActive: { attrs: { textAlign: "center" } },
788
+ operation: { name: "setTextAlign", attributes: "center" }
789
+ });
790
+ var AlignRightControl = createControl({
791
+ label: "alignRightControlLabel",
792
+ iconKey: "alignRightControlIcon",
793
+ isActive: { attrs: { textAlign: "right" } },
794
+ operation: { name: "setTextAlign", attributes: "right" }
795
+ });
796
+ var AlignJustifyControl = createControl({
797
+ label: "alignJustifyControlLabel",
798
+ iconKey: "alignJustifyControlIcon",
799
+ isActive: { attrs: { textAlign: "justify" } },
800
+ operation: { name: "setTextAlign", attributes: "justify" }
801
+ });
802
+ var HighlightControl = createControl({
803
+ label: "highlightControlLabel",
804
+ iconKey: "highlightControlIcon",
805
+ isActive: { name: "highlight" },
806
+ operation: { name: "toggleHighlight" }
807
+ });
808
+ var SubscriptControl = createControl({
809
+ label: "subscriptControlLabel",
810
+ iconKey: "subscriptControlIcon",
811
+ isActive: { name: "subscript" },
812
+ operation: { name: "toggleSubscript" }
813
+ });
814
+ var SuperscriptControl = createControl({
815
+ label: "superscriptControlLabel",
816
+ iconKey: "superscriptControlIcon",
817
+ isActive: { name: "superscript" },
818
+ operation: { name: "toggleSuperscript" }
819
+ });
820
+
821
+ // src/controls/rte-youtube-control.tsx
822
+ var import_react11 = require("react");
823
+ var import_core = require("@tiptap/core");
824
+ var import_react12 = require("@tiptap/react");
825
+
826
+ // src/ui/dialog.tsx
827
+ var React6 = require("react");
828
+ var import_dialog = require("@base-ui/react/dialog");
829
+ var import_jsx_runtime11 = require("react/jsx-runtime");
830
+ function Dialog({ ...props }) {
831
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dialog.Dialog.Root, { "data-slot": "dialog", ...props });
832
+ }
833
+ function DialogTrigger({ ...props }) {
834
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dialog.Dialog.Trigger, { "data-slot": "dialog-trigger", ...props });
835
+ }
836
+ function DialogPortal({ ...props }) {
837
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dialog.Dialog.Portal, { "data-slot": "dialog-portal", ...props });
838
+ }
839
+ function DialogClose({ ...props }) {
840
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dialog.Dialog.Close, { "data-slot": "dialog-close", ...props });
841
+ }
842
+ function DialogOverlay({
843
+ className,
844
+ ...props
845
+ }) {
846
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
847
+ import_dialog.Dialog.Backdrop,
848
+ {
849
+ "data-slot": "dialog-overlay",
850
+ className: cn(
851
+ "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",
852
+ className
853
+ ),
854
+ ...props
855
+ }
856
+ );
857
+ }
858
+ function DialogContent({
859
+ className,
860
+ children,
861
+ showCloseButton = true,
862
+ ...props
863
+ }) {
864
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(DialogPortal, { children: [
865
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(DialogOverlay, {}),
866
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
867
+ import_dialog.Dialog.Popup,
868
+ {
869
+ "data-slot": "dialog-content",
870
+ className: cn(
871
+ "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",
872
+ className
873
+ ),
874
+ ...props,
875
+ children: [
876
+ children,
877
+ showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
878
+ import_dialog.Dialog.Close,
879
+ {
880
+ "data-slot": "dialog-close",
881
+ render: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
882
+ Button,
883
+ {
884
+ variant: "ghost",
885
+ className: "absolute top-2 right-2",
886
+ size: "icon-sm"
887
+ }
888
+ ),
889
+ children: [
890
+ "X",
891
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "sr-only", children: "Close" })
892
+ ]
893
+ }
894
+ )
895
+ ]
896
+ }
897
+ )
898
+ ] });
899
+ }
900
+ function DialogHeader({ className, ...props }) {
901
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
902
+ "div",
903
+ {
904
+ "data-slot": "dialog-header",
905
+ className: cn("flex flex-col gap-1 text-left", className),
906
+ ...props
907
+ }
908
+ );
909
+ }
910
+ function DialogFooter({
911
+ className,
912
+ showCloseButton = false,
913
+ children,
914
+ ...props
915
+ }) {
916
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
917
+ "div",
918
+ {
919
+ "data-slot": "dialog-footer",
920
+ className: cn(
921
+ "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
922
+ className
923
+ ),
924
+ ...props,
925
+ children: [
926
+ children,
927
+ showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dialog.Dialog.Close, { render: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Button, { variant: "outline" }), children: "Close" })
928
+ ]
929
+ }
930
+ );
931
+ }
932
+ function DialogTitle({ className, ...props }) {
933
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
934
+ import_dialog.Dialog.Title,
935
+ {
936
+ "data-slot": "dialog-title",
937
+ className: cn("text-sm font-medium", className),
938
+ ...props
939
+ }
940
+ );
941
+ }
942
+ function DialogDescription({
943
+ className,
944
+ ...props
945
+ }) {
946
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
947
+ import_dialog.Dialog.Description,
948
+ {
949
+ "data-slot": "dialog-description",
950
+ className: cn(
951
+ "text-xs/relaxed text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
952
+ className
953
+ ),
954
+ ...props
955
+ }
956
+ );
957
+ }
958
+
959
+ // src/extensions/resizable-node-view.tsx
960
+ var import_react9 = require("react");
961
+ var import_react10 = require("@tiptap/react");
962
+ var import_jsx_runtime12 = require("react/jsx-runtime");
963
+ function ResizableNodeView({
964
+ node,
965
+ selected,
966
+ updateAttributes,
967
+ view,
968
+ children,
969
+ lockAspect = false,
970
+ aspectRatio = 16 / 9,
971
+ minWidth = 300,
972
+ maxWidth = 1200
973
+ }) {
974
+ const containerRef = (0, import_react9.useRef)(null);
975
+ const resizingRef = (0, import_react9.useRef)(null);
976
+ const width = node.attrs.width;
977
+ const height = node.attrs.height;
978
+ const align = node.attrs.align || "center";
979
+ const getEditorWidth = (0, import_react9.useCallback)(() => {
980
+ return view?.dom?.parentElement?.offsetWidth ?? 0;
981
+ }, [view]);
982
+ const handleMouseDown = (0, import_react9.useCallback)(
983
+ (e, direction) => {
984
+ e.preventDefault();
985
+ e.stopPropagation();
986
+ const editorWidth = getEditorWidth();
987
+ const startWidth = containerRef.current?.offsetWidth ?? width ?? Math.min(560, editorWidth);
988
+ const startHeight = containerRef.current?.offsetHeight ?? height ?? 315;
989
+ resizingRef.current = {
990
+ direction,
991
+ startX: e.clientX,
992
+ startY: e.clientY,
993
+ startWidth,
994
+ startHeight,
995
+ editorWidth
996
+ };
997
+ document.addEventListener("mousemove", handleMouseMove);
998
+ document.addEventListener("mouseup", handleMouseUp);
999
+ document.body.style.cursor = direction === "right" ? "ew-resize" : direction === "bottom" ? "ns-resize" : "nwse-resize";
1000
+ document.body.style.userSelect = "none";
1001
+ },
1002
+ [width, height, getEditorWidth]
1003
+ );
1004
+ const handleMouseMove = (0, import_react9.useCallback)(
1005
+ (e) => {
1006
+ const resize = resizingRef.current;
1007
+ if (!resize) return;
1008
+ const effectiveMax = Math.min(maxWidth, resize.editorWidth);
1009
+ let newWidth = resize.startWidth;
1010
+ let newHeight = resize.startHeight;
1011
+ if (resize.direction === "right" || resize.direction === "corner") {
1012
+ newWidth = Math.max(
1013
+ minWidth,
1014
+ Math.min(effectiveMax, resize.startWidth + (e.clientX - resize.startX))
1015
+ );
1016
+ }
1017
+ if (resize.direction === "bottom" || resize.direction === "corner") {
1018
+ newHeight = Math.max(
1019
+ Math.round(minWidth / aspectRatio),
1020
+ Math.min(
1021
+ Math.round(effectiveMax / aspectRatio),
1022
+ resize.startHeight + (e.clientY - resize.startY)
1023
+ )
1024
+ );
1025
+ }
1026
+ if (lockAspect) {
1027
+ if (resize.direction === "right" || resize.direction === "corner") {
1028
+ newHeight = Math.round(newWidth / aspectRatio);
1029
+ } else {
1030
+ newWidth = Math.round(newHeight * aspectRatio);
1031
+ }
1032
+ }
1033
+ if (containerRef.current) {
1034
+ containerRef.current.style.width = `${newWidth}px`;
1035
+ containerRef.current.style.height = `${newHeight}px`;
1036
+ }
1037
+ },
1038
+ [lockAspect, aspectRatio, minWidth, maxWidth]
1039
+ );
1040
+ const handleMouseUp = (0, import_react9.useCallback)(() => {
1041
+ const resize = resizingRef.current;
1042
+ if (!resize) return;
1043
+ document.removeEventListener("mousemove", handleMouseMove);
1044
+ document.removeEventListener("mouseup", handleMouseUp);
1045
+ document.body.style.cursor = "";
1046
+ document.body.style.userSelect = "";
1047
+ if (containerRef.current) {
1048
+ const w = containerRef.current.offsetWidth;
1049
+ const h = containerRef.current.offsetHeight;
1050
+ updateAttributes({ width: w, height: h });
1051
+ }
1052
+ resizingRef.current = null;
1053
+ }, [handleMouseMove, updateAttributes]);
1054
+ (0, import_react9.useEffect)(() => {
1055
+ return () => {
1056
+ document.removeEventListener("mousemove", handleMouseMove);
1057
+ document.removeEventListener("mouseup", handleMouseUp);
1058
+ document.body.style.cursor = "";
1059
+ document.body.style.userSelect = "";
1060
+ };
1061
+ }, [handleMouseMove]);
1062
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1063
+ import_react10.NodeViewWrapper,
1064
+ {
1065
+ className: "rte-embed-wrapper",
1066
+ "data-selected": selected || void 0,
1067
+ "data-align": align,
1068
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1069
+ "div",
1070
+ {
1071
+ ref: containerRef,
1072
+ className: "rte-embed",
1073
+ contentEditable: false,
1074
+ style: {
1075
+ width: width ? `${width}px` : "100%",
1076
+ height: height ? `${height}px` : "auto",
1077
+ minWidth: `${minWidth}px`
1078
+ },
1079
+ children: [
1080
+ children,
1081
+ selected && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1082
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1083
+ "div",
1084
+ {
1085
+ className: "rte-resize-handle rte-resize-handle--right",
1086
+ onMouseDown: (e) => handleMouseDown(e, "right")
1087
+ }
1088
+ ),
1089
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1090
+ "div",
1091
+ {
1092
+ className: "rte-resize-handle rte-resize-handle--bottom",
1093
+ onMouseDown: (e) => handleMouseDown(e, "bottom")
1094
+ }
1095
+ ),
1096
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1097
+ "div",
1098
+ {
1099
+ className: "rte-resize-handle rte-resize-handle--corner",
1100
+ onMouseDown: (e) => handleMouseDown(e, "corner")
1101
+ }
1102
+ )
1103
+ ] })
1104
+ ]
1105
+ }
1106
+ )
1107
+ }
1108
+ );
1109
+ }
1110
+
1111
+ // src/controls/rte-youtube-control.tsx
1112
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1113
+ function getYouTubeId(url) {
1114
+ const clean = url.trim();
1115
+ const patterns = [
1116
+ /(?:youtube\.com\/watch\?v=)([a-zA-Z0-9_-]{11})/,
1117
+ /(?:youtu\.be\/)([a-zA-Z0-9_-]{11})/,
1118
+ /(?:youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/,
1119
+ /(?:youtube\.com\/shorts\/)([a-zA-Z0-9_-]{11})/,
1120
+ /(?:youtube\.com\/live\/)([a-zA-Z0-9_-]{11})/,
1121
+ /(?:youtube\.com\/v\/)([a-zA-Z0-9_-]{11})/,
1122
+ /(?:m\.youtube\.com\/watch\?v=)([a-zA-Z0-9_-]{11})/
1123
+ ];
1124
+ for (const pattern of patterns) {
1125
+ const match = clean.match(pattern);
1126
+ if (match) return match[1] ?? null;
1127
+ }
1128
+ return /^[a-zA-Z0-9_-]{11}$/.test(clean) ? clean : null;
1129
+ }
1130
+ function YouTubeNodeView(props) {
1131
+ const { node } = props;
1132
+ const videoId = getYouTubeId(node.attrs.src) || node.attrs.src;
1133
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ResizableNodeView, { ...props, lockAspect: true, aspectRatio: 16 / 9, minWidth: 320, maxWidth: 1200, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1134
+ "iframe",
1135
+ {
1136
+ src: `https://www.youtube-nocookie.com/embed/${videoId}`,
1137
+ allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",
1138
+ allowFullScreen: true,
1139
+ title: "YouTube video",
1140
+ className: "rte-embed-iframe"
1141
+ }
1142
+ ) });
1143
+ }
1144
+ var YouTubeEmbed = import_core.Node.create({
1145
+ name: "youtube",
1146
+ group: "block",
1147
+ atom: true,
1148
+ draggable: true,
1149
+ addAttributes() {
1150
+ return {
1151
+ src: {
1152
+ default: null,
1153
+ parseHTML: (el) => el.getAttribute("data-src"),
1154
+ renderHTML: (attrs) => ({
1155
+ "data-src": attrs.src
1156
+ })
1157
+ },
1158
+ width: {
1159
+ default: 560,
1160
+ parseHTML: (el) => el.getAttribute("data-width") ? Number(el.getAttribute("data-width")) : 560,
1161
+ renderHTML: (attrs) => ({
1162
+ "data-width": attrs.width
1163
+ })
1164
+ },
1165
+ height: {
1166
+ default: 315,
1167
+ parseHTML: (el) => el.getAttribute("data-height") ? Number(el.getAttribute("data-height")) : 315,
1168
+ renderHTML: (attrs) => ({
1169
+ "data-height": attrs.height
1170
+ })
1171
+ },
1172
+ align: {
1173
+ default: "center",
1174
+ parseHTML: (el) => el.getAttribute("data-align") || "center",
1175
+ renderHTML: (attrs) => ({
1176
+ "data-align": attrs.align
1177
+ })
1178
+ }
1179
+ };
1180
+ },
1181
+ parseHTML() {
1182
+ return [{ tag: 'div[data-type="youtube"]' }];
1183
+ },
1184
+ renderHTML({ node }) {
1185
+ return [
1186
+ "div",
1187
+ {
1188
+ "data-type": "youtube",
1189
+ "data-src": node.attrs.src,
1190
+ "data-width": node.attrs.width,
1191
+ "data-height": node.attrs.height,
1192
+ "data-align": node.attrs.align
1193
+ }
1194
+ ];
1195
+ },
1196
+ addNodeView() {
1197
+ return (0, import_react12.ReactNodeViewRenderer)(YouTubeNodeView);
1198
+ },
1199
+ addCommands() {
1200
+ return {
1201
+ setYouTubeEmbed: (src) => ({ commands }) => {
1202
+ return commands.insertContent({
1203
+ type: "youtube",
1204
+ attrs: { src }
1205
+ });
1206
+ }
1207
+ };
1208
+ },
1209
+ addInputRules() {
1210
+ return [
1211
+ (0, import_core.nodeInputRule)({
1212
+ find: /https?:\/\/(?:www\.|m\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=|embed\/|shorts\/|live\/|v\/)?([a-zA-Z0-9_-]{11})/,
1213
+ type: this.type,
1214
+ getAttributes: (match) => ({ src: match[0] })
1215
+ })
1216
+ ];
1217
+ }
1218
+ });
1219
+ function YouTubeEmbedControl({ className }) {
1220
+ const { editor } = useRichTextEditorContext();
1221
+ const [open, setOpen] = (0, import_react11.useState)(false);
1222
+ const [url, setUrl] = (0, import_react11.useState)("");
1223
+ const { active } = (0, import_react12.useEditorState)({
1224
+ editor: editor ?? null,
1225
+ selector: (ctx) => ({
1226
+ active: ctx.editor && !ctx.editor.isDestroyed ? ctx.editor.isActive("youtube") : false
1227
+ })
1228
+ }) ?? { active: false };
1229
+ const handleInsert = (0, import_react11.useCallback)(() => {
1230
+ if (url && editor) {
1231
+ editor.chain().focus().setYouTubeEmbed(url).run();
1232
+ setUrl("");
1233
+ }
1234
+ }, [url, editor]);
1235
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Dialog, { open, onOpenChange: setOpen, children: [
1236
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1237
+ DialogTrigger,
1238
+ {
1239
+ render: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1240
+ RichTextEditorControl,
1241
+ {
1242
+ active,
1243
+ className,
1244
+ title: "Embed YouTube video",
1245
+ "aria-label": "Embed YouTube video",
1246
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
1247
+ "svg",
1248
+ {
1249
+ xmlns: "http://www.w3.org/2000/svg",
1250
+ viewBox: "0 0 24 24",
1251
+ fill: "none",
1252
+ stroke: "currentColor",
1253
+ "stroke-width": "2",
1254
+ "stroke-linecap": "round",
1255
+ "stroke-linejoin": "round",
1256
+ className: "rte-editor-icon",
1257
+ children: [
1258
+ /* @__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" }),
1259
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("path", { d: "M9.5 15.5V8.5l6.2 3.5z" })
1260
+ ]
1261
+ }
1262
+ )
1263
+ }
1264
+ )
1265
+ }
1266
+ ),
1267
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(DialogContent, { showCloseButton: false, children: [
1268
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(DialogHeader, { children: [
1269
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(DialogTitle, { children: "Embed YouTube video" }),
1270
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(DialogDescription, { children: "Paste a YouTube video URL or ID." })
1271
+ ] }),
1272
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1273
+ Input,
1274
+ {
1275
+ value: url,
1276
+ onChange: (e) => setUrl(e.target.value),
1277
+ placeholder: "https://youtube.com/watch?v=...",
1278
+ onKeyDown: (e) => {
1279
+ if (e.key === "Enter" && url) {
1280
+ handleInsert();
1281
+ setOpen(false);
1282
+ }
1283
+ }
1284
+ }
1285
+ ),
1286
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(DialogFooter, { children: [
1287
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(DialogClose, { children: "Cancel" }),
1288
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1289
+ DialogClose,
1290
+ {
1291
+ disabled: !url,
1292
+ className: "rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-50",
1293
+ onClick: handleInsert,
1294
+ children: "Insert"
1295
+ }
1296
+ )
1297
+ ] })
1298
+ ] })
1299
+ ] });
1300
+ }
1301
+
1302
+ // src/controls/rte-twitter-control.tsx
1303
+ var import_react13 = require("react");
1304
+ var import_core2 = require("@tiptap/core");
1305
+ var import_react14 = require("@tiptap/react");
1306
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1307
+ var WIDGET_SCRIPT_URL = "https://platform.twitter.com/widgets.js";
1308
+ function TwitterNodeView(props) {
1309
+ const { node } = props;
1310
+ const containerRef = (0, import_react13.useRef)(null);
1311
+ const [loading, setLoading] = (0, import_react13.useState)(true);
1312
+ const tweetId = node.attrs.tweetId;
1313
+ const w = node.attrs.width;
1314
+ const h = node.attrs.height;
1315
+ const renderTweet = (0, import_react13.useCallback)(() => {
1316
+ if (!containerRef.current || !tweetId) return;
1317
+ containerRef.current.innerHTML = "";
1318
+ setLoading(true);
1319
+ const twttr = window.twttr;
1320
+ if (twttr?.widgets) {
1321
+ twttr.widgets.createTweet(tweetId, containerRef.current).then(() => {
1322
+ setLoading(false);
1323
+ });
1324
+ }
1325
+ }, [tweetId]);
1326
+ (0, import_react13.useEffect)(() => {
1327
+ if (!containerRef.current || !tweetId) return;
1328
+ if (window.twttr?.widgets) {
1329
+ renderTweet();
1330
+ } else {
1331
+ const script = document.createElement("script");
1332
+ script.src = WIDGET_SCRIPT_URL;
1333
+ script.async = true;
1334
+ script.onload = renderTweet;
1335
+ document.body.appendChild(script);
1336
+ }
1337
+ }, [tweetId, w, h, renderTweet]);
1338
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(ResizableNodeView, { ...props, lockAspect: false, minWidth: 300, maxWidth: 1200, children: [
1339
+ loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "rte-embed-loading", children: "Loading tweet..." }),
1340
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { ref: containerRef })
1341
+ ] });
1342
+ }
1343
+ var TwitterEmbed = import_core2.Node.create({
1344
+ name: "twitter",
1345
+ group: "block",
1346
+ atom: true,
1347
+ draggable: true,
1348
+ addAttributes() {
1349
+ return {
1350
+ tweetId: {
1351
+ default: null,
1352
+ parseHTML: (el) => el.getAttribute("data-tweet-id"),
1353
+ renderHTML: (attrs) => ({
1354
+ "data-tweet-id": attrs.tweetId
1355
+ })
1356
+ },
1357
+ width: {
1358
+ default: 550,
1359
+ parseHTML: (el) => el.getAttribute("data-width") ? Number(el.getAttribute("data-width")) : 550,
1360
+ renderHTML: (attrs) => ({
1361
+ "data-width": attrs.width
1362
+ })
1363
+ },
1364
+ height: {
1365
+ default: 400,
1366
+ parseHTML: (el) => el.getAttribute("data-height") ? Number(el.getAttribute("data-height")) : 400,
1367
+ renderHTML: (attrs) => ({
1368
+ "data-height": attrs.height
1369
+ })
1370
+ },
1371
+ align: {
1372
+ default: "center",
1373
+ parseHTML: (el) => el.getAttribute("data-align") || "center",
1374
+ renderHTML: (attrs) => ({
1375
+ "data-align": attrs.align
1376
+ })
1377
+ }
1378
+ };
1379
+ },
1380
+ parseHTML() {
1381
+ return [{ tag: 'div[data-type="twitter"]' }];
1382
+ },
1383
+ renderHTML({ node }) {
1384
+ return [
1385
+ "div",
1386
+ {
1387
+ "data-type": "twitter",
1388
+ "data-tweet-id": node.attrs.tweetId,
1389
+ "data-width": node.attrs.width,
1390
+ "data-height": node.attrs.height,
1391
+ "data-align": node.attrs.align
1392
+ }
1393
+ ];
1394
+ },
1395
+ addNodeView() {
1396
+ return (0, import_react14.ReactNodeViewRenderer)(TwitterNodeView);
1397
+ },
1398
+ addCommands() {
1399
+ return {
1400
+ setTwitterEmbed: (tweetId) => ({ commands }) => {
1401
+ return commands.insertContent({
1402
+ type: "twitter",
1403
+ attrs: { tweetId }
1404
+ });
1405
+ }
1406
+ };
1407
+ },
1408
+ addInputRules() {
1409
+ return [
1410
+ (0, import_core2.nodeInputRule)({
1411
+ find: /https?:\/\/(?:www\.)?(?:twitter\.com|x\.com)\/\w+\/status\/(\d+)/,
1412
+ type: this.type,
1413
+ getAttributes: (match) => ({ tweetId: match[1] })
1414
+ })
1415
+ ];
1416
+ }
1417
+ });
1418
+ function extractTweetId(input) {
1419
+ const clean = input.trim();
1420
+ const match = clean.match(/(?:twitter\.com|x\.com)\/(?:\w+\/status\/|i\/web\/status\/)(\d+)/);
1421
+ return match ? match[1] ?? null : /^\d+$/.test(clean) ? clean : null;
1422
+ }
1423
+ function TwitterEmbedControl({ className }) {
1424
+ const { editor } = useRichTextEditorContext();
1425
+ const [open, setOpen] = (0, import_react13.useState)(false);
1426
+ const [url, setUrl] = (0, import_react13.useState)("");
1427
+ const { active } = (0, import_react14.useEditorState)({
1428
+ editor: editor ?? null,
1429
+ selector: (ctx) => ({
1430
+ active: ctx.editor && !ctx.editor.isDestroyed ? ctx.editor.isActive("twitter") : false
1431
+ })
1432
+ }) ?? { active: false };
1433
+ const handleInsert = (0, import_react13.useCallback)(() => {
1434
+ if (url && editor) {
1435
+ const tweetId = extractTweetId(url);
1436
+ if (tweetId) {
1437
+ editor.chain().focus().setTwitterEmbed(tweetId).run();
1438
+ setUrl("");
1439
+ }
1440
+ }
1441
+ }, [url, editor]);
1442
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Dialog, { open, onOpenChange: setOpen, children: [
1443
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1444
+ DialogTrigger,
1445
+ {
1446
+ render: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1447
+ RichTextEditorControl,
1448
+ {
1449
+ active,
1450
+ className,
1451
+ title: "Embed Tweet",
1452
+ "aria-label": "Embed Tweet",
1453
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1454
+ "svg",
1455
+ {
1456
+ xmlns: "http://www.w3.org/2000/svg",
1457
+ viewBox: "0 0 24 24",
1458
+ fill: "currentColor",
1459
+ className: "rte-editor-icon",
1460
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.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" })
1461
+ }
1462
+ )
1463
+ }
1464
+ )
1465
+ }
1466
+ ),
1467
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(DialogContent, { children: [
1468
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(DialogHeader, { children: [
1469
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DialogTitle, { children: "Embed Tweet" }),
1470
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DialogDescription, { children: "Paste a tweet URL or ID." })
1471
+ ] }),
1472
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1473
+ Input,
1474
+ {
1475
+ value: url,
1476
+ onChange: (e) => setUrl(e.target.value),
1477
+ placeholder: "https://x.com/user/status/...",
1478
+ onKeyDown: (e) => {
1479
+ if (e.key === "Enter" && url) {
1480
+ handleInsert();
1481
+ setOpen(false);
1482
+ }
1483
+ }
1484
+ }
1485
+ ),
1486
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(DialogFooter, { children: [
1487
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DialogClose, { children: "Cancel" }),
1488
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1489
+ DialogClose,
1490
+ {
1491
+ disabled: !url,
1492
+ className: "rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-50",
1493
+ onClick: handleInsert,
1494
+ children: "Insert"
1495
+ }
1496
+ )
1497
+ ] })
1498
+ ] })
1499
+ ] });
1500
+ }
1501
+
1502
+ // src/rte-text-editor.tsx
1503
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1504
+ function RichTextEditorRoot({
1505
+ editor,
1506
+ children,
1507
+ className,
1508
+ labels,
1509
+ icons,
1510
+ variant = "default",
1511
+ editable = true
1512
+ }) {
1513
+ const mergedLabels = (0, import_react15.useMemo)(
1514
+ () => ({ ...DEFAULT_LABELS, ...labels }),
1515
+ [labels]
1516
+ );
1517
+ const mergedIcons = (0, import_react15.useMemo)(
1518
+ () => ({ ...DEFAULT_ICONS, ...icons }),
1519
+ [icons]
1520
+ );
1521
+ (0, import_react15.useEffect)(() => {
1522
+ if (editor && editor.isEditable !== editable) {
1523
+ editor.setEditable(editable);
1524
+ }
1525
+ }, [editor, editable]);
1526
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(RichTextEditorContext.Provider, { value: { editor, labels: mergedLabels, icons: mergedIcons, variant, editable }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1527
+ "div",
1528
+ {
1529
+ className: cn(
1530
+ "rte-root",
1531
+ variant !== "default" && `rte-root--${variant}`,
1532
+ className
1533
+ ),
1534
+ "data-variant": variant,
1535
+ children
1536
+ }
1537
+ ) });
1538
+ }
1539
+ var RichTextEditor = Object.assign(RichTextEditorRoot, {
1540
+ Toolbar,
1541
+ ControlsGroup,
1542
+ Content,
1543
+ Control: RichTextEditorControl,
1544
+ Link: LinkControl,
1545
+ YouTubeEmbed: YouTubeEmbedControl,
1546
+ TwitterEmbed: TwitterEmbedControl,
1547
+ Bold: BoldControl,
1548
+ Italic: ItalicControl,
1549
+ Underline: UnderlineControl,
1550
+ Strikethrough: StrikethroughControl,
1551
+ ClearFormatting: ClearFormattingControl,
1552
+ Code: CodeControl,
1553
+ CodeBlock: CodeBlockControl,
1554
+ H1: H1Control,
1555
+ H2: H2Control,
1556
+ H3: H3Control,
1557
+ H4: H4Control,
1558
+ H5: H5Control,
1559
+ H6: H6Control,
1560
+ BulletList: BulletListControl,
1561
+ OrderedList: OrderedListControl,
1562
+ Blockquote: BlockquoteControl,
1563
+ Hr: HrControl,
1564
+ Unlink: UnlinkControl,
1565
+ Undo: UndoControl,
1566
+ Redo: RedoControl,
1567
+ AlignLeft: AlignLeftControl,
1568
+ AlignCenter: AlignCenterControl,
1569
+ AlignRight: AlignRightControl,
1570
+ AlignJustify: AlignJustifyControl,
1571
+ Highlight: HighlightControl,
1572
+ Subscript: SubscriptControl,
1573
+ Superscript: SuperscriptControl
1574
+ });
1575
+
1576
+ // src/extensions/link.ts
1577
+ var import_extension_link = __toESM(require("@tiptap/extension-link"), 1);
1578
+ var Link = import_extension_link.default.extend({
1579
+ addKeyboardShortcuts() {
1580
+ return {
1581
+ "Mod-k": () => {
1582
+ window.dispatchEvent(new Event("edit-link"));
1583
+ return true;
1584
+ }
1585
+ };
1586
+ }
1587
+ }).configure({ openOnClick: false });
1588
+ // Annotate the CommonJS export names for ESM import in node:
1589
+ 0 && (module.exports = {
1590
+ DEFAULT_ICONS,
1591
+ DEFAULT_LABELS,
1592
+ Link,
1593
+ RichTextEditor,
1594
+ TwitterEmbed,
1595
+ YouTubeEmbed,
1596
+ useRichTextEditorContext
1597
+ });
1598
+ //# sourceMappingURL=index.cjs.map