@forgedevstack/bear 1.1.1 → 1.1.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.
Files changed (58) hide show
  1. package/dist/components/AlertDialog/AlertDialog.cjs +1 -0
  2. package/dist/components/AlertDialog/AlertDialog.const.cjs +1 -0
  3. package/dist/components/AlertDialog/AlertDialog.const.d.ts +5 -0
  4. package/dist/components/AlertDialog/AlertDialog.const.js +8 -0
  5. package/dist/components/AlertDialog/AlertDialog.d.ts +4 -0
  6. package/dist/components/AlertDialog/AlertDialog.js +107 -0
  7. package/dist/components/AlertDialog/AlertDialog.types.d.ts +34 -0
  8. package/dist/components/AlertDialog/index.d.ts +3 -0
  9. package/dist/components/AspectRatio/AspectRatio.cjs +1 -0
  10. package/dist/components/AspectRatio/AspectRatio.d.ts +3 -0
  11. package/dist/components/AspectRatio/AspectRatio.js +29 -0
  12. package/dist/components/AspectRatio/AspectRatio.types.d.ts +9 -0
  13. package/dist/components/AspectRatio/index.d.ts +2 -0
  14. package/dist/components/Button/Button.cjs +1 -1
  15. package/dist/components/Button/Button.constants.cjs +2 -2
  16. package/dist/components/Button/Button.constants.d.ts +1 -0
  17. package/dist/components/Button/Button.constants.js +10 -3
  18. package/dist/components/Button/Button.js +92 -84
  19. package/dist/components/Button/Button.types.d.ts +2 -0
  20. package/dist/components/FormField/FormField.cjs +1 -0
  21. package/dist/components/FormField/FormField.const.cjs +1 -0
  22. package/dist/components/FormField/FormField.const.d.ts +20 -0
  23. package/dist/components/FormField/FormField.const.js +23 -0
  24. package/dist/components/FormField/FormField.d.ts +3 -0
  25. package/dist/components/FormField/FormField.js +127 -0
  26. package/dist/components/FormField/FormField.types.d.ts +23 -0
  27. package/dist/components/FormField/index.d.ts +2 -0
  28. package/dist/components/Input/Input.cjs +1 -1
  29. package/dist/components/Input/Input.js +81 -44
  30. package/dist/components/Input/Input.types.d.ts +10 -0
  31. package/dist/components/Input/components/ClearIcon/ClearIcon.cjs +1 -0
  32. package/dist/components/Input/components/ClearIcon/ClearIcon.d.ts +7 -0
  33. package/dist/components/Input/components/ClearIcon/ClearIcon.js +25 -0
  34. package/dist/components/Input/components/ClearIcon/index.d.ts +1 -0
  35. package/dist/components/InputGroup/InputGroup.cjs +1 -0
  36. package/dist/components/InputGroup/InputGroup.d.ts +4 -0
  37. package/dist/components/InputGroup/InputGroup.js +63 -0
  38. package/dist/components/InputGroup/InputGroup.types.d.ts +23 -0
  39. package/dist/components/InputGroup/index.d.ts +2 -0
  40. package/dist/components/PasswordInput/PasswordInput.cjs +1 -0
  41. package/dist/components/PasswordInput/PasswordInput.d.ts +3 -0
  42. package/dist/components/PasswordInput/PasswordInput.js +61 -0
  43. package/dist/components/PasswordInput/PasswordInput.types.d.ts +18 -0
  44. package/dist/components/PasswordInput/index.d.ts +2 -0
  45. package/dist/components/ResizableTextarea/ResizableTextarea.cjs +1 -1
  46. package/dist/components/ResizableTextarea/ResizableTextarea.js +90 -54
  47. package/dist/components/ResizableTextarea/ResizableTextarea.types.d.ts +10 -0
  48. package/dist/components/RichEditor/RichEditor.cjs +1 -1
  49. package/dist/components/RichEditor/RichEditor.js +186 -169
  50. package/dist/components/RichEditor/RichEditor.types.d.ts +4 -0
  51. package/dist/components/index.cjs +1 -1
  52. package/dist/components/index.d.ts +10 -0
  53. package/dist/components/index.js +44 -34
  54. package/dist/index.cjs +1 -1
  55. package/dist/index.js +126 -116
  56. package/dist/styles.css +1 -1
  57. package/dist/types/component.types.d.ts +13 -0
  58. package/package.json +1 -4
