wimui 0.42.0 → 0.44.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.
Files changed (53) hide show
  1. package/README.ja.md +3 -2
  2. package/README.md +3 -2
  3. package/dist/components/data-display/PivotTable/PivotTable.cjs +2 -0
  4. package/dist/components/data-display/PivotTable/PivotTable.d.ts +76 -0
  5. package/dist/components/data-display/PivotTable/PivotTable.js +104 -0
  6. package/dist/components/data-display/PivotTable/layoutPivot.cjs +2 -0
  7. package/dist/components/data-display/PivotTable/layoutPivot.d.ts +62 -0
  8. package/dist/components/data-display/PivotTable/layoutPivot.js +67 -0
  9. package/dist/components/data-display/PivotTable/pivot-table.module.cjs +2 -0
  10. package/dist/components/data-display/PivotTable/pivot-table.module.js +19 -0
  11. package/dist/components/feedback/Snackbar/snackbar.module.cjs +1 -1
  12. package/dist/components/feedback/Snackbar/snackbar.module.js +7 -7
  13. package/dist/components/form/ImageCropper/ImageCropper.cjs +1 -1
  14. package/dist/components/form/ImageCropper/ImageCropper.js +10 -10
  15. package/dist/components/form/RichTextEditor/RichTextEditor.cjs +1 -1
  16. package/dist/components/form/RichTextEditor/RichTextEditor.d.ts +36 -6
  17. package/dist/components/form/RichTextEditor/RichTextEditor.js +486 -307
  18. package/dist/components/form/RichTextEditor/markdown.cjs +3 -0
  19. package/dist/components/form/RichTextEditor/markdown.d.ts +19 -0
  20. package/dist/components/form/RichTextEditor/markdown.js +63 -0
  21. package/dist/components/form/RichTextEditor/rich-text-editor.module.cjs +1 -1
  22. package/dist/components/form/RichTextEditor/rich-text-editor.module.js +7 -3
  23. package/dist/components/form/RichTextEditor/safeUrl.cjs +2 -0
  24. package/dist/components/form/RichTextEditor/safeUrl.d.ts +4 -0
  25. package/dist/components/form/RichTextEditor/safeUrl.js +18 -0
  26. package/dist/data-display-core.d.ts +1 -0
  27. package/dist/data-display.cjs +1 -1
  28. package/dist/data-display.js +17 -16
  29. package/dist/form/rich-text-editor.cjs +2 -0
  30. package/dist/form/rich-text-editor.d.ts +1 -0
  31. package/dist/form/rich-text-editor.js +3 -0
  32. package/dist/form.cjs +1 -1
  33. package/dist/form.d.ts +0 -1
  34. package/dist/form.js +28 -29
  35. package/dist/i18n/generated/keys.d.ts +1 -1
  36. package/dist/i18n/generated/resources.cjs +1 -1
  37. package/dist/i18n/generated/resources.js +31 -4
  38. package/dist/index.cjs +1 -1
  39. package/dist/index.js +85 -85
  40. package/dist/llms-full.txt +23 -5
  41. package/dist/llms.txt +2 -1
  42. package/dist/locales/en/components.json +13 -1
  43. package/dist/locales/ja/components.json +13 -1
  44. package/dist/locales/pt/components.json +13 -1
  45. package/dist/overlay.cjs +1 -1
  46. package/dist/overlay.js +3 -3
  47. package/dist/styles.css +1 -1
  48. package/dist/wimui.umd.css +1 -1
  49. package/dist/wimui.umd.js +5 -5
  50. package/package.json +66 -1
  51. package/dist/components/form/RichTextEditor/commands.cjs +0 -2
  52. package/dist/components/form/RichTextEditor/commands.d.ts +0 -49
  53. 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/italic.js";
