wimui 0.41.0 → 0.43.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.ja.md +2 -1
- package/README.md +2 -1
- package/dist/components/feedback/Snackbar/snackbar.module.cjs +1 -1
- package/dist/components/feedback/Snackbar/snackbar.module.js +7 -7
- package/dist/components/form/ButtonGroup/ButtonGroup.cjs +1 -1
- package/dist/components/form/ButtonGroup/ButtonGroup.d.ts +3 -1
- package/dist/components/form/ButtonGroup/ButtonGroup.js +6 -5
- package/dist/components/form/ButtonGroup/button-group.module.cjs +1 -1
- package/dist/components/form/ButtonGroup/button-group.module.js +1 -1
- package/dist/components/form/ImageCropper/ImageCropper.cjs +1 -1
- package/dist/components/form/ImageCropper/ImageCropper.js +10 -10
- package/dist/components/form/RichTextEditor/RichTextEditor.cjs +1 -1
- package/dist/components/form/RichTextEditor/RichTextEditor.d.ts +36 -6
- package/dist/components/form/RichTextEditor/RichTextEditor.js +486 -307
- package/dist/components/form/RichTextEditor/markdown.cjs +3 -0
- package/dist/components/form/RichTextEditor/markdown.d.ts +19 -0
- package/dist/components/form/RichTextEditor/markdown.js +63 -0
- package/dist/components/form/RichTextEditor/rich-text-editor.module.cjs +1 -1
- package/dist/components/form/RichTextEditor/rich-text-editor.module.js +7 -3
- package/dist/components/form/RichTextEditor/safeUrl.cjs +2 -0
- package/dist/components/form/RichTextEditor/safeUrl.d.ts +4 -0
- package/dist/components/form/RichTextEditor/safeUrl.js +18 -0
- package/dist/components/overlay/Popover/Popover.cjs +1 -1
- package/dist/components/overlay/Popover/Popover.js +28 -19
- package/dist/form/rich-text-editor.cjs +2 -0
- package/dist/form/rich-text-editor.d.ts +1 -0
- package/dist/form/rich-text-editor.js +3 -0
- package/dist/form.cjs +1 -1
- package/dist/form.d.ts +0 -1
- package/dist/form.js +28 -29
- package/dist/i18n/generated/keys.d.ts +1 -1
- package/dist/i18n/generated/resources.cjs +1 -1
- package/dist/i18n/generated/resources.js +25 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +137 -138
- package/dist/llms-full.txt +12 -5
- package/dist/llms.txt +1 -1
- package/dist/locales/en/components.json +8 -0
- package/dist/locales/ja/components.json +8 -0
- package/dist/locales/pt/components.json +8 -0
- package/dist/overlay.cjs +1 -1
- package/dist/overlay.js +3 -3
- package/dist/styles.css +1 -1
- package/dist/wimui.umd.css +1 -1
- package/dist/wimui.umd.js +5 -5
- package/package.json +66 -1
- package/dist/components/form/RichTextEditor/commands.cjs +0 -2
- package/dist/components/form/RichTextEditor/commands.d.ts +0 -49
- package/dist/components/form/RichTextEditor/commands.js +0 -244
|
@@ -2,25 +2,32 @@
|
|
|
2
2
|
import { useWimTranslation as e } from "../../../i18n/useWimTranslation.js";
|
|
3
3
|
import t from "../../../icon/bold.js";
|
|
4
4
|
import n from "../../../icon/eraser.js";
|
|
5
|
-
import r from "../../../icon/
|
|
6
|
-
import i from "../../../icon/
|
|
7
|
-
import a from "../../../icon/
|
|
5
|
+
import r from "../../../icon/image.js";
|
|
6
|
+
import i from "../../../icon/italic.js";
|
|
7
|
+
import a from "../../../icon/link.js";
|
|
8
|
+
import o from "../../../icon/list-ordered.js";
|
|
8
9
|
import ee from "../../../icon/list.js";
|
|
9
10
|
import te from "../../../icon/strikethrough.js";
|
|
10
11
|
import ne from "../../../icon/underline.js";
|
|
11
12
|
import re from "../../../icon/unlink.js";
|
|
12
|
-
import { Icon as
|
|
13
|
-
import { Button as
|
|
14
|
-
import { FieldTemplate as
|
|
15
|
-
import { Input as
|
|
13
|
+
import { Icon as s } from "../../media/Icon/Icon.js";
|
|
14
|
+
import { Button as c } from "../Button/Button.js";
|
|
15
|
+
import { FieldTemplate as ie } from "../FieldTemplate/FieldTemplate.js";
|
|
16
|
+
import { Input as l } from "../Input/Input.js";
|
|
16
17
|
import { Dialog as ae, DialogClose as oe, DialogContent as se, DialogFooter as ce, DialogHeader as le, DialogTitle as ue } from "../../overlay/Dialog/Dialog.js";
|
|
17
|
-
import {
|
|
18
|
-
import d from "./
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
18
|
+
import { isSafeImageUrl as u, isSafeLinkUrl as de } from "./safeUrl.js";
|
|
19
|
+
import { createMarkdownExtensions as d, markdownToHtml as f } from "./markdown.js";
|
|
20
|
+
import p from "./rich-text-editor.module.js";
|
|
21
|
+
import m from "react";
|
|
22
|
+
import fe from "classnames";
|
|
23
|
+
import { Fragment as pe, jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
24
|
+
import { EditorContent as me, useEditor as he, useEditorState as ge } from "@tiptap/react";
|
|
25
|
+
import { createDocument as _e } from "@tiptap/core";
|
|
26
|
+
import { StarterKit as _ } from "@tiptap/starter-kit";
|
|
27
|
+
import { Placeholder as v } from "@tiptap/extensions";
|
|
28
|
+
import { Image as ve } from "@tiptap/extension-image";
|
|
22
29
|
//#region src/components/form/RichTextEditor/RichTextEditor.tsx
|
|
23
|
-
var
|
|
30
|
+
var ye = [
|
|
24
31
|
"bold",
|
|
25
32
|
"italic",
|
|
26
33
|
"underline",
|
|
@@ -37,339 +44,511 @@ var ve = [
|
|
|
37
44
|
"unlink",
|
|
38
45
|
"separator",
|
|
39
46
|
"removeFormat"
|
|
40
|
-
],
|
|
47
|
+
], be = ve.extend({ parseHTML() {
|
|
48
|
+
return [{
|
|
49
|
+
tag: "img[src]",
|
|
50
|
+
getAttrs: (e) => u(e.getAttribute("src")) ? null : !1
|
|
51
|
+
}];
|
|
52
|
+
} }), xe = (e, t, n) => [
|
|
53
|
+
_.configure({
|
|
54
|
+
heading: { levels: [
|
|
55
|
+
1,
|
|
56
|
+
2,
|
|
57
|
+
3
|
|
58
|
+
] },
|
|
59
|
+
blockquote: !1,
|
|
60
|
+
code: !1,
|
|
61
|
+
codeBlock: !1,
|
|
62
|
+
horizontalRule: !1,
|
|
63
|
+
trailingNode: !1,
|
|
64
|
+
...t === "markdown" ? { underline: !1 } : {},
|
|
65
|
+
link: {
|
|
66
|
+
openOnClick: !1,
|
|
67
|
+
autolink: !1,
|
|
68
|
+
linkOnPaste: !1,
|
|
69
|
+
isAllowedUri: (e) => de(e),
|
|
70
|
+
HTMLAttributes: {
|
|
71
|
+
target: null,
|
|
72
|
+
rel: null
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}),
|
|
76
|
+
be.configure({
|
|
77
|
+
inline: !1,
|
|
78
|
+
allowBase64: !1
|
|
79
|
+
}),
|
|
80
|
+
v.configure({ placeholder: e }),
|
|
81
|
+
...t === "markdown" ? d(n) : []
|
|
82
|
+
], Se = (e, t) => e.isEmpty ? "" : t === "markdown" ? e.getMarkdown() : e.getHTML(), Ce = (e, t, n) => n === "markdown" ? f(e, t) : t, we = m.memo(({ onClick: e, active: t, disabled: n, title: r, tabIndex: i, onFocus: a, buttonRef: o, children: ee }) => /* @__PURE__ */ h("button", {
|
|
83
|
+
ref: o,
|
|
41
84
|
type: "button",
|
|
42
|
-
className:
|
|
85
|
+
className: fe(p.toolbarBtn, t && p.active),
|
|
43
86
|
onClick: e,
|
|
87
|
+
onFocus: a,
|
|
44
88
|
disabled: n,
|
|
45
89
|
title: r,
|
|
46
90
|
"aria-label": r,
|
|
47
91
|
"aria-pressed": t,
|
|
48
|
-
tabIndex:
|
|
49
|
-
children:
|
|
92
|
+
tabIndex: i,
|
|
93
|
+
children: ee
|
|
50
94
|
}));
|
|
51
|
-
|
|
52
|
-
var
|
|
53
|
-
let { t:
|
|
95
|
+
we.displayName = "ToolbarButton";
|
|
96
|
+
var y = ({ value: d, defaultValue: f = "", onChange: _, placeholder: v, disabled: ve, intent: be = "default", variant: y = "outline", fullWidth: b = !1, width: x, minHeight: S = 200, label: C, error: w, required: T, layout: Te, className: Ee, id: De, toolbar: E = ye, labels: Oe = {}, "aria-label": ke, "aria-labelledby": D, onImageUpload: O, format: Ae = "html" }) => {
|
|
97
|
+
let { t: k } = e("components"), { bold: je = k("a11y.rte_bold"), italic: Me = k("a11y.rte_italic"), underline: Ne = k("a11y.rte_underline"), strikethrough: Pe = k("a11y.rte_strikethrough"), h1: Fe = k("a11y.rte_h1"), h2: Ie = k("a11y.rte_h2"), h3: Le = k("a11y.rte_h3"), ul: Re = k("a11y.rte_ul"), ol: ze = k("a11y.rte_ol"), link: Be = k("a11y.rte_link"), unlink: Ve = k("a11y.rte_unlink"), removeFormat: He = k("a11y.rte_remove_format"), toolbar: Ue = k("a11y.rte_toolbar"), linkPrompt: We = k("a11y.rte_link_prompt"), linkApply: Ge = k("a11y.rte_link_apply"), linkCancel: Ke = k("a11y.rte_link_cancel"), linkInvalid: qe = k("a11y.rte_link_invalid"), image: Je = k("a11y.rte_image"), imageUrl: Ye = k("a11y.rte_image_url"), imageAlt: Xe = k("a11y.rte_image_alt"), imageAltHint: Ze = k("a11y.rte_image_alt_hint"), imageUpload: Qe = k("a11y.rte_image_upload"), imageUploadFailed: A = k("a11y.rte_image_upload_failed"), imageInvalid: $e = k("a11y.rte_image_invalid") } = Oe, et = m.useId(), j = De || `wim-rte-${et}`, M = w ? `${j}-error` : void 0, N = C ? `${j}-label` : void 0, P = !!ve, F = w ? "danger" : be, tt = typeof x == "string" && [
|
|
54
98
|
"xs",
|
|
55
99
|
"sm",
|
|
56
100
|
"md",
|
|
57
101
|
"lg",
|
|
58
102
|
"xl"
|
|
59
|
-
].includes(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let r = t[n];
|
|
74
|
-
N.current.innerHTML = r, F.current = r, _?.(r);
|
|
75
|
-
let i = document.createRange();
|
|
76
|
-
i.selectNodeContents(N.current), i.collapse(!1);
|
|
77
|
-
let a = window.getSelection();
|
|
78
|
-
a?.removeAllRanges(), a?.addRange(i), V();
|
|
103
|
+
].includes(x), nt = x !== void 0 && !tt && !b, I = tt && !b ? x : void 0, rt = I ? p[`width${I.charAt(0).toUpperCase()}${I.slice(1)}`] : void 0, L = m.useRef(d ?? f), it = m.useRef(_);
|
|
104
|
+
m.useEffect(() => {
|
|
105
|
+
it.current = _;
|
|
106
|
+
}, [_]);
|
|
107
|
+
let at = m.useMemo(() => {
|
|
108
|
+
let e = {
|
|
109
|
+
id: j,
|
|
110
|
+
class: p.content,
|
|
111
|
+
role: "textbox",
|
|
112
|
+
"aria-multiline": "true",
|
|
113
|
+
style: `min-height: ${typeof S == "number" ? `${S}px` : S}`,
|
|
114
|
+
tabindex: P ? "-1" : "0"
|
|
115
|
+
}, t = ke ?? (C || D ? void 0 : k("a11y.rte_editor")), n = D ?? (C ? N : void 0);
|
|
116
|
+
return t && (e["aria-label"] = t), n && (e["aria-labelledby"] = n), F === "danger" && (e["aria-invalid"] = "true"), M && (e["aria-describedby"] = M), T && (e["aria-required"] = "true"), P && (e["aria-disabled"] = "true"), v && (e["aria-placeholder"] = v), e;
|
|
79
117
|
}, [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
118
|
+
j,
|
|
119
|
+
S,
|
|
120
|
+
P,
|
|
121
|
+
ke,
|
|
122
|
+
C,
|
|
123
|
+
D,
|
|
124
|
+
N,
|
|
125
|
+
F,
|
|
126
|
+
M,
|
|
127
|
+
T,
|
|
128
|
+
v,
|
|
129
|
+
k
|
|
130
|
+
]), R = m.useRef(O);
|
|
131
|
+
m.useEffect(() => {
|
|
132
|
+
R.current = O;
|
|
133
|
+
}, [O]);
|
|
134
|
+
let [ot, st] = m.useState(void 0), ct = m.useRef(A);
|
|
135
|
+
m.useEffect(() => {
|
|
136
|
+
ct.current = A;
|
|
137
|
+
}, [A]);
|
|
138
|
+
let z = m.useCallback(async (e, t, n) => {
|
|
139
|
+
let r = R.current;
|
|
140
|
+
if (r) {
|
|
141
|
+
st(void 0);
|
|
142
|
+
for (let i of t) try {
|
|
143
|
+
let t = await r(i);
|
|
144
|
+
if (!u(t)) throw Error("URL not allowed");
|
|
145
|
+
if (e.isDestroyed) return;
|
|
146
|
+
let a = e.chain().focus();
|
|
147
|
+
(n === void 0 ? a : a.setTextSelection(n)).setImage({
|
|
148
|
+
src: t,
|
|
149
|
+
alt: ""
|
|
150
|
+
}).run();
|
|
151
|
+
} catch {
|
|
152
|
+
st(ct.current);
|
|
153
|
+
}
|
|
89
154
|
}
|
|
90
|
-
|
|
91
|
-
let
|
|
92
|
-
|
|
155
|
+
}, []), lt = (e) => Array.from(e ?? []).filter((e) => e.type.startsWith("image/")), B = m.useRef({ ed: null }), ut = m.useCallback((e, t) => {
|
|
156
|
+
let n = lt(t.clipboardData?.files), r = B.current.ed;
|
|
157
|
+
return !R.current || n.length === 0 || !r ? !1 : (t.preventDefault(), z(r, n), !0);
|
|
158
|
+
}, [z]), dt = m.useCallback((e, t, n, r) => {
|
|
159
|
+
let i = lt(t.dataTransfer?.files), a = B.current.ed;
|
|
160
|
+
if (r || !R.current || i.length === 0 || !a) return !1;
|
|
161
|
+
t.preventDefault();
|
|
162
|
+
let o = e.posAtCoords({
|
|
163
|
+
left: t.clientX,
|
|
164
|
+
top: t.clientY
|
|
165
|
+
});
|
|
166
|
+
return z(a, i, o?.pos), !0;
|
|
167
|
+
}, [z]), V = m.useMemo(() => ({
|
|
168
|
+
attributes: at,
|
|
169
|
+
handlePaste: ut,
|
|
170
|
+
handleDrop: dt
|
|
171
|
+
}), [
|
|
172
|
+
at,
|
|
173
|
+
ut,
|
|
174
|
+
dt
|
|
175
|
+
]), [H] = m.useState(Ae), ft = d ?? f, U = he({
|
|
176
|
+
extensions: xe(v ?? "", H, H === "markdown" ? ft : void 0),
|
|
177
|
+
content: H === "markdown" ? "" : ft,
|
|
178
|
+
editable: !P,
|
|
179
|
+
immediatelyRender: !1,
|
|
180
|
+
editorProps: V,
|
|
181
|
+
onUpdate: ({ editor: e }) => {
|
|
182
|
+
let t = Se(e, H);
|
|
183
|
+
t !== L.current && (L.current = t, it.current?.(t));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
m.useEffect(() => {
|
|
187
|
+
U && !U.isDestroyed && U.setOptions({ editorProps: V });
|
|
188
|
+
}, [U, V]), m.useEffect(() => {
|
|
189
|
+
B.current.ed = U;
|
|
190
|
+
}, [U]), m.useEffect(() => {
|
|
191
|
+
U && !U.isDestroyed && U.setEditable(!P, !1);
|
|
192
|
+
}, [U, P]), m.useEffect(() => {
|
|
193
|
+
if (!U || U.isDestroyed) return;
|
|
194
|
+
let e = U.extensionManager.extensions.find((e) => e.name === "placeholder");
|
|
195
|
+
e && e.options.placeholder !== (v ?? "") && (e.options.placeholder = v ?? "", U.view.dispatch(U.state.tr));
|
|
196
|
+
}, [U, v]), m.useEffect(() => {
|
|
197
|
+
if (!U || U.isDestroyed || d === void 0 || d === L.current || d === Se(U, H)) return;
|
|
198
|
+
L.current = d;
|
|
199
|
+
let e = _e(Ce(U, d, H), U.schema);
|
|
200
|
+
e.eq(U.state.doc) || U.commands.setContent(e.toJSON(), { emitUpdate: !1 });
|
|
201
|
+
}, [
|
|
202
|
+
U,
|
|
203
|
+
d,
|
|
204
|
+
H
|
|
205
|
+
]);
|
|
206
|
+
let pt = ge({
|
|
207
|
+
editor: U,
|
|
208
|
+
selector: ({ editor: e }) => ({
|
|
209
|
+
bold: !!e?.isActive("bold"),
|
|
210
|
+
italic: !!e?.isActive("italic"),
|
|
211
|
+
underline: !!e?.schema.marks.underline && e.isActive("underline"),
|
|
212
|
+
strikethrough: !!e?.isActive("strike"),
|
|
213
|
+
h1: !!e?.isActive("heading", { level: 1 }),
|
|
214
|
+
h2: !!e?.isActive("heading", { level: 2 }),
|
|
215
|
+
h3: !!e?.isActive("heading", { level: 3 }),
|
|
216
|
+
ul: !!e?.isActive("bulletList"),
|
|
217
|
+
ol: !!e?.isActive("orderedList"),
|
|
218
|
+
image: !!e?.isActive("image")
|
|
219
|
+
})
|
|
220
|
+
}), W = m.useCallback((e) => {
|
|
221
|
+
!P && U && e(U);
|
|
222
|
+
}, [U, P]), mt = m.useCallback(() => {
|
|
223
|
+
W((e) => {
|
|
224
|
+
let { from: t, to: n, empty: r } = e.state.selection, i = e.chain().focus();
|
|
225
|
+
r && i.selectAll(), i.unsetBold().unsetItalic().unsetStrike().clearNodes(), e.schema.marks.underline && i.unsetUnderline(), r && i.setTextSelection({
|
|
226
|
+
from: t,
|
|
227
|
+
to: n
|
|
228
|
+
}), i.run();
|
|
229
|
+
});
|
|
230
|
+
}, [W]), [ht, G] = m.useState(!1), [K, gt] = m.useState("https://"), [_t, q] = m.useState(void 0), vt = m.useCallback(() => {
|
|
231
|
+
if (P || !U) return;
|
|
232
|
+
let { from: e, to: t } = U.state.selection, n = U.state.doc.textBetween(e, t, " "), r = U.getAttributes("link").href;
|
|
233
|
+
gt(r ?? (n.startsWith("http") ? n : "https://")), q(void 0), G(!0);
|
|
234
|
+
}, [U, P]), yt = m.useCallback(() => {
|
|
235
|
+
let e = K.trim();
|
|
236
|
+
if (!e) {
|
|
237
|
+
G(!1);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (!de(e)) {
|
|
241
|
+
q(qe);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
G(!1), W((t) => {
|
|
245
|
+
t.state.selection.empty && !t.isActive("link") ? t.chain().focus().insertContent({
|
|
246
|
+
type: "text",
|
|
247
|
+
text: e,
|
|
248
|
+
marks: [{
|
|
249
|
+
type: "link",
|
|
250
|
+
attrs: { href: e }
|
|
251
|
+
}]
|
|
252
|
+
}).run() : t.chain().focus().extendMarkRange("link").setLink({ href: e }).run();
|
|
253
|
+
});
|
|
93
254
|
}, [
|
|
94
|
-
R,
|
|
95
255
|
K,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
let t = window.getSelection();
|
|
112
|
-
if (t?.removeAllRanges(), Z.current) t?.addRange(Z.current);
|
|
113
|
-
else {
|
|
114
|
-
let e = document.createRange();
|
|
115
|
-
e.selectNodeContents(N.current), e.collapse(!1), t?.addRange(e);
|
|
256
|
+
qe,
|
|
257
|
+
W
|
|
258
|
+
]), [bt, J] = m.useState(!1), [Y, xt] = m.useState(""), [St, Ct] = m.useState(""), [wt, X] = m.useState(void 0), [Tt, Et] = m.useState(!1), Dt = m.useRef(null), Ot = `${j}-image-alt-hint`, kt = m.useCallback(() => {
|
|
259
|
+
if (P || !U) return;
|
|
260
|
+
let e = U.isActive("image") ? U.getAttributes("image") : {};
|
|
261
|
+
xt(e.src ?? ""), Ct(e.alt ?? ""), X(void 0), J(!0);
|
|
262
|
+
}, [U, P]), At = m.useCallback(() => {
|
|
263
|
+
let e = Y.trim();
|
|
264
|
+
if (!e) {
|
|
265
|
+
J(!1);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (!u(e)) {
|
|
269
|
+
X($e);
|
|
270
|
+
return;
|
|
116
271
|
}
|
|
117
|
-
J((t) =>
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
e !== F.current && (F.current = e, _?.(e), W.current !== void 0 && clearTimeout(W.current), W.current = setTimeout(() => {
|
|
122
|
-
W.current = void 0, G(F.current);
|
|
123
|
-
}, 400)), V();
|
|
272
|
+
J(!1), W((t) => t.chain().focus().setImage({
|
|
273
|
+
src: e,
|
|
274
|
+
alt: St.trim()
|
|
275
|
+
}).run());
|
|
124
276
|
}, [
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}, [
|
|
277
|
+
Y,
|
|
278
|
+
St,
|
|
279
|
+
$e,
|
|
280
|
+
W
|
|
281
|
+
]), jt = m.useCallback(async (e) => {
|
|
282
|
+
let t = e.target.files?.[0];
|
|
283
|
+
if (e.target.value = "", t && O) {
|
|
284
|
+
Et(!0), X(void 0);
|
|
285
|
+
try {
|
|
286
|
+
let e = await O(t);
|
|
287
|
+
if (!u(e)) throw Error("URL not allowed");
|
|
288
|
+
xt(e);
|
|
289
|
+
} catch {
|
|
290
|
+
X(A);
|
|
291
|
+
} finally {
|
|
292
|
+
Et(!1);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}, [O, A]), Mt = m.useRef([]), [Z, Nt] = m.useState(0), Q = m.useMemo(() => {
|
|
296
|
+
let e = H === "markdown" ? E.filter((e) => e !== "underline") : E;
|
|
297
|
+
return e.filter((t, n) => t !== "separator" || n > 0 && n < e.length - 1 && e[n - 1] !== "separator");
|
|
298
|
+
}, [E, H]), $ = m.useMemo(() => Q.filter((e) => e !== "separator"), [Q]), Pt = m.useMemo(() => Q.map((e, t) => e === "separator" ? -1 : Q.slice(0, t).filter((e) => e !== "separator").length), [Q]), Ft = m.useCallback((e) => {
|
|
299
|
+
let t = $.length;
|
|
300
|
+
if (t === 0) return;
|
|
301
|
+
let n;
|
|
302
|
+
e.key === "ArrowRight" ? n = (Z + 1) % t : e.key === "ArrowLeft" ? n = (Z - 1 + t) % t : e.key === "Home" ? n = 0 : e.key === "End" && (n = t - 1), n !== void 0 && (e.preventDefault(), Nt(n), Mt.current[n]?.focus());
|
|
303
|
+
}, [$.length, Z]), It = m.useCallback((e) => {
|
|
144
304
|
e.preventDefault();
|
|
145
|
-
}, [])
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
children: /* @__PURE__ */ p(o, {
|
|
250
|
-
component: i,
|
|
251
|
-
size: "sm"
|
|
252
|
-
})
|
|
253
|
-
}, "link");
|
|
254
|
-
case "unlink": return /* @__PURE__ */ p(h, {
|
|
255
|
-
...c,
|
|
256
|
-
title: Ne,
|
|
257
|
-
onClick: () => J((e) => he(e)),
|
|
258
|
-
children: /* @__PURE__ */ p(o, {
|
|
259
|
-
component: re,
|
|
260
|
-
size: "sm"
|
|
261
|
-
})
|
|
262
|
-
}, "unlink");
|
|
263
|
-
case "removeFormat": return /* @__PURE__ */ p(h, {
|
|
264
|
-
...c,
|
|
265
|
-
title: Pe,
|
|
266
|
-
onClick: qe,
|
|
267
|
-
children: /* @__PURE__ */ p(o, {
|
|
268
|
-
component: n,
|
|
269
|
-
size: "sm"
|
|
270
|
-
})
|
|
271
|
-
}, "removeFormat");
|
|
272
|
-
default: return null;
|
|
305
|
+
}, []), Lt = {
|
|
306
|
+
bold: {
|
|
307
|
+
title: je,
|
|
308
|
+
icon: /* @__PURE__ */ h(s, {
|
|
309
|
+
component: t,
|
|
310
|
+
size: "sm"
|
|
311
|
+
}),
|
|
312
|
+
onClick: () => W((e) => e.chain().focus().toggleBold().run())
|
|
313
|
+
},
|
|
314
|
+
italic: {
|
|
315
|
+
title: Me,
|
|
316
|
+
icon: /* @__PURE__ */ h(s, {
|
|
317
|
+
component: i,
|
|
318
|
+
size: "sm"
|
|
319
|
+
}),
|
|
320
|
+
onClick: () => W((e) => e.chain().focus().toggleItalic().run())
|
|
321
|
+
},
|
|
322
|
+
underline: {
|
|
323
|
+
title: Ne,
|
|
324
|
+
icon: /* @__PURE__ */ h(s, {
|
|
325
|
+
component: ne,
|
|
326
|
+
size: "sm"
|
|
327
|
+
}),
|
|
328
|
+
onClick: () => W((e) => e.chain().focus().toggleUnderline().run())
|
|
329
|
+
},
|
|
330
|
+
strikethrough: {
|
|
331
|
+
title: Pe,
|
|
332
|
+
icon: /* @__PURE__ */ h(s, {
|
|
333
|
+
component: te,
|
|
334
|
+
size: "sm"
|
|
335
|
+
}),
|
|
336
|
+
onClick: () => W((e) => e.chain().focus().toggleStrike().run())
|
|
337
|
+
},
|
|
338
|
+
h1: {
|
|
339
|
+
title: Fe,
|
|
340
|
+
icon: /* @__PURE__ */ h("span", {
|
|
341
|
+
"aria-hidden": "true",
|
|
342
|
+
children: "H1"
|
|
343
|
+
}),
|
|
344
|
+
onClick: () => W((e) => e.chain().focus().toggleHeading({ level: 1 }).run())
|
|
345
|
+
},
|
|
346
|
+
h2: {
|
|
347
|
+
title: Ie,
|
|
348
|
+
icon: /* @__PURE__ */ h("span", {
|
|
349
|
+
"aria-hidden": "true",
|
|
350
|
+
children: "H2"
|
|
351
|
+
}),
|
|
352
|
+
onClick: () => W((e) => e.chain().focus().toggleHeading({ level: 2 }).run())
|
|
353
|
+
},
|
|
354
|
+
h3: {
|
|
355
|
+
title: Le,
|
|
356
|
+
icon: /* @__PURE__ */ h("span", {
|
|
357
|
+
"aria-hidden": "true",
|
|
358
|
+
children: "H3"
|
|
359
|
+
}),
|
|
360
|
+
onClick: () => W((e) => e.chain().focus().toggleHeading({ level: 3 }).run())
|
|
361
|
+
},
|
|
362
|
+
ul: {
|
|
363
|
+
title: Re,
|
|
364
|
+
icon: /* @__PURE__ */ h(s, {
|
|
365
|
+
component: ee,
|
|
366
|
+
size: "sm"
|
|
367
|
+
}),
|
|
368
|
+
onClick: () => W((e) => e.chain().focus().toggleBulletList().run())
|
|
369
|
+
},
|
|
370
|
+
ol: {
|
|
371
|
+
title: ze,
|
|
372
|
+
icon: /* @__PURE__ */ h(s, {
|
|
373
|
+
component: o,
|
|
374
|
+
size: "sm"
|
|
375
|
+
}),
|
|
376
|
+
onClick: () => W((e) => e.chain().focus().toggleOrderedList().run())
|
|
377
|
+
},
|
|
378
|
+
link: {
|
|
379
|
+
title: Be,
|
|
380
|
+
icon: /* @__PURE__ */ h(s, {
|
|
381
|
+
component: a,
|
|
382
|
+
size: "sm"
|
|
383
|
+
}),
|
|
384
|
+
onClick: vt
|
|
385
|
+
},
|
|
386
|
+
unlink: {
|
|
387
|
+
title: Ve,
|
|
388
|
+
icon: /* @__PURE__ */ h(s, {
|
|
389
|
+
component: re,
|
|
390
|
+
size: "sm"
|
|
391
|
+
}),
|
|
392
|
+
onClick: () => W((e) => e.chain().focus().extendMarkRange("link").unsetLink().run())
|
|
393
|
+
},
|
|
394
|
+
image: {
|
|
395
|
+
title: Je,
|
|
396
|
+
icon: /* @__PURE__ */ h(s, {
|
|
397
|
+
component: r,
|
|
398
|
+
size: "sm"
|
|
399
|
+
}),
|
|
400
|
+
onClick: kt
|
|
401
|
+
},
|
|
402
|
+
removeFormat: {
|
|
403
|
+
title: He,
|
|
404
|
+
icon: /* @__PURE__ */ h(s, {
|
|
405
|
+
component: n,
|
|
406
|
+
size: "sm"
|
|
407
|
+
}),
|
|
408
|
+
onClick: mt
|
|
273
409
|
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
M,
|
|
287
|
-
Ne,
|
|
288
|
-
Pe,
|
|
289
|
-
J,
|
|
290
|
-
Q,
|
|
291
|
-
qe
|
|
292
|
-
]);
|
|
293
|
-
return /* @__PURE__ */ p(c, {
|
|
294
|
-
label: x,
|
|
295
|
-
error: S,
|
|
296
|
-
required: C,
|
|
297
|
-
layout: we,
|
|
298
|
-
labelId: He,
|
|
299
|
-
errorId: Ve,
|
|
300
|
-
className: Te,
|
|
301
|
-
children: /* @__PURE__ */ m("div", {
|
|
302
|
-
className: _e("wim-rich-text-editor", d.root, d[Ue], R && d.disabled, d[Ce], v && d.fullWidth, Ge && d.hasCustomWidth, Ke),
|
|
303
|
-
style: Ge ? { "--wim-input-width": typeof y == "number" ? `${y}px` : y } : void 0,
|
|
410
|
+
};
|
|
411
|
+
return /* @__PURE__ */ h(ie, {
|
|
412
|
+
label: C,
|
|
413
|
+
error: w,
|
|
414
|
+
required: T,
|
|
415
|
+
layout: Te,
|
|
416
|
+
labelId: N,
|
|
417
|
+
errorId: M,
|
|
418
|
+
className: Ee,
|
|
419
|
+
children: /* @__PURE__ */ g("div", {
|
|
420
|
+
className: fe("wim-rich-text-editor", p.root, p[F], P && p.disabled, p[y], b && p.fullWidth, nt && p.hasCustomWidth, rt),
|
|
421
|
+
style: nt ? { "--wim-input-width": typeof x == "number" ? `${x}px` : x } : void 0,
|
|
304
422
|
children: [
|
|
305
|
-
/* @__PURE__ */
|
|
306
|
-
className:
|
|
423
|
+
/* @__PURE__ */ h("div", {
|
|
424
|
+
className: p.toolbar,
|
|
307
425
|
role: "toolbar",
|
|
308
|
-
"aria-label":
|
|
309
|
-
"aria-controls":
|
|
310
|
-
onMouseDown:
|
|
311
|
-
|
|
426
|
+
"aria-label": Ue,
|
|
427
|
+
"aria-controls": j,
|
|
428
|
+
onMouseDown: It,
|
|
429
|
+
onKeyDown: Ft,
|
|
430
|
+
children: Q.map((e, t) => {
|
|
431
|
+
if (e === "separator") return /* @__PURE__ */ h("span", {
|
|
432
|
+
className: p.toolbarSep,
|
|
433
|
+
"aria-hidden": "true"
|
|
434
|
+
}, `sep-${t}`);
|
|
435
|
+
let n = Pt[t], r = Lt[e], i = e === "link" || e === "unlink" || e === "removeFormat" ? void 0 : pt?.[e] ?? !1;
|
|
436
|
+
return /* @__PURE__ */ h(we, {
|
|
437
|
+
buttonRef: (e) => {
|
|
438
|
+
Mt.current[n] = e;
|
|
439
|
+
},
|
|
440
|
+
tabIndex: n === Math.min(Z, $.length - 1) ? 0 : -1,
|
|
441
|
+
onFocus: () => Nt(n),
|
|
442
|
+
disabled: P,
|
|
443
|
+
active: i,
|
|
444
|
+
title: r.title,
|
|
445
|
+
onClick: r.onClick,
|
|
446
|
+
children: r.icon
|
|
447
|
+
}, `${e}-${t}`);
|
|
448
|
+
})
|
|
312
449
|
}),
|
|
313
|
-
/* @__PURE__ */
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
className: d.content,
|
|
317
|
-
contentEditable: !R,
|
|
318
|
-
suppressContentEditableWarning: !0,
|
|
319
|
-
role: "textbox",
|
|
320
|
-
"aria-multiline": !0,
|
|
321
|
-
"aria-label": ke ?? (x || w ? void 0 : T("a11y.rte_editor")),
|
|
322
|
-
"aria-labelledby": w ?? (x ? He : void 0),
|
|
323
|
-
"aria-invalid": Ue === "danger",
|
|
324
|
-
"aria-describedby": Ve,
|
|
325
|
-
"aria-required": C,
|
|
326
|
-
"aria-disabled": R,
|
|
327
|
-
"aria-placeholder": be,
|
|
328
|
-
"data-placeholder": be,
|
|
329
|
-
tabIndex: R ? -1 : 0,
|
|
330
|
-
style: {
|
|
331
|
-
minHeight: typeof b == "number" ? `${b}px` : b,
|
|
332
|
-
outline: "none"
|
|
333
|
-
},
|
|
334
|
-
onInput: $,
|
|
335
|
-
onBeforeInput: Ze,
|
|
336
|
-
onKeyDown: Qe,
|
|
337
|
-
onKeyUp: $e,
|
|
338
|
-
onMouseUp: et,
|
|
339
|
-
onCompositionStart: tt,
|
|
340
|
-
onCompositionEnd: nt
|
|
450
|
+
/* @__PURE__ */ h(me, {
|
|
451
|
+
editor: U,
|
|
452
|
+
className: p.contentHost
|
|
341
453
|
}),
|
|
342
|
-
/* @__PURE__ */ p
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
children:
|
|
454
|
+
ot && /* @__PURE__ */ h("p", {
|
|
455
|
+
role: "alert",
|
|
456
|
+
className: p.uploadError,
|
|
457
|
+
children: ot
|
|
458
|
+
}),
|
|
459
|
+
/* @__PURE__ */ h(ae, {
|
|
460
|
+
open: ht,
|
|
461
|
+
onOpenChange: G,
|
|
462
|
+
children: /* @__PURE__ */ g(se, { children: [/* @__PURE__ */ h(le, { children: /* @__PURE__ */ h(ue, { children: Be }) }), /* @__PURE__ */ g("form", {
|
|
346
463
|
onSubmit: (e) => {
|
|
347
|
-
e.preventDefault(),
|
|
464
|
+
e.preventDefault(), yt();
|
|
348
465
|
},
|
|
349
|
-
children: [/* @__PURE__ */
|
|
350
|
-
label:
|
|
466
|
+
children: [/* @__PURE__ */ h(l, {
|
|
467
|
+
label: We,
|
|
351
468
|
type: "url",
|
|
352
|
-
value:
|
|
353
|
-
|
|
469
|
+
value: K,
|
|
470
|
+
error: _t,
|
|
471
|
+
onChange: (e) => {
|
|
472
|
+
gt(e.target.value), q(void 0);
|
|
473
|
+
},
|
|
354
474
|
fullWidth: !0
|
|
355
|
-
}), /* @__PURE__ */
|
|
475
|
+
}), /* @__PURE__ */ g(ce, { children: [/* @__PURE__ */ h(oe, {
|
|
356
476
|
asChild: !0,
|
|
357
|
-
children: /* @__PURE__ */
|
|
477
|
+
children: /* @__PURE__ */ h(c, {
|
|
358
478
|
variant: "ghost",
|
|
359
479
|
type: "button",
|
|
360
|
-
children:
|
|
480
|
+
children: Ke
|
|
361
481
|
})
|
|
362
|
-
}), /* @__PURE__ */
|
|
482
|
+
}), /* @__PURE__ */ h(c, {
|
|
363
483
|
variant: "solid",
|
|
364
484
|
type: "submit",
|
|
365
|
-
children:
|
|
485
|
+
children: Ge
|
|
366
486
|
})] })]
|
|
367
487
|
})] })
|
|
488
|
+
}),
|
|
489
|
+
/* @__PURE__ */ h(ae, {
|
|
490
|
+
open: bt,
|
|
491
|
+
onOpenChange: J,
|
|
492
|
+
children: /* @__PURE__ */ g(se, { children: [/* @__PURE__ */ h(le, { children: /* @__PURE__ */ h(ue, { children: Je }) }), /* @__PURE__ */ g("form", {
|
|
493
|
+
className: p.imageForm,
|
|
494
|
+
onSubmit: (e) => {
|
|
495
|
+
e.preventDefault(), At();
|
|
496
|
+
},
|
|
497
|
+
children: [
|
|
498
|
+
/* @__PURE__ */ h(l, {
|
|
499
|
+
label: Ye,
|
|
500
|
+
type: "url",
|
|
501
|
+
value: Y,
|
|
502
|
+
error: wt,
|
|
503
|
+
onChange: (e) => {
|
|
504
|
+
xt(e.target.value), X(void 0);
|
|
505
|
+
},
|
|
506
|
+
fullWidth: !0
|
|
507
|
+
}),
|
|
508
|
+
O && /* @__PURE__ */ g(pe, { children: [/* @__PURE__ */ h("input", {
|
|
509
|
+
ref: Dt,
|
|
510
|
+
type: "file",
|
|
511
|
+
accept: "image/*",
|
|
512
|
+
hidden: !0,
|
|
513
|
+
onChange: jt
|
|
514
|
+
}), /* @__PURE__ */ h(c, {
|
|
515
|
+
type: "button",
|
|
516
|
+
variant: "outline",
|
|
517
|
+
loading: Tt,
|
|
518
|
+
onClick: () => Dt.current?.click(),
|
|
519
|
+
children: Qe
|
|
520
|
+
})] }),
|
|
521
|
+
/* @__PURE__ */ g("div", { children: [/* @__PURE__ */ h(l, {
|
|
522
|
+
label: Xe,
|
|
523
|
+
"aria-describedby": Ot,
|
|
524
|
+
value: St,
|
|
525
|
+
onChange: (e) => Ct(e.target.value),
|
|
526
|
+
fullWidth: !0
|
|
527
|
+
}), /* @__PURE__ */ h("p", {
|
|
528
|
+
id: Ot,
|
|
529
|
+
className: p.imageHint,
|
|
530
|
+
children: Ze
|
|
531
|
+
})] }),
|
|
532
|
+
/* @__PURE__ */ g(ce, { children: [/* @__PURE__ */ h(oe, {
|
|
533
|
+
asChild: !0,
|
|
534
|
+
children: /* @__PURE__ */ h(c, {
|
|
535
|
+
variant: "ghost",
|
|
536
|
+
type: "button",
|
|
537
|
+
children: Ke
|
|
538
|
+
})
|
|
539
|
+
}), /* @__PURE__ */ h(c, {
|
|
540
|
+
variant: "solid",
|
|
541
|
+
type: "submit",
|
|
542
|
+
disabled: Tt,
|
|
543
|
+
children: Ge
|
|
544
|
+
})] })
|
|
545
|
+
]
|
|
546
|
+
})] })
|
|
368
547
|
})
|
|
369
548
|
]
|
|
370
549
|
})
|
|
371
550
|
});
|
|
372
551
|
};
|
|
373
|
-
|
|
552
|
+
y.displayName = "RichTextEditor";
|
|
374
553
|
//#endregion
|
|
375
|
-
export {
|
|
554
|
+
export { y as RichTextEditor };
|