@entur-partner/rich-text-editor 6.3.4 → 7.0.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/README.md +31 -8
- package/dist/index.d.ts +41 -5
- package/dist/index.js +697 -8
- package/dist/styles.css +6182 -126
- package/package.json +108 -133
- package/dist/ExpandableMultiLanguageRichTextEditor.d.ts +0 -21
- package/dist/ExpandableMultiLanguageRichTextEditor.test.d.ts +0 -1
- package/dist/rich-text-editor.cjs.development.js +0 -919
- package/dist/rich-text-editor.cjs.development.js.map +0 -1
- package/dist/rich-text-editor.cjs.production.min.js +0 -2
- package/dist/rich-text-editor.cjs.production.min.js.map +0 -1
- package/dist/rich-text-editor.esm.js +0 -907
- package/dist/rich-text-editor.esm.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,697 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
1
|
+
import { c } from "react/compiler-runtime";
|
|
2
|
+
import { Label } from "@entur/typography";
|
|
3
|
+
import { CharacterCount } from "@tiptap/extensions";
|
|
4
|
+
import { Markdown } from "@tiptap/markdown";
|
|
5
|
+
import { Tiptap, useEditor, useEditorState, useTiptap } from "@tiptap/react";
|
|
6
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
7
|
+
import { Dropdown } from "@entur/dropdown";
|
|
8
|
+
import { useTranslation } from "react-i18next";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { BoldIcon, BulletListIcon, CheckIcon, CloseIcon, ItalicIcon, LinkIcon, NumberListIcon, UnderlineIcon, UnlinkIcon } from "@entur/icons";
|
|
11
|
+
import { SecondarySquareButton } from "@entur/button";
|
|
12
|
+
import { TextField } from "@entur/form";
|
|
13
|
+
import { useState } from "react";
|
|
14
|
+
//#region src/RichTextEditor/MenuBar/FontDropdown/fontStyleSelector.ts
|
|
15
|
+
const fontStyleSelector = (ctx) => {
|
|
16
|
+
if (ctx.editor.isActive("heading", { level: 1 })) return "header-one";
|
|
17
|
+
if (ctx.editor.isActive("heading", { level: 2 })) return "header-two";
|
|
18
|
+
if (ctx.editor.isActive("heading", { level: 3 })) return "header-three";
|
|
19
|
+
if (ctx.editor.isActive("heading", { level: 4 })) return "header-four";
|
|
20
|
+
if (ctx.editor.isActive("heading", { level: 5 })) return "header-five";
|
|
21
|
+
if (ctx.editor.isActive("heading", { level: 6 })) return "header-six";
|
|
22
|
+
return "unstyled";
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/RichTextEditor/MenuBar/FontDropdown/FontDropdown.tsx
|
|
26
|
+
const fontList = {
|
|
27
|
+
unstyled: {
|
|
28
|
+
label: "styles.p",
|
|
29
|
+
style: "unstyled"
|
|
30
|
+
},
|
|
31
|
+
"header-one": {
|
|
32
|
+
label: "styles.h1",
|
|
33
|
+
style: "header-one"
|
|
34
|
+
},
|
|
35
|
+
"header-two": {
|
|
36
|
+
label: "styles.h2",
|
|
37
|
+
style: "header-two"
|
|
38
|
+
},
|
|
39
|
+
"header-three": {
|
|
40
|
+
label: "styles.h3",
|
|
41
|
+
style: "header-three"
|
|
42
|
+
},
|
|
43
|
+
"header-four": {
|
|
44
|
+
label: "styles.h4",
|
|
45
|
+
style: "header-four"
|
|
46
|
+
},
|
|
47
|
+
"header-five": {
|
|
48
|
+
label: "styles.h5",
|
|
49
|
+
style: "header-five"
|
|
50
|
+
},
|
|
51
|
+
"header-six": {
|
|
52
|
+
label: "styles.h6",
|
|
53
|
+
style: "header-six"
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const FontDropdown = () => {
|
|
57
|
+
const $ = c(16);
|
|
58
|
+
const { editor } = useTiptap();
|
|
59
|
+
const { t } = useTranslation();
|
|
60
|
+
let t0;
|
|
61
|
+
if ($[0] !== editor) {
|
|
62
|
+
t0 = {
|
|
63
|
+
editor,
|
|
64
|
+
selector: fontStyleSelector
|
|
65
|
+
};
|
|
66
|
+
$[0] = editor;
|
|
67
|
+
$[1] = t0;
|
|
68
|
+
} else t0 = $[1];
|
|
69
|
+
const editorState = useEditorState(t0);
|
|
70
|
+
if (!editor) return null;
|
|
71
|
+
let t1;
|
|
72
|
+
if ($[2] !== t) {
|
|
73
|
+
const toItem = (option) => ({
|
|
74
|
+
value: option.style,
|
|
75
|
+
label: t(option.label)
|
|
76
|
+
});
|
|
77
|
+
t1 = Object.values(fontList).map(toItem);
|
|
78
|
+
$[2] = t;
|
|
79
|
+
$[3] = t1;
|
|
80
|
+
} else t1 = $[3];
|
|
81
|
+
const items = t1;
|
|
82
|
+
let t2;
|
|
83
|
+
if ($[4] !== editorState || $[5] !== items) {
|
|
84
|
+
t2 = items.find((item) => item.value === editorState) ?? items[0] ?? null;
|
|
85
|
+
$[4] = editorState;
|
|
86
|
+
$[5] = items;
|
|
87
|
+
$[6] = t2;
|
|
88
|
+
} else t2 = $[6];
|
|
89
|
+
const selectedItem = t2;
|
|
90
|
+
let t3;
|
|
91
|
+
if ($[7] !== editor) {
|
|
92
|
+
t3 = (selectedValue) => {
|
|
93
|
+
if (!selectedValue) return;
|
|
94
|
+
bb20: switch (selectedValue.value) {
|
|
95
|
+
case "unstyled":
|
|
96
|
+
editor.chain().focus().setParagraph().run();
|
|
97
|
+
break bb20;
|
|
98
|
+
case "header-one":
|
|
99
|
+
editor.chain().focus().toggleHeading({ level: 1 }).run();
|
|
100
|
+
break bb20;
|
|
101
|
+
case "header-two":
|
|
102
|
+
editor.chain().focus().toggleHeading({ level: 2 }).run();
|
|
103
|
+
break bb20;
|
|
104
|
+
case "header-three":
|
|
105
|
+
editor.chain().focus().toggleHeading({ level: 3 }).run();
|
|
106
|
+
break bb20;
|
|
107
|
+
case "header-four":
|
|
108
|
+
editor.chain().focus().toggleHeading({ level: 4 }).run();
|
|
109
|
+
break bb20;
|
|
110
|
+
case "header-five":
|
|
111
|
+
editor.chain().focus().toggleHeading({ level: 5 }).run();
|
|
112
|
+
break bb20;
|
|
113
|
+
case "header-six": editor.chain().focus().toggleHeading({ level: 6 }).run();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
$[7] = editor;
|
|
117
|
+
$[8] = t3;
|
|
118
|
+
} else t3 = $[8];
|
|
119
|
+
const onChange = t3;
|
|
120
|
+
let t4;
|
|
121
|
+
if ($[9] !== t) {
|
|
122
|
+
t4 = t("styles.style");
|
|
123
|
+
$[9] = t;
|
|
124
|
+
$[10] = t4;
|
|
125
|
+
} else t4 = $[10];
|
|
126
|
+
let t5;
|
|
127
|
+
if ($[11] !== items || $[12] !== onChange || $[13] !== selectedItem || $[14] !== t4) {
|
|
128
|
+
t5 = /* @__PURE__ */ jsx("div", {
|
|
129
|
+
className: "font-dropdown",
|
|
130
|
+
children: /* @__PURE__ */ jsx(Dropdown, {
|
|
131
|
+
className: "block-type-dropdown",
|
|
132
|
+
label: t4,
|
|
133
|
+
items,
|
|
134
|
+
selectedItem,
|
|
135
|
+
onChange
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
$[11] = items;
|
|
139
|
+
$[12] = onChange;
|
|
140
|
+
$[13] = selectedItem;
|
|
141
|
+
$[14] = t4;
|
|
142
|
+
$[15] = t5;
|
|
143
|
+
} else t5 = $[15];
|
|
144
|
+
return t5;
|
|
145
|
+
};
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/RichTextEditor/MenuBar/InlineStyleButtons/inlineStyleButtonsSelector.ts
|
|
148
|
+
const inlineStyleButtonsSelector = (ctx) => ({
|
|
149
|
+
isBold: ctx.editor.isActive("bold") ?? false,
|
|
150
|
+
isItalic: ctx.editor.isActive("italic") ?? false,
|
|
151
|
+
isUnderline: ctx.editor.isActive("underline") ?? false
|
|
152
|
+
});
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/RichTextEditor/MenuBar/InlineStyleButtons/InlineStyleButtons.tsx
|
|
155
|
+
const hotkey = navigator.platform.includes("Mac") ? "⌘" : "Ctrl";
|
|
156
|
+
const InlineStyleButtons = () => {
|
|
157
|
+
const $ = c(33);
|
|
158
|
+
const { editor } = useTiptap();
|
|
159
|
+
const { t } = useTranslation();
|
|
160
|
+
let t0;
|
|
161
|
+
if ($[0] !== editor) {
|
|
162
|
+
t0 = {
|
|
163
|
+
editor,
|
|
164
|
+
selector: inlineStyleButtonsSelector
|
|
165
|
+
};
|
|
166
|
+
$[0] = editor;
|
|
167
|
+
$[1] = t0;
|
|
168
|
+
} else t0 = $[1];
|
|
169
|
+
const editorState = useEditorState(t0);
|
|
170
|
+
if (!editor) return null;
|
|
171
|
+
let t1;
|
|
172
|
+
if ($[2] !== t) {
|
|
173
|
+
t1 = t("styles.bold");
|
|
174
|
+
$[2] = t;
|
|
175
|
+
$[3] = t1;
|
|
176
|
+
} else t1 = $[3];
|
|
177
|
+
const t2 = `${t1} (${hotkey} + B)`;
|
|
178
|
+
let t3;
|
|
179
|
+
if ($[4] !== editor) {
|
|
180
|
+
t3 = () => editor.chain().focus().toggleBold().run();
|
|
181
|
+
$[4] = editor;
|
|
182
|
+
$[5] = t3;
|
|
183
|
+
} else t3 = $[5];
|
|
184
|
+
const t4 = `editor-stylebutton ${editorState.isBold ? "active" : ""}`;
|
|
185
|
+
let t5;
|
|
186
|
+
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
187
|
+
t5 = /* @__PURE__ */ jsx(BoldIcon, {});
|
|
188
|
+
$[6] = t5;
|
|
189
|
+
} else t5 = $[6];
|
|
190
|
+
let t6;
|
|
191
|
+
if ($[7] !== t2 || $[8] !== t3 || $[9] !== t4) {
|
|
192
|
+
t6 = /* @__PURE__ */ jsx("button", {
|
|
193
|
+
type: "button",
|
|
194
|
+
title: t2,
|
|
195
|
+
onClick: t3,
|
|
196
|
+
className: t4,
|
|
197
|
+
children: t5
|
|
198
|
+
});
|
|
199
|
+
$[7] = t2;
|
|
200
|
+
$[8] = t3;
|
|
201
|
+
$[9] = t4;
|
|
202
|
+
$[10] = t6;
|
|
203
|
+
} else t6 = $[10];
|
|
204
|
+
let t7;
|
|
205
|
+
if ($[11] !== t) {
|
|
206
|
+
t7 = t("styles.italic");
|
|
207
|
+
$[11] = t;
|
|
208
|
+
$[12] = t7;
|
|
209
|
+
} else t7 = $[12];
|
|
210
|
+
const t8 = `${t7} (${hotkey} + I)`;
|
|
211
|
+
let t9;
|
|
212
|
+
if ($[13] !== editor) {
|
|
213
|
+
t9 = () => editor.chain().focus().toggleItalic().run();
|
|
214
|
+
$[13] = editor;
|
|
215
|
+
$[14] = t9;
|
|
216
|
+
} else t9 = $[14];
|
|
217
|
+
const t10 = `editor-stylebutton ${editorState.isItalic ? "active" : ""}`;
|
|
218
|
+
let t11;
|
|
219
|
+
if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
|
|
220
|
+
t11 = /* @__PURE__ */ jsx(ItalicIcon, {});
|
|
221
|
+
$[15] = t11;
|
|
222
|
+
} else t11 = $[15];
|
|
223
|
+
let t12;
|
|
224
|
+
if ($[16] !== t10 || $[17] !== t8 || $[18] !== t9) {
|
|
225
|
+
t12 = /* @__PURE__ */ jsx("button", {
|
|
226
|
+
type: "button",
|
|
227
|
+
title: t8,
|
|
228
|
+
onClick: t9,
|
|
229
|
+
className: t10,
|
|
230
|
+
children: t11
|
|
231
|
+
});
|
|
232
|
+
$[16] = t10;
|
|
233
|
+
$[17] = t8;
|
|
234
|
+
$[18] = t9;
|
|
235
|
+
$[19] = t12;
|
|
236
|
+
} else t12 = $[19];
|
|
237
|
+
let t13;
|
|
238
|
+
if ($[20] !== t) {
|
|
239
|
+
t13 = t("styles.underline");
|
|
240
|
+
$[20] = t;
|
|
241
|
+
$[21] = t13;
|
|
242
|
+
} else t13 = $[21];
|
|
243
|
+
const t14 = `${t13} (${hotkey} + U)`;
|
|
244
|
+
let t15;
|
|
245
|
+
if ($[22] !== editor) {
|
|
246
|
+
t15 = () => editor.chain().focus().toggleUnderline().run();
|
|
247
|
+
$[22] = editor;
|
|
248
|
+
$[23] = t15;
|
|
249
|
+
} else t15 = $[23];
|
|
250
|
+
const t16 = `editor-stylebutton ${editorState.isUnderline ? "active" : ""}`;
|
|
251
|
+
let t17;
|
|
252
|
+
if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
|
|
253
|
+
t17 = /* @__PURE__ */ jsx(UnderlineIcon, {});
|
|
254
|
+
$[24] = t17;
|
|
255
|
+
} else t17 = $[24];
|
|
256
|
+
let t18;
|
|
257
|
+
if ($[25] !== t14 || $[26] !== t15 || $[27] !== t16) {
|
|
258
|
+
t18 = /* @__PURE__ */ jsx("button", {
|
|
259
|
+
type: "button",
|
|
260
|
+
title: t14,
|
|
261
|
+
onClick: t15,
|
|
262
|
+
className: t16,
|
|
263
|
+
children: t17
|
|
264
|
+
});
|
|
265
|
+
$[25] = t14;
|
|
266
|
+
$[26] = t15;
|
|
267
|
+
$[27] = t16;
|
|
268
|
+
$[28] = t18;
|
|
269
|
+
} else t18 = $[28];
|
|
270
|
+
let t19;
|
|
271
|
+
if ($[29] !== t12 || $[30] !== t18 || $[31] !== t6) {
|
|
272
|
+
t19 = /* @__PURE__ */ jsxs("div", {
|
|
273
|
+
className: "controls-group block-editor-controls",
|
|
274
|
+
children: [
|
|
275
|
+
t6,
|
|
276
|
+
t12,
|
|
277
|
+
t18
|
|
278
|
+
]
|
|
279
|
+
});
|
|
280
|
+
$[29] = t12;
|
|
281
|
+
$[30] = t18;
|
|
282
|
+
$[31] = t6;
|
|
283
|
+
$[32] = t19;
|
|
284
|
+
} else t19 = $[32];
|
|
285
|
+
return t19;
|
|
286
|
+
};
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/RichTextEditor/MenuBar/LinkButton/linkButtonSelector.ts
|
|
289
|
+
const linkButtonSelector = (ctx) => ({ hasLink: ctx.editor.isActive("link") ?? false });
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/RichTextEditor/MenuBar/LinkButton/LinkButton.tsx
|
|
292
|
+
const LinkButton = () => {
|
|
293
|
+
const $ = c(30);
|
|
294
|
+
const { editor } = useTiptap();
|
|
295
|
+
const { t } = useTranslation();
|
|
296
|
+
const [showUrlInput, setShowUrlInput] = useState(false);
|
|
297
|
+
const [urlValue, setUrlValue] = useState("");
|
|
298
|
+
let t0;
|
|
299
|
+
if ($[0] !== editor) {
|
|
300
|
+
t0 = {
|
|
301
|
+
editor,
|
|
302
|
+
selector: linkButtonSelector
|
|
303
|
+
};
|
|
304
|
+
$[0] = editor;
|
|
305
|
+
$[1] = t0;
|
|
306
|
+
} else t0 = $[1];
|
|
307
|
+
const editorState = useEditorState(t0);
|
|
308
|
+
if (!editor) return null;
|
|
309
|
+
let t1;
|
|
310
|
+
if ($[2] !== editor || $[3] !== editorState.hasLink) {
|
|
311
|
+
t1 = () => {
|
|
312
|
+
if (editorState.hasLink || !editor.state.selection.empty) {
|
|
313
|
+
setUrlValue(editor.getAttributes("link").href);
|
|
314
|
+
setShowUrlInput(true);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
$[2] = editor;
|
|
318
|
+
$[3] = editorState.hasLink;
|
|
319
|
+
$[4] = t1;
|
|
320
|
+
} else t1 = $[4];
|
|
321
|
+
const addLink = t1;
|
|
322
|
+
let t2;
|
|
323
|
+
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
|
|
324
|
+
t2 = (event) => {
|
|
325
|
+
setUrlValue(event.target.value);
|
|
326
|
+
};
|
|
327
|
+
$[5] = t2;
|
|
328
|
+
} else t2 = $[5];
|
|
329
|
+
const onUrlChange = t2;
|
|
330
|
+
let confirmLink;
|
|
331
|
+
let onLinkInputKeyDown;
|
|
332
|
+
if ($[6] !== editor || $[7] !== urlValue) {
|
|
333
|
+
onLinkInputKeyDown = (event_0) => {
|
|
334
|
+
if (event_0.key === "Enter") {
|
|
335
|
+
event_0.preventDefault();
|
|
336
|
+
confirmLink();
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
confirmLink = () => {
|
|
340
|
+
if (urlValue === "") editor.chain().focus().unsetLink().run();
|
|
341
|
+
else editor.chain().focus().extendMarkRange("link").setLink({ href: urlValue }).run();
|
|
342
|
+
setShowUrlInput(false);
|
|
343
|
+
};
|
|
344
|
+
$[6] = editor;
|
|
345
|
+
$[7] = urlValue;
|
|
346
|
+
$[8] = confirmLink;
|
|
347
|
+
$[9] = onLinkInputKeyDown;
|
|
348
|
+
} else {
|
|
349
|
+
confirmLink = $[8];
|
|
350
|
+
onLinkInputKeyDown = $[9];
|
|
351
|
+
}
|
|
352
|
+
let t3;
|
|
353
|
+
if ($[10] !== editor) {
|
|
354
|
+
t3 = () => {
|
|
355
|
+
editor.chain().focus().unsetLink().run();
|
|
356
|
+
setShowUrlInput(false);
|
|
357
|
+
};
|
|
358
|
+
$[10] = editor;
|
|
359
|
+
$[11] = t3;
|
|
360
|
+
} else t3 = $[11];
|
|
361
|
+
const removeLink = t3;
|
|
362
|
+
const t4 = `editor-stylebutton ${editorState.hasLink ? "active" : ""}`;
|
|
363
|
+
let t5;
|
|
364
|
+
if ($[12] !== t) {
|
|
365
|
+
t5 = t("styles.link");
|
|
366
|
+
$[12] = t;
|
|
367
|
+
$[13] = t5;
|
|
368
|
+
} else t5 = $[13];
|
|
369
|
+
let t6;
|
|
370
|
+
if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
|
|
371
|
+
t6 = /* @__PURE__ */ jsx(LinkIcon, {});
|
|
372
|
+
$[14] = t6;
|
|
373
|
+
} else t6 = $[14];
|
|
374
|
+
let t7;
|
|
375
|
+
if ($[15] !== addLink || $[16] !== t4 || $[17] !== t5) {
|
|
376
|
+
t7 = /* @__PURE__ */ jsx("button", {
|
|
377
|
+
type: "button",
|
|
378
|
+
className: t4,
|
|
379
|
+
title: t5,
|
|
380
|
+
onClick: addLink,
|
|
381
|
+
tabIndex: 0,
|
|
382
|
+
children: t6
|
|
383
|
+
});
|
|
384
|
+
$[15] = addLink;
|
|
385
|
+
$[16] = t4;
|
|
386
|
+
$[17] = t5;
|
|
387
|
+
$[18] = t7;
|
|
388
|
+
} else t7 = $[18];
|
|
389
|
+
let t8;
|
|
390
|
+
if ($[19] !== confirmLink || $[20] !== editor || $[21] !== onLinkInputKeyDown || $[22] !== removeLink || $[23] !== showUrlInput || $[24] !== t || $[25] !== urlValue) {
|
|
391
|
+
t8 = showUrlInput && /* @__PURE__ */ jsxs("div", {
|
|
392
|
+
className: "url-input-container",
|
|
393
|
+
children: [
|
|
394
|
+
/* @__PURE__ */ jsx("button", {
|
|
395
|
+
type: "button",
|
|
396
|
+
className: "exit-button",
|
|
397
|
+
onClick: () => setShowUrlInput(false),
|
|
398
|
+
children: /* @__PURE__ */ jsx(CloseIcon, {})
|
|
399
|
+
}),
|
|
400
|
+
/* @__PURE__ */ jsx("div", {
|
|
401
|
+
className: "link-label",
|
|
402
|
+
children: t("common.from")
|
|
403
|
+
}),
|
|
404
|
+
/* @__PURE__ */ jsxs("div", {
|
|
405
|
+
className: "url-input-form",
|
|
406
|
+
children: [/* @__PURE__ */ jsx(TextField, {
|
|
407
|
+
label: "",
|
|
408
|
+
style: {
|
|
409
|
+
width: 250,
|
|
410
|
+
margin: 5
|
|
411
|
+
},
|
|
412
|
+
onChange: onUrlChange,
|
|
413
|
+
value: urlValue,
|
|
414
|
+
onKeyDown: onLinkInputKeyDown,
|
|
415
|
+
placeholder: "https://example.com"
|
|
416
|
+
}), /* @__PURE__ */ jsx(SecondarySquareButton, {
|
|
417
|
+
onMouseDown: confirmLink,
|
|
418
|
+
children: /* @__PURE__ */ jsx(CheckIcon, {
|
|
419
|
+
width: 15,
|
|
420
|
+
height: 15
|
|
421
|
+
})
|
|
422
|
+
})]
|
|
423
|
+
}),
|
|
424
|
+
editor.getAttributes("link").href?.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
425
|
+
className: "remove-link",
|
|
426
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
427
|
+
type: "button",
|
|
428
|
+
onClick: removeLink,
|
|
429
|
+
title: t("styles.unlink"),
|
|
430
|
+
children: [/* @__PURE__ */ jsx(UnlinkIcon, { inline: true }), /* @__PURE__ */ jsx("span", {
|
|
431
|
+
style: { marginLeft: "10px" },
|
|
432
|
+
children: t("styles.unlink")
|
|
433
|
+
})]
|
|
434
|
+
})
|
|
435
|
+
})
|
|
436
|
+
]
|
|
437
|
+
});
|
|
438
|
+
$[19] = confirmLink;
|
|
439
|
+
$[20] = editor;
|
|
440
|
+
$[21] = onLinkInputKeyDown;
|
|
441
|
+
$[22] = removeLink;
|
|
442
|
+
$[23] = showUrlInput;
|
|
443
|
+
$[24] = t;
|
|
444
|
+
$[25] = urlValue;
|
|
445
|
+
$[26] = t8;
|
|
446
|
+
} else t8 = $[26];
|
|
447
|
+
let t9;
|
|
448
|
+
if ($[27] !== t7 || $[28] !== t8) {
|
|
449
|
+
t9 = /* @__PURE__ */ jsxs("div", {
|
|
450
|
+
className: "controls-group block-editor-controls link-controls",
|
|
451
|
+
children: [t7, t8]
|
|
452
|
+
});
|
|
453
|
+
$[27] = t7;
|
|
454
|
+
$[28] = t8;
|
|
455
|
+
$[29] = t9;
|
|
456
|
+
} else t9 = $[29];
|
|
457
|
+
return t9;
|
|
458
|
+
};
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/RichTextEditor/MenuBar/ListButtons/listButtonsSelector.ts
|
|
461
|
+
const listButtonsSelector = (ctx) => ({
|
|
462
|
+
isBulletList: ctx.editor.isActive("bulletList") ?? false,
|
|
463
|
+
isOrderedList: ctx.editor.isActive("orderedList") ?? false
|
|
464
|
+
});
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region src/RichTextEditor/MenuBar/ListButtons/ListButtons.tsx
|
|
467
|
+
const ListButtons = () => {
|
|
468
|
+
const $ = c(23);
|
|
469
|
+
const { editor } = useTiptap();
|
|
470
|
+
const { t } = useTranslation();
|
|
471
|
+
let t0;
|
|
472
|
+
if ($[0] !== editor) {
|
|
473
|
+
t0 = {
|
|
474
|
+
editor,
|
|
475
|
+
selector: listButtonsSelector
|
|
476
|
+
};
|
|
477
|
+
$[0] = editor;
|
|
478
|
+
$[1] = t0;
|
|
479
|
+
} else t0 = $[1];
|
|
480
|
+
const editorState = useEditorState(t0);
|
|
481
|
+
if (!editor) return null;
|
|
482
|
+
let t1;
|
|
483
|
+
if ($[2] !== t) {
|
|
484
|
+
t1 = t("styles.unordered_list_item");
|
|
485
|
+
$[2] = t;
|
|
486
|
+
$[3] = t1;
|
|
487
|
+
} else t1 = $[3];
|
|
488
|
+
let t2;
|
|
489
|
+
if ($[4] !== editor) {
|
|
490
|
+
t2 = () => editor.chain().focus().toggleBulletList().run();
|
|
491
|
+
$[4] = editor;
|
|
492
|
+
$[5] = t2;
|
|
493
|
+
} else t2 = $[5];
|
|
494
|
+
const t3 = `editor-stylebutton ${editorState.isBulletList ? "active" : ""}`;
|
|
495
|
+
let t4;
|
|
496
|
+
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
497
|
+
t4 = /* @__PURE__ */ jsx(BulletListIcon, {});
|
|
498
|
+
$[6] = t4;
|
|
499
|
+
} else t4 = $[6];
|
|
500
|
+
let t5;
|
|
501
|
+
if ($[7] !== t1 || $[8] !== t2 || $[9] !== t3) {
|
|
502
|
+
t5 = /* @__PURE__ */ jsx("button", {
|
|
503
|
+
type: "button",
|
|
504
|
+
title: t1,
|
|
505
|
+
onClick: t2,
|
|
506
|
+
className: t3,
|
|
507
|
+
children: t4
|
|
508
|
+
});
|
|
509
|
+
$[7] = t1;
|
|
510
|
+
$[8] = t2;
|
|
511
|
+
$[9] = t3;
|
|
512
|
+
$[10] = t5;
|
|
513
|
+
} else t5 = $[10];
|
|
514
|
+
let t6;
|
|
515
|
+
if ($[11] !== t) {
|
|
516
|
+
t6 = t("styles.ordered_list_item");
|
|
517
|
+
$[11] = t;
|
|
518
|
+
$[12] = t6;
|
|
519
|
+
} else t6 = $[12];
|
|
520
|
+
let t7;
|
|
521
|
+
if ($[13] !== editor) {
|
|
522
|
+
t7 = () => editor.chain().focus().toggleOrderedList().run();
|
|
523
|
+
$[13] = editor;
|
|
524
|
+
$[14] = t7;
|
|
525
|
+
} else t7 = $[14];
|
|
526
|
+
const t8 = `editor-stylebutton ${editorState.isOrderedList ? "active" : ""}`;
|
|
527
|
+
let t9;
|
|
528
|
+
if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
|
|
529
|
+
t9 = /* @__PURE__ */ jsx(NumberListIcon, {});
|
|
530
|
+
$[15] = t9;
|
|
531
|
+
} else t9 = $[15];
|
|
532
|
+
let t10;
|
|
533
|
+
if ($[16] !== t6 || $[17] !== t7 || $[18] !== t8) {
|
|
534
|
+
t10 = /* @__PURE__ */ jsx("button", {
|
|
535
|
+
type: "button",
|
|
536
|
+
title: t6,
|
|
537
|
+
onClick: t7,
|
|
538
|
+
className: t8,
|
|
539
|
+
children: t9
|
|
540
|
+
});
|
|
541
|
+
$[16] = t6;
|
|
542
|
+
$[17] = t7;
|
|
543
|
+
$[18] = t8;
|
|
544
|
+
$[19] = t10;
|
|
545
|
+
} else t10 = $[19];
|
|
546
|
+
let t11;
|
|
547
|
+
if ($[20] !== t10 || $[21] !== t5) {
|
|
548
|
+
t11 = /* @__PURE__ */ jsxs("div", {
|
|
549
|
+
className: "controls-group block-editor-controls",
|
|
550
|
+
children: [t5, t10]
|
|
551
|
+
});
|
|
552
|
+
$[20] = t10;
|
|
553
|
+
$[21] = t5;
|
|
554
|
+
$[22] = t11;
|
|
555
|
+
} else t11 = $[22];
|
|
556
|
+
return t11;
|
|
557
|
+
};
|
|
558
|
+
//#endregion
|
|
559
|
+
//#region src/RichTextEditor/MenuBar/MenuBar.tsx
|
|
560
|
+
const MenuBar = () => {
|
|
561
|
+
const $ = c(1);
|
|
562
|
+
let t0;
|
|
563
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
564
|
+
t0 = /* @__PURE__ */ jsxs("div", {
|
|
565
|
+
className: "controls-wrapper",
|
|
566
|
+
children: [
|
|
567
|
+
/* @__PURE__ */ jsx(FontDropdown, {}),
|
|
568
|
+
/* @__PURE__ */ jsx(InlineStyleButtons, {}),
|
|
569
|
+
/* @__PURE__ */ jsx(ListButtons, {}),
|
|
570
|
+
/* @__PURE__ */ jsx(LinkButton, {})
|
|
571
|
+
]
|
|
572
|
+
});
|
|
573
|
+
$[0] = t0;
|
|
574
|
+
} else t0 = $[0];
|
|
575
|
+
return t0;
|
|
576
|
+
};
|
|
577
|
+
//#endregion
|
|
578
|
+
//#region src/RichTextEditor/RichTextEditor.tsx
|
|
579
|
+
/**
|
|
580
|
+
* RichTextEditor is a React component that provides a rich text editing interface using the Tiptap editor.
|
|
581
|
+
*
|
|
582
|
+
* @param {string} [className] - Optional additional class name for styling the editor container.
|
|
583
|
+
* @param {string} [label] - Optional label to display above the editor.
|
|
584
|
+
* @param {string} initialValue - The initial content of the editor, which can be in markdown or HTML format.
|
|
585
|
+
* @param {function} onChange - A callback function that is called whenever the content of the editor changes. It receives the current content as an argument.
|
|
586
|
+
* @param {'markdown' | 'html'} [contentType='html'] - The format of the content (either 'markdown' or 'html'). This determines how the content is processed and returned in the onChange callback.
|
|
587
|
+
* @param {number} [maxNumberOfCharacters=0] - The maximum number of characters allowed in the editor. This limits the amount of content that can be entered by the user. (0 means no limit)
|
|
588
|
+
* @returns {JSX.Element} A React component that renders a rich text editor with the specified configuration and functionality.
|
|
589
|
+
* @example
|
|
590
|
+
* <RichTextEditor
|
|
591
|
+
* className="description-editor"
|
|
592
|
+
* initialValue="# Hello World\n\nThis is **Markdown**!"
|
|
593
|
+
* onChange={(value) => console.log(value)}
|
|
594
|
+
* label="My Rich Text Editor"
|
|
595
|
+
* contentType="markdown"
|
|
596
|
+
* maxNumberOfCharacters={5000}
|
|
597
|
+
* />
|
|
598
|
+
*/
|
|
599
|
+
const RichTextEditor = (t0) => {
|
|
600
|
+
const $ = c(23);
|
|
601
|
+
const { className: t1, label: t2, initialValue, onChange, contentType: t3, maxNumberOfCharacters: t4 } = t0;
|
|
602
|
+
const className = t1 === void 0 ? "" : t1;
|
|
603
|
+
const label = t2 === void 0 ? "" : t2;
|
|
604
|
+
const contentType = t3 === void 0 ? "html" : t3;
|
|
605
|
+
const maxNumberOfCharacters = t4 === void 0 ? 0 : t4;
|
|
606
|
+
let t5;
|
|
607
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
608
|
+
t5 = StarterKit.configure({ link: { openOnClick: false } });
|
|
609
|
+
$[0] = t5;
|
|
610
|
+
} else t5 = $[0];
|
|
611
|
+
let t6;
|
|
612
|
+
if ($[1] !== maxNumberOfCharacters) {
|
|
613
|
+
t6 = CharacterCount.configure({ limit: maxNumberOfCharacters });
|
|
614
|
+
$[1] = maxNumberOfCharacters;
|
|
615
|
+
$[2] = t6;
|
|
616
|
+
} else t6 = $[2];
|
|
617
|
+
let t7;
|
|
618
|
+
if ($[3] !== t6) {
|
|
619
|
+
t7 = [
|
|
620
|
+
t5,
|
|
621
|
+
t6,
|
|
622
|
+
Markdown
|
|
623
|
+
];
|
|
624
|
+
$[3] = t6;
|
|
625
|
+
$[4] = t7;
|
|
626
|
+
} else t7 = $[4];
|
|
627
|
+
let t8;
|
|
628
|
+
if ($[5] !== contentType || $[6] !== onChange) {
|
|
629
|
+
t8 = (t9) => {
|
|
630
|
+
const { editor: currentEditor } = t9;
|
|
631
|
+
return onChange(contentType === "markdown" ? currentEditor.getMarkdown() : currentEditor.getHTML());
|
|
632
|
+
};
|
|
633
|
+
$[5] = contentType;
|
|
634
|
+
$[6] = onChange;
|
|
635
|
+
$[7] = t8;
|
|
636
|
+
} else t8 = $[7];
|
|
637
|
+
let t9;
|
|
638
|
+
if ($[8] !== contentType || $[9] !== initialValue || $[10] !== t7 || $[11] !== t8) {
|
|
639
|
+
t9 = {
|
|
640
|
+
extensions: t7,
|
|
641
|
+
content: initialValue,
|
|
642
|
+
contentType,
|
|
643
|
+
onUpdate: t8
|
|
644
|
+
};
|
|
645
|
+
$[8] = contentType;
|
|
646
|
+
$[9] = initialValue;
|
|
647
|
+
$[10] = t7;
|
|
648
|
+
$[11] = t8;
|
|
649
|
+
$[12] = t9;
|
|
650
|
+
} else t9 = $[12];
|
|
651
|
+
const editor = useEditor(t9);
|
|
652
|
+
if (!editor) return null;
|
|
653
|
+
const t10 = `et-rich-text-editor ${className}`;
|
|
654
|
+
let t11;
|
|
655
|
+
if ($[13] !== label) {
|
|
656
|
+
t11 = label && /* @__PURE__ */ jsx(Label, { children: label });
|
|
657
|
+
$[13] = label;
|
|
658
|
+
$[14] = t11;
|
|
659
|
+
} else t11 = $[14];
|
|
660
|
+
let t12;
|
|
661
|
+
let t13;
|
|
662
|
+
if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
|
|
663
|
+
t12 = /* @__PURE__ */ jsx(MenuBar, {});
|
|
664
|
+
t13 = /* @__PURE__ */ jsx(Tiptap.Content, {});
|
|
665
|
+
$[15] = t12;
|
|
666
|
+
$[16] = t13;
|
|
667
|
+
} else {
|
|
668
|
+
t12 = $[15];
|
|
669
|
+
t13 = $[16];
|
|
670
|
+
}
|
|
671
|
+
let t14;
|
|
672
|
+
if ($[17] !== editor) {
|
|
673
|
+
t14 = /* @__PURE__ */ jsx("div", {
|
|
674
|
+
className: "editor-root",
|
|
675
|
+
children: /* @__PURE__ */ jsxs(Tiptap, {
|
|
676
|
+
editor,
|
|
677
|
+
children: [t12, t13]
|
|
678
|
+
})
|
|
679
|
+
});
|
|
680
|
+
$[17] = editor;
|
|
681
|
+
$[18] = t14;
|
|
682
|
+
} else t14 = $[18];
|
|
683
|
+
let t15;
|
|
684
|
+
if ($[19] !== t10 || $[20] !== t11 || $[21] !== t14) {
|
|
685
|
+
t15 = /* @__PURE__ */ jsxs("div", {
|
|
686
|
+
className: t10,
|
|
687
|
+
children: [t11, t14]
|
|
688
|
+
});
|
|
689
|
+
$[19] = t10;
|
|
690
|
+
$[20] = t11;
|
|
691
|
+
$[21] = t14;
|
|
692
|
+
$[22] = t15;
|
|
693
|
+
} else t15 = $[22];
|
|
694
|
+
return t15;
|
|
695
|
+
};
|
|
696
|
+
//#endregion
|
|
697
|
+
export { RichTextEditor };
|