6
- import i from "../../../icon/link.js";
7
- import a from "../../../icon/list-ordered.js";
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 o } from "../../media/Icon/Icon.js";
13
- import { Button as s } from "../Button/Button.js";
14
- import { FieldTemplate as c } from "../FieldTemplate/FieldTemplate.js";
15
- import { Input as ie } from "../Input/Input.js";
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 { createLink as de, getActiveFormats as fe, getEditorRange as pe, removeAllFormatting as me, removeLink as he, setBlock as l, toggleInline as u, toggleList as ge } from "./commands.js";
18
- import d from "./rich-text-editor.module.js";
19
- import f from "react";
20
- import _e from "classnames";
21
- import { jsx as p, jsxs as m } from "react/jsx-runtime";
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 ve = [
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
- ], h = f.memo(({ onClick: e, active: t, disabled: n, title: r, children: i }) => /* @__PURE__ */ p("button", {
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: _e(d.toolbarBtn, t && d.active),
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: -1,
49
- children: i
92
+ tabIndex: i,
93
+ children: ee
50
94
  }));
51
- h.displayName = "ToolbarButton";
52
- var g = ({ value: g, defaultValue: ye = "", onChange: _, placeholder: be, disabled: xe, intent: Se = "default", variant: Ce = "outline", fullWidth: v = !1, width: y, minHeight: b = 200, label: x, error: S, required: C, layout: we, className: Te, id: Ee, toolbar: De = ve, labels: Oe = {}, "aria-label": ke, "aria-labelledby": w }) => {
53
- let { t: T } = e("components"), { bold: E = T("a11y.rte_bold"), italic: D = T("a11y.rte_italic"), underline: O = T("a11y.rte_underline"), strikethrough: k = T("a11y.rte_strikethrough"), h1: A = T("a11y.rte_h1"), h2: j = T("a11y.rte_h2"), h3: Ae = T("a11y.rte_h3"), ul: je = T("a11y.rte_ul"), ol: Me = T("a11y.rte_ol"), link: M = T("a11y.rte_link"), unlink: Ne = T("a11y.rte_unlink"), removeFormat: Pe = T("a11y.rte_remove_format"), toolbar: Fe = T("a11y.rte_toolbar"), linkPrompt: Ie = T("a11y.rte_link_prompt"), linkApply: Le = T("a11y.rte_link_apply"), linkCancel: Re = T("a11y.rte_link_cancel") } = Oe, N = f.useRef(null), P = f.useRef(!1), F = f.useRef(g ?? ye), [I, ze] = f.useState(/* @__PURE__ */ new Set()), Be = f.useId(), L = Ee || `wim-rte-${Be}`, Ve = S ? `${L}-error` : void 0, He = x ? `${L}-label` : void 0, R = xe, Ue = S ? "danger" : Se, We = typeof y == "string" && [
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(y), Ge = y !== void 0 && !We && !v, z = We && !v ? y : void 0, Ke = z ? d[`width${z.charAt(0).toUpperCase()}${z.slice(1)}`] : void 0, B = f.useRef(g === void 0 ? ye : g), V = f.useCallback(() => {
60
- N.current && ze(fe(N.current));
61
- }, []), H = f.useRef([]), U = f.useRef(-1), W = f.useRef(void 0), G = f.useCallback((e) => {
62
- let t = H.current, n = U.current;
63
- if (t[n] === e) return;
64
- let r = [...t.slice(0, n + 1), e];
65
- r.length > 100 && (r = r.slice(1)), H.current = r, U.current = r.length - 1;
66
- }, []), K = f.useCallback(() => {
67
- W.current !== void 0 && (clearTimeout(W.current), W.current = void 0, G(F.current));
68
- }, [G]), q = f.useCallback((e) => {
69
- K();
70
- let t = H.current, n = U.current + e;
71
- if (n < 0 || n >= t.length || !N.current) return;
72
- U.current = n;
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
- K,
81
- _,
82
- V
83
- ]), J = f.useCallback((e) => {
84
- if (R || !N.current) return;
85
- let t = N.current, n = pe(t)?.cloneRange() ?? null;
86
- if (t.focus(), n) {
87
- let e = window.getSelection();
88
- e?.removeAllRanges(), e?.addRange(n);
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
- K(), G(t.innerHTML), e(t), V();
91
- let r = t.innerHTML;
92
- F.current = r, G(r), _?.(r);
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
- G,
97
- _,
98
- V
99
- ]), qe = f.useCallback(() => {
100
- J((e) => me(e));
101
- }, [J]), [Je, Y] = f.useState(!1), [X, Ye] = f.useState("https://"), Z = f.useRef(null), Q = f.useCallback(() => {
102
- if (R || !N.current) return;
103
- N.current.focus();
104
- let e = pe(N.current);
105
- Z.current = e ? e.cloneRange() : null;
106
- let t = e?.toString() ?? "";
107
- Ye(t.startsWith("http") ? t : "https://"), Y(!0);
108
- }, [R]), Xe = f.useCallback(() => {
109
- let e = X.trim();
110
- if (Y(!1), !e || !N.current) return;
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) => de(t, e));
118
- }, [X, J]), $ = f.useCallback(() => {
119
- if (P.current) return;
120
- let e = N.current?.innerHTML ?? "";
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
- G,
127
- V
128
- ]), Ze = f.useCallback((e) => {
129
- let t = e.nativeEvent.inputType;
130
- t === "historyUndo" ? (e.preventDefault(), q(-1)) : t === "historyRedo" && (e.preventDefault(), q(1));
131
- }, [q]), Qe = f.useCallback((e) => {
132
- if (!(e.ctrlKey || e.metaKey)) return;
133
- let t = e.key.toLowerCase();
134
- t === "z" ? (e.preventDefault(), q(e.shiftKey ? 1 : -1)) : t === "y" && (e.preventDefault(), q(1));
135
- }, [q]), $e = f.useCallback(() => {
136
- V();
137
- }, [V]), et = f.useCallback(() => {
138
- V();
139
- }, [V]), tt = f.useCallback(() => {
140
- P.current = !0;
141
- }, []), nt = f.useCallback(() => {
142
- P.current = !1, $();
143
- }, [$]), rt = f.useCallback((e) => {
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
- f.useEffect(() => {
147
- N.current && (N.current.innerHTML = B.current, F.current = B.current, H.current = [B.current], U.current = 0);
148
- }, []), f.useEffect(() => {
149
- g !== void 0 && N.current && N.current.innerHTML !== g && (N.current.innerHTML = g, F.current = g);
150
- }, [g]);
151
- let it = f.useCallback((e, s) => {
152
- if (e === "separator") return /* @__PURE__ */ p("span", {
153
- className: d.toolbarSep,
154
- "aria-hidden": "true"
155
- }, `sep-${s}`);
156
- let c = {
157
- disabled: R,
158
- active: I.has(e)
159
- };
160
- switch (e) {
161
- case "bold": return /* @__PURE__ */ p(h, {
162
- ...c,
163
- title: E,
164
- onClick: () => J((e) => u(e, "bold")),
165
- children: /* @__PURE__ */ p(o, {
166
- component: t,
167
- size: "sm"
168
- })
169
- }, "bold");
170
- case "italic": return /* @__PURE__ */ p(h, {
171
- ...c,
172
- title: D,
173
- onClick: () => J((e) => u(e, "italic")),
174
- children: /* @__PURE__ */ p(o, {
175
- component: r,
176
- size: "sm"
177
- })
178
- }, "italic");
179
- case "underline": return /* @__PURE__ */ p(h, {
180
- ...c,
181
- title: O,
182
- onClick: () => J((e) => u(e, "underline")),
183
- children: /* @__PURE__ */ p(o, {
184
- component: ne,
185
- size: "sm"
186
- })
187
- }, "underline");
188
- case "strikethrough": return /* @__PURE__ */ p(h, {
189
- ...c,
190
- title: k,
191
- onClick: () => J((e) => u(e, "strikethrough")),
192
- children: /* @__PURE__ */ p(o, {
193
- component: te,
194
- size: "sm"
195
- })
196
- }, "strikethrough");
197
- case "h1": return /* @__PURE__ */ p(h, {
198
- ...c,
199
- active: I.has("h1"),
200
- title: A,
201
- onClick: () => J((e) => l(e, "h1")),
202
- children: /* @__PURE__ */ p("span", {
203
- "aria-hidden": "true",
204
- children: "H1"
205
- })
206
- }, "h1");
207
- case "h2": return /* @__PURE__ */ p(h, {
208
- ...c,
209
- active: I.has("h2"),
210
- title: j,
211
- onClick: () => J((e) => l(e, "h2")),
212
- children: /* @__PURE__ */ p("span", {
213
- "aria-hidden": "true",
214
- children: "H2"
215
- })
216
- }, "h2");
217
- case "h3": return /* @__PURE__ */ p(h, {
218
- ...c,
219
- active: I.has("h3"),
220
- title: Ae,
221
- onClick: () => J((e) => l(e, "h3")),
222
- children: /* @__PURE__ */ p("span", {
223
- "aria-hidden": "true",
224
- children: "H3"
225
- })
226
- }, "h3");
227
- case "ul": return /* @__PURE__ */ p(h, {
228
- ...c,
229
- title: je,
230
- onClick: () => J((e) => ge(e, "ul")),
231
- children: /* @__PURE__ */ p(o, {
232
- component: ee,
233
- size: "sm"
234
- })
235
- }, "ul");
236
- case "ol": return /* @__PURE__ */ p(h, {
237
- ...c,
238
- title: Me,
239
- onClick: () => J((e) => ge(e, "ol")),
240
- children: /* @__PURE__ */ p(o, {
241
- component: a,
242
- size: "sm"
243
- })
244
- }, "ol");
245
- case "link": return /* @__PURE__ */ p(h, {
246
- ...c,
247
- title: M,
248
- onClick: Q,
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
- I,
276
- R,
277
- E,
278
- D,
279
- O,
280
- k,
281
- A,
282
- j,
283
- Ae,
284
- je,
285
- Me,
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__ */ p("div", {
306
- className: d.toolbar,
423
+ /* @__PURE__ */ h("div", {
424
+ className: p.toolbar,
307
425
  role: "toolbar",
308
- "aria-label": Fe,
309
- "aria-controls": L,
310
- onMouseDown: rt,
311
- children: De.map((e, t) => it(e, t))
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__ */ p("div", {
314
- ref: N,
315
- id: L,
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(ae, {
343
- open: Je,
344
- onOpenChange: Y,
345
- children: /* @__PURE__ */ m(se, { children: [/* @__PURE__ */ p(le, { children: /* @__PURE__ */ p(ue, { children: M }) }), /* @__PURE__ */ m("form", {
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(), Xe();
464
+ e.preventDefault(), yt();
348
465
  },
349
- children: [/* @__PURE__ */ p(ie, {
350
- label: Ie,
466
+ children: [/* @__PURE__ */ h(l, {
467
+ label: We,
351
468
  type: "url",
352
- value: X,
353
- onChange: (e) => Ye(e.target.value),
469
+ value: K,
470
+ error: _t,
471
+ onChange: (e) => {
472
+ gt(e.target.value), q(void 0);
473
+ },
354
474
  fullWidth: !0
355
- }), /* @__PURE__ */ m(ce, { children: [/* @__PURE__ */ p(oe, {
475
+ }), /* @__PURE__ */ g(ce, { children: [/* @__PURE__ */ h(oe, {
356
476
  asChild: !0,
357
- children: /* @__PURE__ */ p(s, {
477
+ children: /* @__PURE__ */ h(c, {
358
478
  variant: "ghost",
359
479
  type: "button",
360
- children: Re
480
+ children: Ke
361
481
  })
362
- }), /* @__PURE__ */ p(s, {
482
+ }), /* @__PURE__ */ h(c, {
363
483
  variant: "solid",
364
484
  type: "submit",
365
- children: Le
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
- g.displayName = "RichTextEditor";
552
+ y.displayName = "RichTextEditor";
374
553
  //#endregion
375
- export { g as RichTextEditor };
554
+ export { y as RichTextEditor };