@alixpartners/ui-components 2.5.2 → 2.5.3

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.
@@ -0,0 +1,412 @@
1
+ import { jsxs as c, jsx as n } from "react/jsx-runtime";
2
+ import { c as f } from "./clsx-OuTLNxxd.js";
3
+ import { useMemo as be, useId as De, useRef as F, useState as d, useEffect as D } from "react";
4
+ import Ae from "./components/Dialog/Dialog.js";
5
+ import A from "./components/Icon/Icon.js";
6
+ import Te from "./components/Input/Input.js";
7
+ import J from "./components/Tooltip/Tooltip.js";
8
+ import { R as Be, T as Ie, P as Pe, C as je } from "./index-DZ4Gof57.js";
9
+ import './assets/RichTextEditor.css';const Ue = "RichTextEditor-module__container___AplP0", ze = "RichTextEditor-module__label___vjzs-", qe = "RichTextEditor-module__required___7duke", $e = "RichTextEditor-module__frame___7OSyf", We = "RichTextEditor-module__frameFocused___GtJ2x", Ke = "RichTextEditor-module__frameDisabled___LubtU", Ve = "RichTextEditor-module__frameError___sPTiY", Je = "RichTextEditor-module__errorMessage___4VdKj", Ge = "RichTextEditor-module__helpers___cpuz6", Ye = "RichTextEditor-module__helperText___rFoU0", Xe = "RichTextEditor-module__helpLink___7gYcv", Ze = "RichTextEditor-module__containerDisabled___6h9dd", Qe = "RichTextEditor-module__containerFullWidth___pOoeL", et = "RichTextEditor-module__toolbarContent___YXKHD", tt = "RichTextEditor-module__toolbarPanel___OVGHO", nt = "RichTextEditor-module__toolbarRow___f0xJR", ot = "RichTextEditor-module__toolbar___m9-M-", rt = "RichTextEditor-module__toolbarStacked___6rB10", it = "RichTextEditor-module__actions___ZAK9J", at = "RichTextEditor-module__toolButton___IT2Kg", lt = "RichTextEditor-module__toolButtonActive___-HvZQ", ct = "RichTextEditor-module__toolIcon___Wndhd", st = "RichTextEditor-module__formatControl___w4WcA", dt = "RichTextEditor-module__toolbarLinkSlot___Gu-9l", ut = "RichTextEditor-module__selectTrigger___frv3x", mt = "RichTextEditor-module__selectTriggerOpen___tk2Pb", _t = "RichTextEditor-module__selectTriggerLabel___FkEv0", pt = "RichTextEditor-module__selectIcon___aJWUk", ht = "RichTextEditor-module__formatMenu___y-uBL", ft = "RichTextEditor-module__formatMenuOptions___zcdlo", gt = "RichTextEditor-module__formatMenuOption___3ppTs", bt = "RichTextEditor-module__formatMenuOptionSelected___bq9J9", Tt = "RichTextEditor-module__formatMenuOptionParagraph___4BLds", xt = "RichTextEditor-module__formatMenuOptionHeading1___H1cKX", Rt = "RichTextEditor-module__formatMenuOptionHeading2___JdixR", Et = "RichTextEditor-module__formatMenuOptionHeading3___NcwLr", Mt = "RichTextEditor-module__formatMenuOptionHeading4___4mLbG", vt = "RichTextEditor-module__formatMenuOptionPreformatted___cB0Ix", Ct = "RichTextEditor-module__editor___M32R7", kt = "RichTextEditor-module__wordCount___5SSVY", Ot = "RichTextEditor-module__wordCountExceeded___NhqBc", yt = "RichTextEditor-module__linkDialogForm___vOLO1", t = {
10
+ container: Ue,
11
+ label: ze,
12
+ required: qe,
13
+ frame: $e,
14
+ frameFocused: We,
15
+ frameDisabled: Ke,
16
+ frameError: Ve,
17
+ errorMessage: Je,
18
+ helpers: Ge,
19
+ helperText: Ye,
20
+ helpLink: Xe,
21
+ containerDisabled: Ze,
22
+ containerFullWidth: Qe,
23
+ toolbarContent: et,
24
+ toolbarPanel: tt,
25
+ toolbarRow: nt,
26
+ toolbar: ot,
27
+ toolbarStacked: rt,
28
+ actions: it,
29
+ toolButton: at,
30
+ toolButtonActive: lt,
31
+ toolIcon: ct,
32
+ formatControl: st,
33
+ toolbarLinkSlot: dt,
34
+ selectTrigger: ut,
35
+ selectTriggerOpen: mt,
36
+ selectTriggerLabel: _t,
37
+ selectIcon: pt,
38
+ formatMenu: ht,
39
+ formatMenuOptions: ft,
40
+ formatMenuOption: gt,
41
+ formatMenuOptionSelected: bt,
42
+ formatMenuOptionParagraph: Tt,
43
+ formatMenuOptionHeading1: xt,
44
+ formatMenuOptionHeading2: Rt,
45
+ formatMenuOptionHeading3: Et,
46
+ formatMenuOptionHeading4: Mt,
47
+ formatMenuOptionPreformatted: vt,
48
+ editor: Ct,
49
+ wordCount: kt,
50
+ wordCountExceeded: Ot,
51
+ linkDialogForm: yt
52
+ }, Lt = {
53
+ paragraph: "p",
54
+ heading1: "h1",
55
+ heading2: "h2",
56
+ heading3: "h3",
57
+ heading4: "h4",
58
+ preformatted: "pre",
59
+ "unordered-list": "ul",
60
+ "ordered-list": "ol"
61
+ };
62
+ function Re(r) {
63
+ return r.trim().length > 0 ? r : "<br>";
64
+ }
65
+ function Ht(r) {
66
+ switch (r.toLowerCase()) {
67
+ case "h1":
68
+ return "heading1";
69
+ case "h2":
70
+ return "heading2";
71
+ case "h3":
72
+ return "heading3";
73
+ case "h4":
74
+ return "heading4";
75
+ case "pre":
76
+ return "preformatted";
77
+ case "ul":
78
+ return "unordered-list";
79
+ case "ol":
80
+ return "ordered-list";
81
+ case "p":
82
+ default:
83
+ return "paragraph";
84
+ }
85
+ }
86
+ function G(r) {
87
+ if (!r.trim())
88
+ return {
89
+ blocks: [{
90
+ type: "paragraph",
91
+ html: "<br>"
92
+ }]
93
+ };
94
+ const m = new DOMParser().parseFromString(r, "text/html"), _ = Array.from(m.body.childNodes), g = [];
95
+ return _.forEach((i) => {
96
+ var T;
97
+ if (i.nodeType === Node.TEXT_NODE) {
98
+ const E = (T = i.textContent) == null ? void 0 : T.trim();
99
+ E && g.push({
100
+ type: "paragraph",
101
+ html: E
102
+ });
103
+ return;
104
+ }
105
+ if (i.nodeType !== Node.ELEMENT_NODE)
106
+ return;
107
+ const u = i, b = u.style.textAlign;
108
+ g.push({
109
+ type: Ht(u.tagName),
110
+ html: Re(u.innerHTML),
111
+ align: b || void 0
112
+ });
113
+ }), {
114
+ blocks: g.length > 0 ? g : [{
115
+ type: "paragraph",
116
+ html: "<br>"
117
+ }]
118
+ };
119
+ }
120
+ function xe(r) {
121
+ return r.blocks.length ? r.blocks.map((l) => {
122
+ const m = Lt[l.type], _ = l.align ? ` style="text-align:${l.align}"` : "";
123
+ return `<${m}${_}>${Re(l.html)}</${m}>`;
124
+ }).join("") : "<p><br></p>";
125
+ }
126
+ function Nt(r) {
127
+ const l = r.blocks.map((m) => m.html.replace(/<[^>]+>/g, " ")).join(" ").replace(/\s+/g, " ").trim();
128
+ return l ? l.split(" ").length : 0;
129
+ }
130
+ const wt = ["bold", "italic", "underline", "align-left", "align-center", "align-right", "bulleted", "link", "format"], St = [{
131
+ label: "Paragraph",
132
+ value: "paragraph"
133
+ }, {
134
+ label: "Heading 1",
135
+ value: "heading1"
136
+ }, {
137
+ label: "Heading 2",
138
+ value: "heading2"
139
+ }, {
140
+ label: "Heading 3",
141
+ value: "heading3"
142
+ }, {
143
+ label: "Heading 4",
144
+ value: "heading4"
145
+ }, {
146
+ label: "Preformatted",
147
+ value: "preformatted"
148
+ }], Ft = {
149
+ paragraph: "P",
150
+ heading1: "H1",
151
+ heading2: "H2",
152
+ heading3: "H3",
153
+ heading4: "H4",
154
+ preformatted: "PRE",
155
+ "unordered-list": "UL",
156
+ "ordered-list": "OL"
157
+ };
158
+ function Y() {
159
+ return "<p><br></p>";
160
+ }
161
+ function Dt(r) {
162
+ return r.trim().length > 0 ? r : Y();
163
+ }
164
+ function At() {
165
+ const r = document.queryCommandValue("formatBlock");
166
+ switch (String(r || "").replace(/[<>]/g, "").toUpperCase()) {
167
+ case "H1":
168
+ return "heading1";
169
+ case "H2":
170
+ return "heading2";
171
+ case "H3":
172
+ return "heading3";
173
+ case "H4":
174
+ return "heading4";
175
+ case "PRE":
176
+ return "preformatted";
177
+ default:
178
+ return "paragraph";
179
+ }
180
+ }
181
+ function Bt(r) {
182
+ switch (r) {
183
+ case "heading1":
184
+ return t.formatMenuOptionHeading1;
185
+ case "heading2":
186
+ return t.formatMenuOptionHeading2;
187
+ case "heading3":
188
+ return t.formatMenuOptionHeading3;
189
+ case "heading4":
190
+ return t.formatMenuOptionHeading4;
191
+ case "preformatted":
192
+ return t.formatMenuOptionPreformatted;
193
+ default:
194
+ return t.formatMenuOptionParagraph;
195
+ }
196
+ }
197
+ function Kt({
198
+ className: r,
199
+ label: l,
200
+ required: m = !1,
201
+ value: _,
202
+ placeholder: g = "Content",
203
+ disabled: i = !1,
204
+ errorMessage: u,
205
+ helpText: b,
206
+ helpLink: T,
207
+ helpLinkText: E,
208
+ toolbarLayout: B = "inline",
209
+ showToolbar: I = !0,
210
+ showWordCount: Ee = !0,
211
+ maxWords: O,
212
+ resizable: Me = !0,
213
+ rows: ve = 8,
214
+ fullWidth: P = !1,
215
+ tooltipEnabled: y = !0,
216
+ formatOptions: X = St,
217
+ toolbarOptions: Z = wt,
218
+ onChange: j,
219
+ onModelChange: U
220
+ }) {
221
+ const Ce = be(() => new Set(Z), [Z]), M = (e) => Ce.has(e), Q = De(), s = F(null), ee = F(null), te = F(null), v = F(null), [ke, ne] = d(!1), [z, oe] = d(!1), [Oe, ye] = d(0), [re, ie] = d(null), [Le, ae] = d(!1), [le, ce] = d(""), [se, de] = d(""), [L, ue] = d(() => G(_ || Y())), [me, He] = d("paragraph"), [p, Ne] = d({
222
+ bold: !1,
223
+ italic: !1,
224
+ underline: !1,
225
+ justifyLeft: !1,
226
+ justifyCenter: !1,
227
+ justifyRight: !1,
228
+ insertUnorderedList: !1
229
+ }), q = be(() => Nt(L), [L]), $ = () => {
230
+ if (!s.current) return;
231
+ const e = G(s.current.innerHTML);
232
+ ue(e), U == null || U(e), j == null || j(xe(e));
233
+ }, C = () => {
234
+ He(At()), Ne({
235
+ bold: document.queryCommandState("bold"),
236
+ italic: document.queryCommandState("italic"),
237
+ underline: document.queryCommandState("underline"),
238
+ justifyLeft: document.queryCommandState("justifyLeft"),
239
+ justifyCenter: document.queryCommandState("justifyCenter"),
240
+ justifyRight: document.queryCommandState("justifyRight"),
241
+ insertUnorderedList: document.queryCommandState("insertUnorderedList")
242
+ });
243
+ }, W = () => {
244
+ var e;
245
+ i || (e = s.current) == null || e.focus();
246
+ }, _e = (e, o) => {
247
+ i || (W(), document.execCommand(e, !1, o), $(), C());
248
+ }, we = (e) => {
249
+ _e("formatBlock", Ft[e]);
250
+ }, pe = () => {
251
+ var h, R;
252
+ if (i) return;
253
+ W();
254
+ const e = window.getSelection();
255
+ let o = "", a = "";
256
+ if (e && e.rangeCount > 0) {
257
+ const k = e.getRangeAt(0);
258
+ v.current = k.cloneRange(), o = e.toString();
259
+ const V = ((h = k.startContainer.parentElement) == null ? void 0 : h.closest("a")) ?? ((R = k.endContainer.parentElement) == null ? void 0 : R.closest("a"));
260
+ V instanceof HTMLAnchorElement && (o = V.textContent ?? o, a = V.getAttribute("href") ?? "");
261
+ } else
262
+ v.current = null;
263
+ ce(o), de(a), ae(!0);
264
+ }, H = () => {
265
+ ae(!1), v.current = null;
266
+ }, Se = () => {
267
+ const e = se.trim();
268
+ if (!e) {
269
+ H();
270
+ return;
271
+ }
272
+ const o = le.trim() || e, a = (k) => k.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"), h = `<a href="${a(e)}" target="_blank" rel="noopener noreferrer">${a(o)}</a>`;
273
+ W();
274
+ const R = window.getSelection();
275
+ R && v.current && (R.removeAllRanges(), R.addRange(v.current)), document.execCommand("insertHTML", !1, h), $(), C(), H();
276
+ }, Fe = (e) => {
277
+ if (!e.ctrlKey && !e.metaKey) return;
278
+ const o = e.target, a = o == null ? void 0 : o.closest("a");
279
+ a instanceof HTMLAnchorElement && a.href && (e.preventDefault(), window.open(a.href, "_blank", "noopener,noreferrer"));
280
+ };
281
+ D(() => {
282
+ const e = Dt(_ || Y()), o = G(e);
283
+ ue(o), s.current && s.current.innerHTML !== e && (s.current.innerHTML = e);
284
+ }, [_]), D(() => {
285
+ s.current && (s.current.innerHTML.trim() || (s.current.innerHTML = xe(L)));
286
+ }, [L]), D(() => {
287
+ var o;
288
+ const e = (o = ee.current) == null ? void 0 : o.getBoundingClientRect().width;
289
+ e && ye(e);
290
+ }, [z]), D(() => {
291
+ if (!I || P) {
292
+ ie(null);
293
+ return;
294
+ }
295
+ const e = te.current;
296
+ if (!e) return;
297
+ const o = () => {
298
+ const h = e.getBoundingClientRect().width;
299
+ h > 0 && ie(h);
300
+ };
301
+ o();
302
+ const a = new ResizeObserver(() => {
303
+ o();
304
+ });
305
+ return a.observe(e), window.addEventListener("resize", o), () => {
306
+ a.disconnect(), window.removeEventListener("resize", o);
307
+ };
308
+ }, [I, B, i, y, P]);
309
+ const x = (e) => /* @__PURE__ */ n(J, { content: e.tooltip, size: "sm", theme: "dark", tipSide: "top", tipAlignment: "center", disabled: !y, children: /* @__PURE__ */ n("button", { type: "button", className: f(t.toolButton, e.active && t.toolButtonActive), onMouseDown: (o) => o.preventDefault(), onClick: () => _e(e.command, e.value), "aria-label": e.tooltip, disabled: i, children: /* @__PURE__ */ n(A, { icon: e.icon, className: t.toolIcon }) }) }, e.id), K = [{
310
+ id: "bold",
311
+ icon: "ap-icon-bold",
312
+ command: "bold",
313
+ tooltip: "Bold (CTRL + B)",
314
+ active: p.bold
315
+ }, {
316
+ id: "italic",
317
+ icon: "ap-icon-italic",
318
+ command: "italic",
319
+ tooltip: "Italic (CTRL + I)",
320
+ active: p.italic
321
+ }, {
322
+ id: "underline",
323
+ icon: "ap-icon-underline",
324
+ command: "underline",
325
+ tooltip: "Underline (CTRL + U)",
326
+ active: p.underline
327
+ }, {
328
+ id: "align-left",
329
+ icon: "ap-icon-left",
330
+ command: "justifyLeft",
331
+ tooltip: "Align left",
332
+ active: p.justifyLeft
333
+ }, {
334
+ id: "align-center",
335
+ icon: "ap-icon-bar",
336
+ command: "justifyCenter",
337
+ tooltip: "Align center",
338
+ active: p.justifyCenter
339
+ }, {
340
+ id: "align-right",
341
+ icon: "ap-icon-right",
342
+ command: "justifyRight",
343
+ tooltip: "Align right",
344
+ active: p.justifyRight
345
+ }, {
346
+ id: "bulleted",
347
+ icon: "ap-icon-list",
348
+ command: "insertUnorderedList",
349
+ tooltip: "Bulleted list",
350
+ active: p.insertUnorderedList
351
+ }], N = K.filter((e) => ["bold", "italic", "underline"].includes(e.id) && M(e.id)), w = K.filter((e) => ["align-left", "align-center", "align-right"].includes(e.id) && M(e.id)), S = K.filter((e) => ["bulleted"].includes(e.id) && M(e.id)), he = M("link"), fe = M("format"), ge = () => {
352
+ var e;
353
+ return /* @__PURE__ */ n("div", { className: t.formatControl, children: /* @__PURE__ */ c(Be, { open: z, onOpenChange: oe, children: [
354
+ /* @__PURE__ */ c(Ie, { ref: ee, disabled: i, className: f(t.selectTrigger, z && t.selectTriggerOpen), children: [
355
+ /* @__PURE__ */ n("span", { className: t.selectTriggerLabel, children: ((e = X.find((o) => o.value === me)) == null ? void 0 : e.label) || "Paragraph" }),
356
+ /* @__PURE__ */ n(A, { icon: "ap-icon-expand-more", className: t.selectIcon })
357
+ ] }),
358
+ /* @__PURE__ */ n(Pe, { children: /* @__PURE__ */ n(je, { align: "end", side: "bottom", sideOffset: 6, collisionPadding: 8, className: t.formatMenu, style: {
359
+ minWidth: Oe || 180,
360
+ zIndex: 9999
361
+ }, children: /* @__PURE__ */ n("div", { className: t.formatMenuOptions, children: X.map((o) => /* @__PURE__ */ n("button", { type: "button", className: f(t.formatMenuOption, Bt(o.value), o.value === me && t.formatMenuOptionSelected), onMouseDown: (a) => a.preventDefault(), onClick: () => {
362
+ we(o.value), oe(!1);
363
+ }, children: o.label }, o.value)) }) }) })
364
+ ] }) });
365
+ };
366
+ return /* @__PURE__ */ c("div", { className: f(t.container, i && t.containerDisabled, P && t.containerFullWidth, r), children: [
367
+ l && /* @__PURE__ */ c("label", { className: t.label, htmlFor: Q, children: [
368
+ l,
369
+ m && /* @__PURE__ */ n("span", { className: t.required, children: "*" })
370
+ ] }),
371
+ /* @__PURE__ */ c("div", { className: f(t.frame, ke && t.frameFocused, i && t.frameDisabled, u && t.frameError), style: {
372
+ width: re ? `${re}px` : void 0
373
+ }, children: [
374
+ I && /* @__PURE__ */ n("div", { className: f(t.toolbar, B === "stacked" && t.toolbarStacked), children: /* @__PURE__ */ n("div", { ref: te, className: t.toolbarContent, children: B === "stacked" ? /* @__PURE__ */ c("div", { className: t.toolbarPanel, children: [
375
+ /* @__PURE__ */ c("div", { className: t.toolbarRow, children: [
376
+ N.length > 0 && /* @__PURE__ */ n("div", { className: t.actions, children: N.map(x) }),
377
+ w.length > 0 && /* @__PURE__ */ n("div", { className: t.actions, children: w.map(x) })
378
+ ] }),
379
+ /* @__PURE__ */ c("div", { className: t.toolbarRow, children: [
380
+ S.length > 0 && /* @__PURE__ */ n("div", { className: t.actions, children: S.map(x) }),
381
+ he && /* @__PURE__ */ n("div", { className: t.toolbarLinkSlot, children: /* @__PURE__ */ n(J, { content: "Insert link", size: "sm", theme: "dark", tipSide: "top", tipAlignment: "center", disabled: !y, children: /* @__PURE__ */ n("button", { type: "button", className: t.toolButton, onMouseDown: (e) => e.preventDefault(), onClick: pe, "aria-label": "Insert link", disabled: i, children: /* @__PURE__ */ n(A, { icon: "ap-icon-link", className: t.toolIcon }) }) }) }),
382
+ fe && ge()
383
+ ] })
384
+ ] }) : /* @__PURE__ */ n("div", { className: t.toolbarPanel, children: /* @__PURE__ */ c("div", { className: t.toolbarRow, children: [
385
+ N.length > 0 && /* @__PURE__ */ n("div", { className: t.actions, children: N.map(x) }),
386
+ w.length > 0 && /* @__PURE__ */ n("div", { className: t.actions, children: w.map(x) }),
387
+ S.length > 0 && /* @__PURE__ */ n("div", { className: t.actions, children: S.map(x) }),
388
+ he && /* @__PURE__ */ n("div", { className: t.toolbarLinkSlot, children: /* @__PURE__ */ n(J, { content: "Insert link", size: "sm", theme: "dark", tipSide: "top", tipAlignment: "center", disabled: !y, children: /* @__PURE__ */ n("button", { type: "button", className: t.toolButton, onMouseDown: (e) => e.preventDefault(), onClick: pe, "aria-label": "Insert link", disabled: i, children: /* @__PURE__ */ n(A, { icon: "ap-icon-link", className: t.toolIcon }) }) }) }),
389
+ fe && ge()
390
+ ] }) }) }) }),
391
+ /* @__PURE__ */ n("div", { id: Q, ref: s, className: t.editor, contentEditable: !i, suppressContentEditableWarning: !0, role: "textbox", "aria-multiline": "true", "aria-label": l || "Rich text editor", "data-placeholder": g, onInput: $, onFocus: () => {
392
+ ne(!0), C();
393
+ }, onBlur: () => ne(!1), onKeyUp: C, onMouseUp: C, onClick: Fe, style: {
394
+ minHeight: `${ve * 20}px`,
395
+ resize: Me ? "vertical" : "none"
396
+ } }),
397
+ Ee && /* @__PURE__ */ n("div", { className: f(t.wordCount, O && q > O && t.wordCountExceeded), children: O ? `${q}/${O}` : q })
398
+ ] }),
399
+ (u || b || T) && /* @__PURE__ */ c("div", { className: t.helpers, children: [
400
+ u ? /* @__PURE__ */ n("span", { title: u, className: t.errorMessage, children: u }) : b && /* @__PURE__ */ n("span", { title: b, className: t.helperText, children: b }),
401
+ T && E && /* @__PURE__ */ n("a", { href: T, className: t.helpLink, target: "_blank", rel: "noopener noreferrer", children: E })
402
+ ] }),
403
+ /* @__PURE__ */ n(Ae, { isOpen: Le, onClose: H, title: "Attach link", cancelButtonText: "Cancel", cancelButtonType: "secondary", cancelButtonVariant: "cancel", confirmButtonText: "Attach", confirmButtonType: "primary", onCancel: H, onConfirm: Se, description: /* @__PURE__ */ c("div", { className: t.linkDialogForm, children: [
404
+ /* @__PURE__ */ n(Te, { type: "text", label: "Displayed text", value: le, onChange: ce, autofocus: !0 }),
405
+ /* @__PURE__ */ n(Te, { type: "text", label: "Link", value: se, placeholder: "https://example.com/", onChange: de })
406
+ ] }) })
407
+ ] });
408
+ }
409
+ export {
410
+ Kt as R,
411
+ t as s
412
+ };
@@ -1 +1 @@
1
- .RichTextEditor-module__container___AplP0{width:fit-content;max-width:100%;display:grid;grid-template-columns:1fr;row-gap:12px}.RichTextEditor-module__label___vjzs-{color:#4a4a4a;font-size:14px;font-weight:500;line-height:1.2;display:inline-flex;align-items:center;gap:4px}.RichTextEditor-module__required___7duke{color:#cb282e}.RichTextEditor-module__frame___7OSyf{border:1px solid #cccccc;border-radius:4px;background:#fff;overflow:hidden}.RichTextEditor-module__frameFocused___GtJ2x{border-color:#5cb335}.RichTextEditor-module__frameDisabled___LubtU{opacity:.7}.RichTextEditor-module__toolbar___m9-M-{display:block;border-bottom:1px solid #cccccc}.RichTextEditor-module__toolbarContent___YXKHD{width:fit-content;display:flex;align-items:center;gap:12px}.RichTextEditor-module__toolbarStacked___6rB10 .RichTextEditor-module__toolbarContent___YXKHD{display:block}.RichTextEditor-module__actions___ZAK9J{display:flex;align-items:center;gap:6px}.RichTextEditor-module__toolbarPanel___OVGHO{border-radius:4px;overflow:hidden;width:fit-content}.RichTextEditor-module__toolbarRow___f0xJR{display:flex;align-items:center;width:fit-content;min-height:32px;border-bottom:1px solid #cccccc;padding:2px 4px;gap:2px}.RichTextEditor-module__toolbarRow___f0xJR:last-child{border-bottom:none}.RichTextEditor-module__toolbarRow___f0xJR>*{padding-right:8px;margin-right:8px;border-right:1px solid #cccccc}.RichTextEditor-module__toolbarRow___f0xJR>*:last-child{padding-right:0;margin-right:0;border-right:none}.RichTextEditor-module__toolButton___IT2Kg{width:32px;height:32px;border:none;background:transparent;border-radius:2px;display:inline-flex;align-items:center;justify-content:center;cursor:pointer}.RichTextEditor-module__toolButton___IT2Kg:hover:not(:disabled){background:#f7f7f7}.RichTextEditor-module__toolButton___IT2Kg:active:not(:disabled),.RichTextEditor-module__toolButton___IT2Kg.RichTextEditor-module__toolButtonActive___-HvZQ{background:#e4e4e4}.RichTextEditor-module__toolIcon___Wndhd{color:#4a4a4a;font-size:20px}.RichTextEditor-module__formatControl___w4WcA{position:relative;flex-shrink:0}.RichTextEditor-module__toolbarLinkSlot___Gu-9l{display:inline-flex;align-items:center;flex-shrink:0}.RichTextEditor-module__selectTrigger___frv3x{height:32px;min-width:180px;flex-shrink:0;border:none;background:transparent;color:#4a4a4a;font-size:16px;outline:none;border-radius:2px;cursor:pointer;display:inline-flex;align-items:center;justify-content:space-between}.RichTextEditor-module__selectTrigger___frv3x:hover:not(:disabled){background:#f7f7f7}.RichTextEditor-module__selectTrigger___frv3x:focus-visible{background:#e4e4e4}.RichTextEditor-module__selectTriggerOpen___tk2Pb{background:#e4e4e4}.RichTextEditor-module__selectTriggerLabel___FkEv0{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.RichTextEditor-module__selectIcon___aJWUk{margin-left:8px;pointer-events:none;color:#4a4a4a;font-size:16px}.RichTextEditor-module__formatMenu___y-uBL{background-color:#fff;border:1px solid #cccccc;border-radius:4px;box-shadow:0 0 4px #00000029;max-width:640px;width:fit-content;overflow:hidden}.RichTextEditor-module__formatMenuOptions___zcdlo{padding:8px;display:flex;flex-direction:column;gap:0}.RichTextEditor-module__formatMenuOption___3ppTs{width:100%;border:none;background:none;min-height:32px;padding:8px;border-radius:4px;color:#4a4a4a;text-align:left;font-size:14px;cursor:pointer}.RichTextEditor-module__formatMenuOption___3ppTs:hover,.RichTextEditor-module__formatMenuOptionSelected___bq9J9{background-color:#dff0db}.RichTextEditor-module__formatMenuOptionParagraph___4BLds{font-size:16px;font-weight:400;line-height:1.3}.RichTextEditor-module__formatMenuOptionHeading1___H1cKX{font-size:48px;font-weight:600;line-height:1.2}.RichTextEditor-module__formatMenuOptionHeading2___JdixR{font-size:40px;font-weight:600;line-height:1.2}.RichTextEditor-module__formatMenuOptionHeading3___NcwLr{font-size:32px;font-weight:600;line-height:1.25}.RichTextEditor-module__formatMenuOptionHeading4___4mLbG{font-size:24px;font-weight:600;line-height:1.3}.RichTextEditor-module__formatMenuOptionPreformatted___cB0Ix{font-family:Roboto Mono,Consolas,Monaco,Courier New,monospace;font-size:14px;letter-spacing:.08em;font-weight:400;line-height:1.3}.RichTextEditor-module__editor___M32R7{width:100%;box-sizing:border-box;min-height:160px;padding:6px 12px;color:#28292c;font-size:14px;line-height:1.4;overflow:auto;outline:none}.RichTextEditor-module__editor___M32R7:empty:before{content:attr(data-placeholder);color:#878787;pointer-events:none}.RichTextEditor-module__wordCount___5SSVY{text-align:right;color:#727272;font-size:12px;padding-right:8px;padding-bottom:4px;padding-top:4px}.RichTextEditor-module__wordCountExceeded___NhqBc{color:#bf494e}
1
+ .RichTextEditor-module__container___AplP0{width:fit-content;max-width:100%;display:grid;grid-template-columns:1fr;row-gap:6px}.RichTextEditor-module__label___vjzs-{color:#4a4a4a;font-size:14px;font-weight:500;line-height:1.2;display:inline-flex;align-items:center;gap:4px}.RichTextEditor-module__required___7duke{color:#cb282e}.RichTextEditor-module__frame___7OSyf{border:1px solid #cccccc;border-radius:4px;background:#fff;overflow:hidden}.RichTextEditor-module__frameFocused___GtJ2x{border-color:#5cb335}.RichTextEditor-module__frameDisabled___LubtU{opacity:.7}.RichTextEditor-module__frameError___sPTiY{border-color:#bf494e}.RichTextEditor-module__errorMessage___4VdKj{color:#bf494e;font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.RichTextEditor-module__helpers___cpuz6{display:flex;justify-content:space-between;align-items:center;gap:6px;min-width:0}.RichTextEditor-module__helperText___rFoU0{color:#727272;font-size:12px;font-weight:400;line-height:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.RichTextEditor-module__helpLink___7gYcv{color:#0369a3;font-size:13px;font-weight:500;line-height:1;text-decoration:none;flex-shrink:0;margin-left:auto}.RichTextEditor-module__helpLink___7gYcv:hover{text-decoration:underline}.RichTextEditor-module__containerDisabled___6h9dd .RichTextEditor-module__helperText___rFoU0{color:#b2b2b2}.RichTextEditor-module__containerDisabled___6h9dd .RichTextEditor-module__helpLink___7gYcv{color:#878787;pointer-events:none;cursor:not-allowed}.RichTextEditor-module__containerFullWidth___pOoeL,.RichTextEditor-module__containerFullWidth___pOoeL .RichTextEditor-module__frame___7OSyf,.RichTextEditor-module__containerFullWidth___pOoeL .RichTextEditor-module__toolbarContent___YXKHD,.RichTextEditor-module__containerFullWidth___pOoeL .RichTextEditor-module__toolbarPanel___OVGHO,.RichTextEditor-module__containerFullWidth___pOoeL .RichTextEditor-module__toolbarRow___f0xJR{width:100%}.RichTextEditor-module__toolbar___m9-M-{display:block;border-bottom:1px solid #cccccc}.RichTextEditor-module__toolbarContent___YXKHD{width:fit-content;display:flex;align-items:center;gap:12px}.RichTextEditor-module__toolbarStacked___6rB10 .RichTextEditor-module__toolbarContent___YXKHD{display:block}.RichTextEditor-module__actions___ZAK9J{display:flex;align-items:center;gap:6px}.RichTextEditor-module__toolbarPanel___OVGHO{border-radius:4px;overflow:hidden;width:fit-content}.RichTextEditor-module__toolbarRow___f0xJR{display:flex;align-items:center;width:fit-content;min-height:32px;border-bottom:1px solid #cccccc;padding:2px 4px;gap:2px}.RichTextEditor-module__toolbarRow___f0xJR:last-child{border-bottom:none}.RichTextEditor-module__toolbarRow___f0xJR>*{padding-right:8px;margin-right:8px;border-right:1px solid #cccccc}.RichTextEditor-module__toolbarRow___f0xJR>*:last-child{padding-right:0;margin-right:0;border-right:none}.RichTextEditor-module__toolButton___IT2Kg{width:32px;height:32px;border:none;background:transparent;border-radius:2px;display:inline-flex;align-items:center;justify-content:center;cursor:pointer}.RichTextEditor-module__toolButton___IT2Kg:hover:not(:disabled){background:#f7f7f7}.RichTextEditor-module__toolButton___IT2Kg:active:not(:disabled),.RichTextEditor-module__toolButton___IT2Kg.RichTextEditor-module__toolButtonActive___-HvZQ{background:#e4e4e4}.RichTextEditor-module__toolIcon___Wndhd{color:#4a4a4a;font-size:20px!important}.RichTextEditor-module__formatControl___w4WcA{position:relative;flex-shrink:0}.RichTextEditor-module__toolbarLinkSlot___Gu-9l{display:inline-flex;align-items:center;flex-shrink:0}.RichTextEditor-module__selectTrigger___frv3x{height:32px;flex-shrink:0;border:none;background:transparent;color:#4a4a4a;font-size:16px;outline:none;border-radius:2px;cursor:pointer;display:inline-flex;align-items:center;justify-content:space-between}.RichTextEditor-module__selectTrigger___frv3x:hover:not(:disabled){background:#f7f7f7}.RichTextEditor-module__selectTrigger___frv3x:focus-visible{background:#e4e4e4}.RichTextEditor-module__selectTriggerOpen___tk2Pb{background:#e4e4e4}.RichTextEditor-module__selectTriggerLabel___FkEv0{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.RichTextEditor-module__selectIcon___aJWUk{margin-left:8px;pointer-events:none;color:#4a4a4a;font-size:16px}.RichTextEditor-module__formatMenu___y-uBL{background-color:#fff;border:1px solid #cccccc;border-radius:4px;box-shadow:0 0 4px #00000029;max-width:640px;width:fit-content;overflow:hidden}.RichTextEditor-module__formatMenuOptions___zcdlo{padding:8px;display:flex;flex-direction:column;gap:0}.RichTextEditor-module__formatMenuOption___3ppTs{width:100%;border:none;background:none;min-height:32px;padding:8px;border-radius:4px;color:#4a4a4a;text-align:left;font-size:14px;cursor:pointer}.RichTextEditor-module__formatMenuOption___3ppTs:hover,.RichTextEditor-module__formatMenuOptionSelected___bq9J9{background-color:#dff0db}.RichTextEditor-module__formatMenuOptionParagraph___4BLds{font-size:16px;font-weight:400;line-height:1.3}.RichTextEditor-module__formatMenuOptionHeading1___H1cKX{font-size:48px;font-weight:600;line-height:1.2}.RichTextEditor-module__formatMenuOptionHeading2___JdixR{font-size:40px;font-weight:600;line-height:1.2}.RichTextEditor-module__formatMenuOptionHeading3___NcwLr{font-size:32px;font-weight:600;line-height:1.25}.RichTextEditor-module__formatMenuOptionHeading4___4mLbG{font-size:24px;font-weight:600;line-height:1.3}.RichTextEditor-module__formatMenuOptionPreformatted___cB0Ix{font-family:Roboto Mono,Consolas,Monaco,Courier New,monospace;font-size:14px;letter-spacing:.08em;font-weight:400;line-height:1.3}.RichTextEditor-module__editor___M32R7{width:100%;box-sizing:border-box;min-height:160px;padding:6px 12px;color:#28292c;font-size:14px;line-height:1.4;overflow:auto;outline:none}.RichTextEditor-module__editor___M32R7:empty:before{content:attr(data-placeholder);color:#878787;pointer-events:none}.RichTextEditor-module__wordCount___5SSVY{text-align:right;color:#727272;font-size:12px;padding-right:8px;padding-bottom:4px;padding-top:4px}.RichTextEditor-module__wordCountExceeded___NhqBc{color:#bf494e}.RichTextEditor-module__linkDialogForm___vOLO1{padding-top:1rem;display:flex;flex-direction:column;gap:.75rem}.RichTextEditor-module__linkDialogForm___vOLO1>*{width:100%}a{cursor:pointer}
@@ -1,5 +1,6 @@
1
1
  import { RichTextBlockType, RichTextDocumentModel } from './RichTextEditor.model';
2
2
  type ToolbarLayout = 'inline' | 'stacked';
3
+ export type ToolbarOption = 'bold' | 'italic' | 'underline' | 'align-left' | 'align-center' | 'align-right' | 'bulleted' | 'link' | 'format';
3
4
  type FormatOption = {
4
5
  label: string;
5
6
  value: RichTextBlockType;
@@ -11,16 +12,22 @@ type RichTextEditorProps = {
11
12
  value?: string;
12
13
  placeholder?: string;
13
14
  disabled?: boolean;
15
+ errorMessage?: string;
16
+ helpText?: string;
17
+ helpLink?: string;
18
+ helpLinkText?: string;
14
19
  toolbarLayout?: ToolbarLayout;
15
20
  showToolbar?: boolean;
16
21
  showWordCount?: boolean;
17
22
  maxWords?: number;
18
23
  resizable?: boolean;
19
24
  rows?: number;
25
+ fullWidth?: boolean;
20
26
  tooltipEnabled?: boolean;
21
27
  formatOptions?: FormatOption[];
28
+ toolbarOptions?: ToolbarOption[];
22
29
  onChange?: (value: string) => void;
23
30
  onModelChange?: (model: RichTextDocumentModel) => void;
24
31
  };
25
- export default function RichTextEditor({ className, label, required, value, placeholder, disabled, toolbarLayout, showToolbar, showWordCount, maxWords, resizable, rows, tooltipEnabled, formatOptions, onChange, onModelChange, }: RichTextEditorProps): import("react/jsx-runtime").JSX.Element;
32
+ export default function RichTextEditor({ className, label, required, value, placeholder, disabled, errorMessage, helpText, helpLink, helpLinkText, toolbarLayout, showToolbar, showWordCount, maxWords, resizable, rows, fullWidth, tooltipEnabled, formatOptions, toolbarOptions, onChange, onModelChange, }: RichTextEditorProps): import("react/jsx-runtime").JSX.Element;
26
33
  export {};
@@ -1,10 +1,12 @@
1
1
  import "react/jsx-runtime";
2
2
  import "../../clsx-OuTLNxxd.js";
3
3
  import "react";
4
+ import "../Dialog/Dialog.js";
4
5
  import "../Icon/Icon.js";
6
+ import "../Input/Input.js";
5
7
  import "../Tooltip/Tooltip.js";
6
- import { R as f } from "../../RichTextEditor-CHGQT1Qj.js";
8
+ import { R as l } from "../../RichTextEditor-CfINW9Xs.js";
7
9
  import "../../index-DZ4Gof57.js";
8
10
  export {
9
- f as default
11
+ l as default
10
12
  };
@@ -1,6 +1,6 @@
1
1
  import { jsx as o } from "react/jsx-runtime";
2
2
  import { d, i as r, r as a, g as t, s as e, f as i, w as y, v as b } from "../../vi.bdSIJ99Y-017e_Pkz.js";
3
- import { s as c, R as n } from "../../RichTextEditor-CHGQT1Qj.js";
3
+ import { s as c, R as n } from "../../RichTextEditor-CfINW9Xs.js";
4
4
  d("RichTextEditor", () => {
5
5
  d("Rendering", () => {
6
6
  r("renders label and required marker", () => {
package/dist/main.js CHANGED
@@ -12,7 +12,7 @@ import { default as B } from "./components/Dropdown/Dropdown.js";
12
12
  import { default as v, useFilePickerContext as C } from "./components/FilePicker/FilePicker.js";
13
13
  import { default as I } from "./components/Search/Search.js";
14
14
  import { default as S } from "./components/Datepicker/Datepicker.js";
15
- import { R as N } from "./RichTextEditor-CHGQT1Qj.js";
15
+ import { R as N } from "./RichTextEditor-CfINW9Xs.js";
16
16
  import { default as w } from "./components/Toast/Toast.js";
17
17
  import { T as E } from "./ToastProvider-D5LImZ-Q.js";
18
18
  import { u as j } from "./useToast-Cz5MGKnw.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alixpartners/ui-components",
3
- "version": "2.5.2",
3
+ "version": "2.5.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1,363 +0,0 @@
1
- import { jsxs as c, jsx as n } from "react/jsx-runtime";
2
- import { c as _ } from "./clsx-OuTLNxxd.js";
3
- import { useId as se, useRef as w, useState as p, useMemo as ue, useEffect as E } from "react";
4
- import O from "./components/Icon/Icon.js";
5
- import S from "./components/Tooltip/Tooltip.js";
6
- import { R as me, T as fe, P as _e, C as pe } from "./index-DZ4Gof57.js";
7
- import './assets/RichTextEditor.css';const he = "RichTextEditor-module__container___AplP0", ge = "RichTextEditor-module__label___vjzs-", be = "RichTextEditor-module__required___7duke", Me = "RichTextEditor-module__frame___7OSyf", Te = "RichTextEditor-module__frameFocused___GtJ2x", xe = "RichTextEditor-module__frameDisabled___LubtU", ve = "RichTextEditor-module__toolbar___m9-M-", Re = "RichTextEditor-module__toolbarContent___YXKHD", Ee = "RichTextEditor-module__toolbarStacked___6rB10", Oe = "RichTextEditor-module__actions___ZAK9J", Ce = "RichTextEditor-module__toolbarPanel___OVGHO", ye = "RichTextEditor-module__toolbarRow___f0xJR", He = "RichTextEditor-module__toolButton___IT2Kg", Ne = "RichTextEditor-module__toolButtonActive___-HvZQ", ke = "RichTextEditor-module__toolIcon___Wndhd", Le = "RichTextEditor-module__formatControl___w4WcA", we = "RichTextEditor-module__toolbarLinkSlot___Gu-9l", Se = "RichTextEditor-module__selectTrigger___frv3x", Fe = "RichTextEditor-module__selectTriggerOpen___tk2Pb", Ie = "RichTextEditor-module__selectTriggerLabel___FkEv0", Pe = "RichTextEditor-module__selectIcon___aJWUk", Be = "RichTextEditor-module__formatMenu___y-uBL", Ae = "RichTextEditor-module__formatMenuOptions___zcdlo", je = "RichTextEditor-module__formatMenuOption___3ppTs", ze = "RichTextEditor-module__formatMenuOptionSelected___bq9J9", De = "RichTextEditor-module__formatMenuOptionParagraph___4BLds", qe = "RichTextEditor-module__formatMenuOptionHeading1___H1cKX", Ue = "RichTextEditor-module__formatMenuOptionHeading2___JdixR", $e = "RichTextEditor-module__formatMenuOptionHeading3___NcwLr", We = "RichTextEditor-module__formatMenuOptionHeading4___4mLbG", Je = "RichTextEditor-module__formatMenuOptionPreformatted___cB0Ix", Ke = "RichTextEditor-module__editor___M32R7", Ve = "RichTextEditor-module__wordCount___5SSVY", Ge = "RichTextEditor-module__wordCountExceeded___NhqBc", e = {
8
- container: he,
9
- label: ge,
10
- required: be,
11
- frame: Me,
12
- frameFocused: Te,
13
- frameDisabled: xe,
14
- toolbar: ve,
15
- toolbarContent: Re,
16
- toolbarStacked: Ee,
17
- actions: Oe,
18
- toolbarPanel: Ce,
19
- toolbarRow: ye,
20
- toolButton: He,
21
- toolButtonActive: Ne,
22
- toolIcon: ke,
23
- formatControl: Le,
24
- toolbarLinkSlot: we,
25
- selectTrigger: Se,
26
- selectTriggerOpen: Fe,
27
- selectTriggerLabel: Ie,
28
- selectIcon: Pe,
29
- formatMenu: Be,
30
- formatMenuOptions: Ae,
31
- formatMenuOption: je,
32
- formatMenuOptionSelected: ze,
33
- formatMenuOptionParagraph: De,
34
- formatMenuOptionHeading1: qe,
35
- formatMenuOptionHeading2: Ue,
36
- formatMenuOptionHeading3: $e,
37
- formatMenuOptionHeading4: We,
38
- formatMenuOptionPreformatted: Je,
39
- editor: Ke,
40
- wordCount: Ve,
41
- wordCountExceeded: Ge
42
- }, Xe = {
43
- paragraph: "p",
44
- heading1: "h1",
45
- heading2: "h2",
46
- heading3: "h3",
47
- heading4: "h4",
48
- preformatted: "pre",
49
- "unordered-list": "ul",
50
- "ordered-list": "ol"
51
- };
52
- function te(o) {
53
- return o.trim().length > 0 ? o : "<br>";
54
- }
55
- function Ye(o) {
56
- switch (o.toLowerCase()) {
57
- case "h1":
58
- return "heading1";
59
- case "h2":
60
- return "heading2";
61
- case "h3":
62
- return "heading3";
63
- case "h4":
64
- return "heading4";
65
- case "pre":
66
- return "preformatted";
67
- case "ul":
68
- return "unordered-list";
69
- case "ol":
70
- return "ordered-list";
71
- case "p":
72
- default:
73
- return "paragraph";
74
- }
75
- }
76
- function F(o) {
77
- if (!o.trim())
78
- return {
79
- blocks: [{
80
- type: "paragraph",
81
- html: "<br>"
82
- }]
83
- };
84
- const d = new DOMParser().parseFromString(o, "text/html"), s = Array.from(d.body.childNodes), h = [];
85
- return s.forEach((i) => {
86
- var T;
87
- if (i.nodeType === Node.TEXT_NODE) {
88
- const m = (T = i.textContent) == null ? void 0 : T.trim();
89
- m && h.push({
90
- type: "paragraph",
91
- html: m
92
- });
93
- return;
94
- }
95
- if (i.nodeType !== Node.ELEMENT_NODE)
96
- return;
97
- const u = i, b = u.style.textAlign;
98
- h.push({
99
- type: Ye(u.tagName),
100
- html: te(u.innerHTML),
101
- align: b || void 0
102
- });
103
- }), {
104
- blocks: h.length > 0 ? h : [{
105
- type: "paragraph",
106
- html: "<br>"
107
- }]
108
- };
109
- }
110
- function ee(o) {
111
- return o.blocks.length ? o.blocks.map((a) => {
112
- const d = Xe[a.type], s = a.align ? ` style="text-align:${a.align}"` : "";
113
- return `<${d}${s}>${te(a.html)}</${d}>`;
114
- }).join("") : "<p><br></p>";
115
- }
116
- function Ze(o) {
117
- const a = o.blocks.map((d) => d.html.replace(/<[^>]+>/g, " ")).join(" ").replace(/\s+/g, " ").trim();
118
- return a ? a.split(" ").length : 0;
119
- }
120
- const Qe = [{
121
- label: "Paragraph",
122
- value: "paragraph"
123
- }, {
124
- label: "Heading 1",
125
- value: "heading1"
126
- }, {
127
- label: "Heading 2",
128
- value: "heading2"
129
- }, {
130
- label: "Heading 3",
131
- value: "heading3"
132
- }, {
133
- label: "Heading 4",
134
- value: "heading4"
135
- }, {
136
- label: "Preformatted",
137
- value: "preformatted"
138
- }], et = {
139
- paragraph: "P",
140
- heading1: "H1",
141
- heading2: "H2",
142
- heading3: "H3",
143
- heading4: "H4",
144
- preformatted: "PRE",
145
- "unordered-list": "UL",
146
- "ordered-list": "OL"
147
- };
148
- function I() {
149
- return "<p><br></p>";
150
- }
151
- function tt(o) {
152
- return o.trim().length > 0 ? o : I();
153
- }
154
- function nt() {
155
- const o = document.queryCommandValue("formatBlock");
156
- switch (String(o || "").replace(/[<>]/g, "").toUpperCase()) {
157
- case "H1":
158
- return "heading1";
159
- case "H2":
160
- return "heading2";
161
- case "H3":
162
- return "heading3";
163
- case "H4":
164
- return "heading4";
165
- case "PRE":
166
- return "preformatted";
167
- default:
168
- return "paragraph";
169
- }
170
- }
171
- function ot(o) {
172
- switch (o) {
173
- case "heading1":
174
- return e.formatMenuOptionHeading1;
175
- case "heading2":
176
- return e.formatMenuOptionHeading2;
177
- case "heading3":
178
- return e.formatMenuOptionHeading3;
179
- case "heading4":
180
- return e.formatMenuOptionHeading4;
181
- case "preformatted":
182
- return e.formatMenuOptionPreformatted;
183
- default:
184
- return e.formatMenuOptionParagraph;
185
- }
186
- }
187
- function st({
188
- className: o,
189
- label: a,
190
- required: d = !1,
191
- value: s,
192
- placeholder: h = "Content",
193
- disabled: i = !1,
194
- toolbarLayout: u = "inline",
195
- showToolbar: b = !0,
196
- showWordCount: T = !0,
197
- maxWords: m,
198
- resizable: ne = !0,
199
- rows: oe = 8,
200
- tooltipEnabled: x = !0,
201
- formatOptions: P = Qe,
202
- onChange: C,
203
- onModelChange: y
204
- }) {
205
- const B = se(), l = w(null), A = w(null), j = w(null), [re, z] = p(!1), [H, D] = p(!1), [ie, ae] = p(0), [q, U] = p(null), [v, $] = p(() => F(s || I())), [W, le] = p("paragraph"), [f, ce] = p({
206
- bold: !1,
207
- italic: !1,
208
- underline: !1,
209
- justifyLeft: !1,
210
- justifyCenter: !1,
211
- justifyRight: !1,
212
- insertUnorderedList: !1
213
- }), N = ue(() => Ze(v), [v]), k = () => {
214
- if (!l.current) return;
215
- const t = F(l.current.innerHTML);
216
- $(t), y == null || y(t), C == null || C(ee(t));
217
- }, M = () => {
218
- le(nt()), ce({
219
- bold: document.queryCommandState("bold"),
220
- italic: document.queryCommandState("italic"),
221
- underline: document.queryCommandState("underline"),
222
- justifyLeft: document.queryCommandState("justifyLeft"),
223
- justifyCenter: document.queryCommandState("justifyCenter"),
224
- justifyRight: document.queryCommandState("justifyRight"),
225
- insertUnorderedList: document.queryCommandState("insertUnorderedList")
226
- });
227
- }, J = () => {
228
- var t;
229
- i || (t = l.current) == null || t.focus();
230
- }, K = (t, r) => {
231
- i || (J(), document.execCommand(t, !1, r), k(), M());
232
- }, de = (t) => {
233
- K("formatBlock", et[t]);
234
- }, V = () => {
235
- if (i) return;
236
- J();
237
- const t = window.prompt("Enter URL");
238
- t && (document.execCommand("createLink", !1, t), k(), M());
239
- };
240
- E(() => {
241
- const t = tt(s || I()), r = F(t);
242
- $(r), l.current && l.current.innerHTML !== t && (l.current.innerHTML = t);
243
- }, [s]), E(() => {
244
- l.current && (l.current.innerHTML.trim() || (l.current.innerHTML = ee(v)));
245
- }, [v]), E(() => {
246
- var r;
247
- const t = (r = A.current) == null ? void 0 : r.getBoundingClientRect().width;
248
- t && ae(t);
249
- }, [H]), E(() => {
250
- if (!b) {
251
- U(null);
252
- return;
253
- }
254
- const t = j.current;
255
- if (!t) return;
256
- const r = () => {
257
- const Q = t.getBoundingClientRect().width;
258
- Q > 0 && U(Q);
259
- };
260
- r();
261
- const R = new ResizeObserver(() => {
262
- r();
263
- });
264
- return R.observe(t), window.addEventListener("resize", r), () => {
265
- R.disconnect(), window.removeEventListener("resize", r);
266
- };
267
- }, [b, u, i, x]);
268
- const g = (t) => /* @__PURE__ */ n(S, { content: t.tooltip, size: "sm", theme: "dark", tipSide: "top", tipAlignment: "center", disabled: !x, children: /* @__PURE__ */ n("button", { type: "button", className: _(e.toolButton, t.active && e.toolButtonActive), onMouseDown: (r) => r.preventDefault(), onClick: () => K(t.command, t.value), "aria-label": t.tooltip, disabled: i, children: /* @__PURE__ */ n(O, { icon: t.icon, className: e.toolIcon }) }) }, t.id), L = [{
269
- id: "bold",
270
- icon: "ap-icon-bold",
271
- command: "bold",
272
- tooltip: "Bold",
273
- active: f.bold
274
- }, {
275
- id: "italic",
276
- icon: "ap-icon-italic",
277
- command: "italic",
278
- tooltip: "Italic",
279
- active: f.italic
280
- }, {
281
- id: "underline",
282
- icon: "ap-icon-underline",
283
- command: "underline",
284
- tooltip: "Underline",
285
- active: f.underline
286
- }, {
287
- id: "align-left",
288
- icon: "ap-icon-left",
289
- command: "justifyLeft",
290
- tooltip: "Align left",
291
- active: f.justifyLeft
292
- }, {
293
- id: "align-center",
294
- icon: "ap-icon-bar",
295
- command: "justifyCenter",
296
- tooltip: "Align center",
297
- active: f.justifyCenter
298
- }, {
299
- id: "align-right",
300
- icon: "ap-icon-right",
301
- command: "justifyRight",
302
- tooltip: "Align right",
303
- active: f.justifyRight
304
- }, {
305
- id: "bulleted",
306
- icon: "ap-icon-list",
307
- command: "insertUnorderedList",
308
- tooltip: "Bulleted list",
309
- active: f.insertUnorderedList
310
- }], G = L.filter((t) => ["bold", "italic", "underline"].includes(t.id)), X = L.filter((t) => ["align-left", "align-center", "align-right"].includes(t.id)), Y = L.filter((t) => ["bulleted"].includes(t.id)), Z = () => {
311
- var t;
312
- return /* @__PURE__ */ n("div", { className: e.formatControl, children: /* @__PURE__ */ c(me, { open: H, onOpenChange: D, children: [
313
- /* @__PURE__ */ c(fe, { ref: A, disabled: i, className: _(e.selectTrigger, H && e.selectTriggerOpen), children: [
314
- /* @__PURE__ */ n("span", { className: e.selectTriggerLabel, children: ((t = P.find((r) => r.value === W)) == null ? void 0 : t.label) || "Paragraph" }),
315
- /* @__PURE__ */ n(O, { icon: "ap-icon-expand-more", className: e.selectIcon })
316
- ] }),
317
- /* @__PURE__ */ n(_e, { children: /* @__PURE__ */ n(pe, { align: "end", side: "bottom", sideOffset: 6, collisionPadding: 8, className: e.formatMenu, style: {
318
- minWidth: ie || 180,
319
- zIndex: 9999
320
- }, children: /* @__PURE__ */ n("div", { className: e.formatMenuOptions, children: P.map((r) => /* @__PURE__ */ n("button", { type: "button", className: _(e.formatMenuOption, ot(r.value), r.value === W && e.formatMenuOptionSelected), onMouseDown: (R) => R.preventDefault(), onClick: () => {
321
- de(r.value), D(!1);
322
- }, children: r.label }, r.value)) }) }) })
323
- ] }) });
324
- };
325
- return /* @__PURE__ */ c("div", { className: _(e.container, o), children: [
326
- a && /* @__PURE__ */ c("label", { className: e.label, htmlFor: B, children: [
327
- a,
328
- d && /* @__PURE__ */ n("span", { className: e.required, children: "*" })
329
- ] }),
330
- /* @__PURE__ */ c("div", { className: _(e.frame, re && e.frameFocused, i && e.frameDisabled), style: {
331
- width: q ? `${q}px` : void 0
332
- }, children: [
333
- b && /* @__PURE__ */ n("div", { className: _(e.toolbar, u === "stacked" && e.toolbarStacked), children: /* @__PURE__ */ n("div", { ref: j, className: e.toolbarContent, children: u === "stacked" ? /* @__PURE__ */ c("div", { className: e.toolbarPanel, children: [
334
- /* @__PURE__ */ c("div", { className: e.toolbarRow, children: [
335
- /* @__PURE__ */ n("div", { className: e.actions, children: G.map(g) }),
336
- /* @__PURE__ */ n("div", { className: e.actions, children: X.map(g) })
337
- ] }),
338
- /* @__PURE__ */ c("div", { className: e.toolbarRow, children: [
339
- /* @__PURE__ */ n("div", { className: e.actions, children: Y.map(g) }),
340
- /* @__PURE__ */ n("div", { className: e.toolbarLinkSlot, children: /* @__PURE__ */ n(S, { content: "Insert link", size: "sm", theme: "dark", tipSide: "top", tipAlignment: "center", disabled: !x, children: /* @__PURE__ */ n("button", { type: "button", className: e.toolButton, onMouseDown: (t) => t.preventDefault(), onClick: V, "aria-label": "Insert link", disabled: i, children: /* @__PURE__ */ n(O, { icon: "ap-icon-link", className: e.toolIcon }) }) }) }),
341
- Z()
342
- ] })
343
- ] }) : /* @__PURE__ */ n("div", { className: e.toolbarPanel, children: /* @__PURE__ */ c("div", { className: e.toolbarRow, children: [
344
- /* @__PURE__ */ n("div", { className: e.actions, children: G.map(g) }),
345
- /* @__PURE__ */ n("div", { className: e.actions, children: X.map(g) }),
346
- /* @__PURE__ */ n("div", { className: e.actions, children: Y.map(g) }),
347
- /* @__PURE__ */ n("div", { className: e.toolbarLinkSlot, children: /* @__PURE__ */ n(S, { content: "Insert link", size: "sm", theme: "dark", tipSide: "top", tipAlignment: "center", disabled: !x, children: /* @__PURE__ */ n("button", { type: "button", className: e.toolButton, onMouseDown: (t) => t.preventDefault(), onClick: V, "aria-label": "Insert link", disabled: i, children: /* @__PURE__ */ n(O, { icon: "ap-icon-link", className: e.toolIcon }) }) }) }),
348
- Z()
349
- ] }) }) }) }),
350
- /* @__PURE__ */ n("div", { id: B, ref: l, className: e.editor, contentEditable: !i, suppressContentEditableWarning: !0, role: "textbox", "aria-multiline": "true", "aria-label": a || "Rich text editor", "data-placeholder": h, onInput: k, onFocus: () => {
351
- z(!0), M();
352
- }, onBlur: () => z(!1), onKeyUp: M, onMouseUp: M, style: {
353
- minHeight: `${oe * 20}px`,
354
- resize: ne ? "vertical" : "none"
355
- } }),
356
- T && /* @__PURE__ */ n("div", { className: _(e.wordCount, m && N > m && e.wordCountExceeded), children: m ? `${N}/${m}` : N })
357
- ] })
358
- ] });
359
- }
360
- export {
361
- st as R,
362
- e as s
363
- };