@@ -1,60 +1,96 @@
1
- import { jsxs as k, jsx as f } from "react/jsx-runtime";
2
- import { useRef as d, useState as L, useCallback as _ } from "react";
3
- import { cn as g } from "../../utils/cn.js";
4
- import { DEFAULT_MIN_HEIGHT as D, DEFAULT_MAX_HEIGHT as I } from "./ResizableTextarea.const.js";
5
- const P = ({
6
- minHeight: e = D,
7
- maxHeight: t = I,
8
- resizable: a = !0,
9
- className: w,
10
- style: m,
11
- testId: y,
12
- ...x
1
+ import { jsxs as d, jsx as s } from "react/jsx-runtime";
2
+ import { useRef as p, useState as j, useCallback as A } from "react";
3
+ import { cn as c } from "../../utils/cn.js";
4
+ import { DEFAULT_MIN_HEIGHT as U, DEFAULT_MAX_HEIGHT as Y } from "./ResizableTextarea.const.js";
5
+ const O = ({
6
+ label: x,
7
+ helperText: m,
8
+ error: u,
9
+ minHeight: e = U,
10
+ maxHeight: t = Y,
11
+ resizable: n = !0,
12
+ showCharCount: v = !1,
13
+ charCountMax: L,
14
+ className: N,
15
+ style: R,
16
+ testId: B,
17
+ ...r
13
18
  }) => {
14
- const h = d(null), [i, E] = L(e), b = d(0), c = d(e), T = _((r) => {
15
- var p, v;
16
- if (!a) return;
17
- r.preventDefault(), b.current = r.clientY, c.current = i, (v = (p = r.target).setPointerCapture) == null || v.call(p, r.pointerId);
18
- const u = (n) => {
19
- const s = n.clientY - b.current;
20
- let o = c.current + s;
21
- e > 0 && (o = Math.max(e, o)), t > 0 && (o = Math.min(t, o)), E(o);
22
- }, l = () => {
23
- var n, s;
24
- (s = (n = r.target).releasePointerCapture) == null || s.call(n, r.pointerId), window.removeEventListener("pointermove", u), window.removeEventListener("pointerup", l);
19
+ const f = !!u, i = L ?? r.maxLength, y = typeof r.value == "string" ? r.value.length : typeof r.defaultValue == "string" ? r.defaultValue.length : 0, M = i != null && y > i, z = p(null), [g, D] = j(e), h = p(0), _ = p(e), I = A((a) => {
20
+ var T, E;
21
+ if (!n) return;
22
+ a.preventDefault(), h.current = a.clientY, _.current = g, (E = (T = a.target).setPointerCapture) == null || E.call(T, a.pointerId);
23
+ const w = (l) => {
24
+ const b = l.clientY - h.current;
25
+ let o = _.current + b;
26
+ e > 0 && (o = Math.max(e, o)), t > 0 && (o = Math.min(t, o)), D(o);
27
+ }, k = () => {
28
+ var l, b;
29
+ (b = (l = a.target).releasePointerCapture) == null || b.call(l, a.pointerId), window.removeEventListener("pointermove", w), window.removeEventListener("pointerup", k);
25
30
  };
26
- window.addEventListener("pointermove", u), window.addEventListener("pointerup", l);
27
- }, [a, i, e, t]);
28
- return /* @__PURE__ */ k("div", { className: g("Bear-ResizableTextarea bear-relative", w), "data-testid": y, children: [
29
- /* @__PURE__ */ f(
30
- "textarea",
31
- {
32
- ref: h,
33
- className: g(
34
- "bear-w-full bear-rounded-lg bear-border bear-border-gray-300 dark:bear-border-gray-600",
35
- "bear-bg-white dark:bear-bg-gray-900 bear-text-gray-900 dark:bear-text-gray-100",
36
- "bear-p-3 bear-resize-none focus:bear-outline-none focus:bear-ring-2 focus:bear-ring-pink-500/50"
37
- ),
38
- style: {
39
- ...m,
40
- minHeight: a ? e : void 0,
41
- height: a ? i : void 0,
42
- maxHeight: t > 0 ? t : void 0
43
- },
44
- ...x
45
- }
46
- ),
47
- a && /* @__PURE__ */ f(
48
- "div",
49
- {
50
- role: "separator",
51
- onPointerDown: T,
52
- className: "Bear-ResizableTextarea__handle bear-absolute bear-right-0 bear-bottom-0 bear-w-4 bear-h-4 bear-cursor-s-resize bear-opacity-50 hover:bear-opacity-100",
53
- style: { background: "linear-gradient(135deg, transparent 50%, currentColor 50%)" }
54
- }
55
- )
31
+ window.addEventListener("pointermove", w), window.addEventListener("pointerup", k);
32
+ }, [n, g, e, t]);
33
+ return /* @__PURE__ */ d("div", { className: c("Bear-ResizableTextarea bear-flex bear-flex-col bear-gap-1.5", N), "data-testid": B, children: [
34
+ x && /* @__PURE__ */ s("label", { className: "Bear-ResizableTextarea__label bear-text-sm bear-font-medium bear-text-gray-700 dark:bear-text-gray-300", children: x }),
35
+ /* @__PURE__ */ d("div", { className: "bear-relative", children: [
36
+ /* @__PURE__ */ s(
37
+ "textarea",
38
+ {
39
+ ref: z,
40
+ "aria-invalid": f || void 0,
41
+ className: c(
42
+ "bear-w-full bear-rounded-lg bear-border",
43
+ "bear-bg-white dark:bear-bg-gray-900 bear-text-gray-900 dark:bear-text-gray-100",
44
+ "bear-p-3 bear-resize-none focus:bear-outline-none focus:bear-ring-2",
45
+ f ? "bear-border-red-500 focus:bear-ring-red-500" : "bear-border-gray-300 dark:bear-border-gray-600 focus:bear-ring-pink-500/50"
46
+ ),
47
+ style: {
48
+ ...R,
49
+ minHeight: n ? e : void 0,
50
+ height: n ? g : void 0,
51
+ maxHeight: t > 0 ? t : void 0
52
+ },
53
+ ...r
54
+ }
55
+ ),
56
+ n && /* @__PURE__ */ s(
57
+ "div",
58
+ {
59
+ role: "separator",
60
+ onPointerDown: I,
61
+ className: "Bear-ResizableTextarea__handle bear-absolute bear-right-0 bear-bottom-0 bear-w-4 bear-h-4 bear-cursor-s-resize bear-opacity-50 hover:bear-opacity-100",
62
+ style: { background: "linear-gradient(135deg, transparent 50%, currentColor 50%)" }
63
+ }
64
+ )
65
+ ] }),
66
+ /* @__PURE__ */ d("div", { className: "Bear-ResizableTextarea__footer bear-flex bear-items-center bear-justify-between bear-gap-2", children: [
67
+ m || u ? /* @__PURE__ */ s(
68
+ "p",
69
+ {
70
+ className: c(
71
+ "Bear-ResizableTextarea__helper bear-text-sm bear-flex-1",
72
+ f ? "bear-text-red-500" : "bear-text-gray-500 dark:bear-text-gray-400"
73
+ ),
74
+ children: u || m
75
+ }
76
+ ) : v ? /* @__PURE__ */ s("span", {}) : null,
77
+ v && i != null && /* @__PURE__ */ d(
78
+ "span",
79
+ {
80
+ className: c(
81
+ "Bear-ResizableTextarea__char-count bear-text-xs bear-tabular-nums bear-shrink-0",
82
+ M ? "bear-text-red-500" : "bear-text-gray-400 dark:bear-text-gray-500"
83
+ ),
84
+ children: [
85
+ y,
86
+ "/",
87
+ i
88
+ ]
89
+ }
90
+ )
91
+ ] })
56
92
  ] });
57
93
  };
58
94
  export {
59
- P as ResizableTextarea
95
+ O as ResizableTextarea
60
96
  };
@@ -1,5 +1,11 @@
1
1
  import { TextareaHTMLAttributes } from 'react';
2
2
  export interface ResizableTextareaProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'style'> {
3
+ /** Textarea label */
4
+ label?: string;
5
+ /** Helper text below textarea */
6
+ helperText?: string;
7
+ /** Error message (shows red border + text) */
8
+ error?: string;
3
9
  /** Minimum height in pixels */
4
10
  minHeight?: number;
5
11
  /** Maximum height in pixels (0 = unbounded) */
@@ -12,4 +18,8 @@ export interface ResizableTextareaProps extends Omit<TextareaHTMLAttributes<HTML
12
18
  style?: React.CSSProperties;
13
19
  /** Test ID */
14
20
  testId?: string;
21
+ /** Show live character count (requires maxLength or charCountMax) */
22
+ showCharCount?: boolean;
23
+ /** Max chars for counter display (alternative to maxLength when you don't want native enforcement) */
24
+ charCountMax?: number;
15
25
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),c=require("react"),T=require("../../utils/cn.cjs"),u=require("./helpers/formatHelpers.cjs"),f=require("./RichEditor.const.cjs"),re=require("../../hooks/useMediaQuery.cjs"),C=require("./components/ToolbarButton/ToolbarButton.cjs"),se=require("./components/ToolbarDropdown/ToolbarDropdown.cjs"),H=require("./components/ToolbarColorPicker/ToolbarColorPicker.cjs"),le=require("./components/ToolbarMore/ToolbarMore.cjs"),r=require("../Icon/icons/editor.cjs"),ae=6,ce=B=>{const{value:x,defaultValue:E="",onChange:R,placeholder:S="Start typing...",disabled:o=!1,readOnly:i=!1,minHeight:j=f.RICH_EDITOR_MIN_HEIGHT,maxHeight:b,toolbar:z=f.RICH_EDITOR_DEFAULT_TOOLBAR,className:A="",testId:D,id:v,allowImagePaste:y=!0,...N}=B,a=c.useRef(null),p=re.useMediaQuery(`(max-width: ${f.RICH_EDITOR_MOBILE_BREAKPOINT}px)`),k=p?f.RICH_EDITOR_MOBILE_TOOLBAR:z,[F,M]=c.useState(new Set),[q,L]=c.useState("p"),[w,U]=c.useState("#000000"),[P,V]=c.useState("#fef08a"),[J,G]=c.useState([]),[$,Q]=c.useState([]);c.useEffect(()=>{const e="bear-rich-editor-styles";if(!document.getElementById(e)){const n=document.createElement("style");n.id=e,n.textContent=f.RICH_EDITOR_CONTENT_STYLES,document.head.appendChild(n)}},[]),c.useEffect(()=>{a.current&&x!==void 0&&a.current.innerHTML!==x&&(a.current.innerHTML=x)},[x]),c.useEffect(()=>{a.current&&E&&!x&&(a.current.innerHTML=E)},[]);const h=c.useCallback(()=>{M(u.getActiveFormats());const e=u.queryCommandValue("formatBlock");e&&L(e.toLowerCase().replace(/[<>]/g,""))},[]),l=c.useCallback(()=>{a.current&&R&&R(a.current.innerHTML),h()},[R,h]),K=c.useCallback(e=>{var d;if(o||i)return;(d=a.current)==null||d.focus();const n=f.RICH_EDITOR_BUTTON_CONFIG[e];if(!n)return;const g="value"in n?n.value:void 0;g?u.execCommand(n.command,g):u.execCommand(n.command),h(),l()},[o,i,h,l]),Y=c.useCallback(e=>{var n;o||i||((n=a.current)==null||n.focus(),u.execCommand("formatBlock",e),L(e),l())},[o,i,l]),W=c.useCallback(()=>{var d;if(o||i)return;const e=window.getSelection(),n=e&&e.toString().length>0,g=prompt("Enter URL:",n?"":"https://");g&&((d=a.current)==null||d.focus(),u.insertLink(g),l())},[o,i,l]),m=c.useCallback((e,n)=>{if(!e)return;(n==="text"?G:Q)(d=>{const s=d.filter(I=>I!==e);return[e,...s].slice(0,ae)})},[]),X=c.useCallback(e=>{var n;o||i||((n=a.current)==null||n.focus(),u.setTextColor(e),U(e),m(e,"text"),l())},[o,i,l,m]),Z=c.useCallback(e=>{var n;o||i||((n=a.current)==null||n.focus(),u.setHighlightColor(e),V(e),m(e,"highlight"),l())},[o,i,l,m]),ee=c.useCallback(e=>{var n;o||i||((n=a.current)==null||n.focus(),u.setTextColor(e),l())},[o,i,l]),te=c.useCallback(e=>{var n;o||i||((n=a.current)==null||n.focus(),u.setHighlightColor(e),l())},[o,i,l]),ne=c.useCallback(async e=>{var g;if(!y)return;const n=(g=e.clipboardData)==null?void 0:g.items;if(n)for(let d=0;d<n.length;d++){const s=n[d];if(s.type.startsWith("image/")){e.preventDefault();const I=s.getAsFile();if(I){const _=await u.fileToDataUrl(I);u.insertImage(_),l()}return}}},[y,l]),oe=c.useCallback(()=>{if(o||i)return;const e=document.createElement("input");e.type="file",e.accept="image/*",e.onchange=async n=>{var d,s;const g=(d=n.target.files)==null?void 0:d[0];if(g){const I=await u.fileToDataUrl(g);(s=a.current)==null||s.focus(),u.insertImage(I),l()}},e.click()},[o,i,l]),ie={bold:t.jsx(r.BoldIcon,{size:16}),italic:t.jsx(r.ItalicIcon,{size:16}),underline:t.jsx(r.UnderlineIcon,{size:16}),strikethrough:t.jsx(r.StrikethroughIcon,{size:16}),heading1:t.jsx(r.Heading1Icon,{size:16}),heading2:t.jsx(r.Heading2Icon,{size:16}),heading3:t.jsx(r.Heading3Icon,{size:16}),bulletList:t.jsx(r.ListBulletIcon,{size:16}),orderedList:t.jsx(r.ListNumberedIcon,{size:16}),blockquote:t.jsx(r.QuoteIcon,{size:16}),code:t.jsx(r.CodeIcon,{size:16}),link:t.jsx(r.InsertLinkIcon,{size:16}),alignLeft:t.jsx(r.AlignLeftIcon,{size:16}),alignCenter:t.jsx(r.AlignCenterIcon,{size:16}),alignRight:t.jsx(r.AlignRightIcon,{size:16}),alignJustify:t.jsx(r.AlignJustifyIcon,{size:16}),image:t.jsx(r.InsertPhotoIcon,{size:16}),indent:t.jsx(r.IndentIncreaseIcon,{size:16}),outdent:t.jsx(r.IndentDecreaseIcon,{size:16}),clearFormat:t.jsx(r.FormatClearIcon,{size:16}),table:t.jsx(r.TableIcon,{size:16})},O=(e,n)=>{if(e==="divider")return t.jsx("div",{className:T.cn("Bear-RichEditor__divider",f.RICH_EDITOR_DIVIDER_CLASSES)},`divider-${n}`);if(e==="headingDropdown")return t.jsx(se.ToolbarDropdown,{options:f.RICH_EDITOR_HEADING_OPTIONS,value:q,onChange:Y,title:"Text Style",disabled:o||i,icon:t.jsx(r.TextIcon,{size:16})},"heading-dropdown");if(e==="textColor")return t.jsx(H.ToolbarColorPicker,{value:w,onChange:X,title:"Text Color",disabled:o||i,type:"text",recentColors:J,onApplyLast:ee},"text-color");if(e==="highlightColor")return t.jsx(H.ToolbarColorPicker,{value:P,onChange:Z,title:"Highlight Color",disabled:o||i,type:"highlight",recentColors:$,onApplyLast:te},"highlight-color");if(e==="link")return t.jsx(C.ToolbarButton,{icon:t.jsx(r.InsertLinkIcon,{size:16}),title:"Insert Link",onClick:W,disabled:o||i},"link");if(e==="image")return t.jsx(C.ToolbarButton,{icon:t.jsx(r.InsertPhotoIcon,{size:16}),title:"Insert Image",onClick:oe,disabled:o||i},"image");if(e==="alignLeft")return t.jsx(C.ToolbarButton,{icon:t.jsx(r.AlignLeftIcon,{size:16}),title:"Align Left",onClick:()=>{var s;(s=a.current)==null||s.focus(),u.execCommand("justifyLeft"),l()},disabled:o||i},"alignLeft");if(e==="alignCenter")return t.jsx(C.ToolbarButton,{icon:t.jsx(r.AlignCenterIcon,{size:16}),title:"Align Center",onClick:()=>{var s;(s=a.current)==null||s.focus(),u.execCommand("justifyCenter"),l()},disabled:o||i},"alignCenter");if(e==="alignRight")return t.jsx(C.ToolbarButton,{icon:t.jsx(r.AlignRightIcon,{size:16}),title:"Align Right",onClick:()=>{var s;(s=a.current)==null||s.focus(),u.execCommand("justifyRight"),l()},disabled:o||i},"alignRight");if(e==="alignJustify")return t.jsx(C.ToolbarButton,{icon:t.jsx(r.AlignJustifyIcon,{size:16}),title:"Justify",onClick:()=>{var s;(s=a.current)==null||s.focus(),u.execCommand("justifyFull"),l()},disabled:o||i},"alignJustify");if(e==="indent")return t.jsx(C.ToolbarButton,{icon:t.jsx(r.IndentIncreaseIcon,{size:16}),title:"Increase Indent",onClick:()=>{var s;(s=a.current)==null||s.focus(),u.execCommand("indent"),l()},disabled:o||i},"indent");if(e==="outdent")return t.jsx(C.ToolbarButton,{icon:t.jsx(r.IndentDecreaseIcon,{size:16}),title:"Decrease Indent",onClick:()=>{var s;(s=a.current)==null||s.focus(),u.execCommand("outdent"),l()},disabled:o||i},"outdent");if(e==="clearFormat")return t.jsx(C.ToolbarButton,{icon:t.jsx(r.FormatClearIcon,{size:16}),title:"Clear Formatting",onClick:()=>{var s;(s=a.current)==null||s.focus(),u.execCommand("removeFormat"),l()},disabled:o||i},"clearFormat");if(e==="more"){const s=p?f.RICH_EDITOR_MOBILE_MORE_ITEMS:["alignLeft","alignCenter","alignRight","alignJustify","indent","outdent","blockquote","code","clearFormat"];return t.jsx(le.ToolbarMore,{disabled:o||i,isMobile:p,children:s.map((I,_)=>O(I,_+1e3))},"more")}const g=f.RICH_EDITOR_BUTTON_CONFIG[e],d=ie[e];return!g||!d?null:t.jsx(C.ToolbarButton,{icon:d,title:g.title,active:F.has(e),onClick:()=>K(e),disabled:o||i},e)};return t.jsxs("div",{id:v,"data-testid":D,className:T.cn("Bear-RichEditor",f.RICH_EDITOR_ROOT_CLASSES,o&&"Bear-RichEditor--disabled",i&&"Bear-RichEditor--readonly",A),...N,children:[k.length>0&&t.jsx("div",{className:T.cn("Bear-RichEditor__toolbar",f.RICH_EDITOR_TOOLBAR_CLASSES),children:k.map((e,n)=>O(e,n))}),t.jsx("div",{ref:a,contentEditable:!o&&!i,onInput:l,onSelect:h,onKeyUp:h,onMouseUp:h,onPaste:ne,"data-placeholder":S,className:T.cn("Bear-RichEditor__content",f.RICH_EDITOR_CONTENT_CLASSES,"[&:empty]:before:bear-content-[attr(data-placeholder)] [&:empty]:before:bear-text-gray-400 [&:empty]:before:bear-pointer-events-none",o&&"Bear-RichEditor__content--disabled bear-opacity-50 bear-cursor-not-allowed"),style:{minHeight:typeof j=="number"?`${j}px`:j,maxHeight:b?typeof b=="number"?`${b}px`:b:void 0,overflowY:b?"auto":void 0}})]})};exports.RichEditor=ce;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),c=require("react"),m=require("../../utils/cn.cjs"),u=require("./helpers/formatHelpers.cjs"),f=require("./RichEditor.const.cjs"),ce=require("../../hooks/useMediaQuery.cjs"),C=require("./components/ToolbarButton/ToolbarButton.cjs"),ue=require("./components/ToolbarDropdown/ToolbarDropdown.cjs"),z=require("./components/ToolbarColorPicker/ToolbarColorPicker.cjs"),de=require("./components/ToolbarMore/ToolbarMore.cjs"),i=require("../Icon/icons/editor.cjs"),ge=6,fe=A=>{const{value:x,defaultValue:k="",onChange:R,placeholder:v="Start typing...",disabled:o=!1,readOnly:r=!1,minHeight:j=f.RICH_EDITOR_MIN_HEIGHT,maxHeight:b,toolbar:D=f.RICH_EDITOR_DEFAULT_TOOLBAR,className:N="",testId:M,id:F,allowImagePaste:L=!0,showCharCount:p=!1,charCountMax:_,...w}=A,l=c.useRef(null),E=ce.useMediaQuery(`(max-width: ${f.RICH_EDITOR_MOBILE_BREAKPOINT}px)`),O=E?f.RICH_EDITOR_MOBILE_TOOLBAR:D,[q,U]=c.useState(new Set),[P,H]=c.useState("p"),[B,V]=c.useState(0),[J,G]=c.useState("#000000"),[$,Q]=c.useState("#fef08a"),[K,Y]=c.useState([]),[W,X]=c.useState([]);c.useEffect(()=>{const e="bear-rich-editor-styles";if(!document.getElementById(e)){const n=document.createElement("style");n.id=e,n.textContent=f.RICH_EDITOR_CONTENT_STYLES,document.head.appendChild(n)}},[]),c.useEffect(()=>{l.current&&x!==void 0&&l.current.innerHTML!==x&&(l.current.innerHTML=x)},[x]),c.useEffect(()=>{l.current&&k&&!x&&(l.current.innerHTML=k)},[]);const I=c.useCallback(()=>{U(u.getActiveFormats());const e=u.queryCommandValue("formatBlock");e&&H(e.toLowerCase().replace(/[<>]/g,""))},[]),a=c.useCallback(()=>{var e;l.current&&(R&&R(l.current.innerHTML),p&&V(((e=l.current.textContent)==null?void 0:e.length)??0)),I()},[R,I,p]),Z=c.useCallback(e=>{var d;if(o||r)return;(d=l.current)==null||d.focus();const n=f.RICH_EDITOR_BUTTON_CONFIG[e];if(!n)return;const g="value"in n?n.value:void 0;g?u.execCommand(n.command,g):u.execCommand(n.command),I(),a()},[o,r,I,a]),ee=c.useCallback(e=>{var n;o||r||((n=l.current)==null||n.focus(),u.execCommand("formatBlock",e),H(e),a())},[o,r,a]),te=c.useCallback(()=>{var d;if(o||r)return;const e=window.getSelection(),n=e&&e.toString().length>0,g=prompt("Enter URL:",n?"":"https://");g&&((d=l.current)==null||d.focus(),u.insertLink(g),a())},[o,r,a]),T=c.useCallback((e,n)=>{if(!e)return;(n==="text"?Y:X)(d=>{const s=d.filter(h=>h!==e);return[e,...s].slice(0,ge)})},[]),ne=c.useCallback(e=>{var n;o||r||((n=l.current)==null||n.focus(),u.setTextColor(e),G(e),T(e,"text"),a())},[o,r,a,T]),oe=c.useCallback(e=>{var n;o||r||((n=l.current)==null||n.focus(),u.setHighlightColor(e),Q(e),T(e,"highlight"),a())},[o,r,a,T]),re=c.useCallback(e=>{var n;o||r||((n=l.current)==null||n.focus(),u.setTextColor(e),a())},[o,r,a]),ie=c.useCallback(e=>{var n;o||r||((n=l.current)==null||n.focus(),u.setHighlightColor(e),a())},[o,r,a]),se=c.useCallback(async e=>{var g;if(!L)return;const n=(g=e.clipboardData)==null?void 0:g.items;if(n)for(let d=0;d<n.length;d++){const s=n[d];if(s.type.startsWith("image/")){e.preventDefault();const h=s.getAsFile();if(h){const y=await u.fileToDataUrl(h);u.insertImage(y),a()}return}}},[L,a]),ae=c.useCallback(()=>{if(o||r)return;const e=document.createElement("input");e.type="file",e.accept="image/*",e.onchange=async n=>{var d,s;const g=(d=n.target.files)==null?void 0:d[0];if(g){const h=await u.fileToDataUrl(g);(s=l.current)==null||s.focus(),u.insertImage(h),a()}},e.click()},[o,r,a]),le={bold:t.jsx(i.BoldIcon,{size:16}),italic:t.jsx(i.ItalicIcon,{size:16}),underline:t.jsx(i.UnderlineIcon,{size:16}),strikethrough:t.jsx(i.StrikethroughIcon,{size:16}),heading1:t.jsx(i.Heading1Icon,{size:16}),heading2:t.jsx(i.Heading2Icon,{size:16}),heading3:t.jsx(i.Heading3Icon,{size:16}),bulletList:t.jsx(i.ListBulletIcon,{size:16}),orderedList:t.jsx(i.ListNumberedIcon,{size:16}),blockquote:t.jsx(i.QuoteIcon,{size:16}),code:t.jsx(i.CodeIcon,{size:16}),link:t.jsx(i.InsertLinkIcon,{size:16}),alignLeft:t.jsx(i.AlignLeftIcon,{size:16}),alignCenter:t.jsx(i.AlignCenterIcon,{size:16}),alignRight:t.jsx(i.AlignRightIcon,{size:16}),alignJustify:t.jsx(i.AlignJustifyIcon,{size:16}),image:t.jsx(i.InsertPhotoIcon,{size:16}),indent:t.jsx(i.IndentIncreaseIcon,{size:16}),outdent:t.jsx(i.IndentDecreaseIcon,{size:16}),clearFormat:t.jsx(i.FormatClearIcon,{size:16}),table:t.jsx(i.TableIcon,{size:16})},S=(e,n)=>{if(e==="divider")return t.jsx("div",{className:m.cn("Bear-RichEditor__divider",f.RICH_EDITOR_DIVIDER_CLASSES)},`divider-${n}`);if(e==="headingDropdown")return t.jsx(ue.ToolbarDropdown,{options:f.RICH_EDITOR_HEADING_OPTIONS,value:P,onChange:ee,title:"Text Style",disabled:o||r,icon:t.jsx(i.TextIcon,{size:16})},"heading-dropdown");if(e==="textColor")return t.jsx(z.ToolbarColorPicker,{value:J,onChange:ne,title:"Text Color",disabled:o||r,type:"text",recentColors:K,onApplyLast:re},"text-color");if(e==="highlightColor")return t.jsx(z.ToolbarColorPicker,{value:$,onChange:oe,title:"Highlight Color",disabled:o||r,type:"highlight",recentColors:W,onApplyLast:ie},"highlight-color");if(e==="link")return t.jsx(C.ToolbarButton,{icon:t.jsx(i.InsertLinkIcon,{size:16}),title:"Insert Link",onClick:te,disabled:o||r},"link");if(e==="image")return t.jsx(C.ToolbarButton,{icon:t.jsx(i.InsertPhotoIcon,{size:16}),title:"Insert Image",onClick:ae,disabled:o||r},"image");if(e==="alignLeft")return t.jsx(C.ToolbarButton,{icon:t.jsx(i.AlignLeftIcon,{size:16}),title:"Align Left",onClick:()=>{var s;(s=l.current)==null||s.focus(),u.execCommand("justifyLeft"),a()},disabled:o||r},"alignLeft");if(e==="alignCenter")return t.jsx(C.ToolbarButton,{icon:t.jsx(i.AlignCenterIcon,{size:16}),title:"Align Center",onClick:()=>{var s;(s=l.current)==null||s.focus(),u.execCommand("justifyCenter"),a()},disabled:o||r},"alignCenter");if(e==="alignRight")return t.jsx(C.ToolbarButton,{icon:t.jsx(i.AlignRightIcon,{size:16}),title:"Align Right",onClick:()=>{var s;(s=l.current)==null||s.focus(),u.execCommand("justifyRight"),a()},disabled:o||r},"alignRight");if(e==="alignJustify")return t.jsx(C.ToolbarButton,{icon:t.jsx(i.AlignJustifyIcon,{size:16}),title:"Justify",onClick:()=>{var s;(s=l.current)==null||s.focus(),u.execCommand("justifyFull"),a()},disabled:o||r},"alignJustify");if(e==="indent")return t.jsx(C.ToolbarButton,{icon:t.jsx(i.IndentIncreaseIcon,{size:16}),title:"Increase Indent",onClick:()=>{var s;(s=l.current)==null||s.focus(),u.execCommand("indent"),a()},disabled:o||r},"indent");if(e==="outdent")return t.jsx(C.ToolbarButton,{icon:t.jsx(i.IndentDecreaseIcon,{size:16}),title:"Decrease Indent",onClick:()=>{var s;(s=l.current)==null||s.focus(),u.execCommand("outdent"),a()},disabled:o||r},"outdent");if(e==="clearFormat")return t.jsx(C.ToolbarButton,{icon:t.jsx(i.FormatClearIcon,{size:16}),title:"Clear Formatting",onClick:()=>{var s;(s=l.current)==null||s.focus(),u.execCommand("removeFormat"),a()},disabled:o||r},"clearFormat");if(e==="more"){const s=E?f.RICH_EDITOR_MOBILE_MORE_ITEMS:["alignLeft","alignCenter","alignRight","alignJustify","indent","outdent","blockquote","code","clearFormat"];return t.jsx(de.ToolbarMore,{disabled:o||r,isMobile:E,children:s.map((h,y)=>S(h,y+1e3))},"more")}const g=f.RICH_EDITOR_BUTTON_CONFIG[e],d=le[e];return!g||!d?null:t.jsx(C.ToolbarButton,{icon:d,title:g.title,active:q.has(e),onClick:()=>Z(e),disabled:o||r},e)};return t.jsxs("div",{id:F,"data-testid":M,className:m.cn("Bear-RichEditor",f.RICH_EDITOR_ROOT_CLASSES,o&&"Bear-RichEditor--disabled",r&&"Bear-RichEditor--readonly",N),...w,children:[O.length>0&&t.jsx("div",{className:m.cn("Bear-RichEditor__toolbar",f.RICH_EDITOR_TOOLBAR_CLASSES),children:O.map((e,n)=>S(e,n))}),t.jsx("div",{ref:l,contentEditable:!o&&!r,onInput:a,onSelect:I,onKeyUp:I,onMouseUp:I,onPaste:se,"data-placeholder":v,className:m.cn("Bear-RichEditor__content",f.RICH_EDITOR_CONTENT_CLASSES,"[&:empty]:before:bear-content-[attr(data-placeholder)] [&:empty]:before:bear-text-gray-400 [&:empty]:before:bear-pointer-events-none",o&&"Bear-RichEditor__content--disabled bear-opacity-50 bear-cursor-not-allowed"),style:{minHeight:typeof j=="number"?`${j}px`:j,maxHeight:b?typeof b=="number"?`${b}px`:b:void 0,overflowY:b?"auto":void 0}}),p&&_!=null&&t.jsxs("div",{className:m.cn("Bear-RichEditor__char-count bear-text-xs bear-tabular-nums bear-px-3 bear-py-1.5 bear-text-right bear-border-t bear-border-gray-200 dark:bear-border-gray-700",B>_?"bear-text-red-500":"bear-text-gray-400 dark:bear-text-gray-500"),children:[B,"/",_]})]})};exports.RichEditor=fe;