@lax-wp/design-system 0.14.29 → 0.14.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/forms/icon-picker/IconPicker.cjs.js +1 -1
- package/dist/components/forms/icon-picker/IconPicker.cjs.js.map +1 -1
- package/dist/components/forms/icon-picker/IconPicker.es.js +82 -67
- package/dist/components/forms/icon-picker/IconPicker.es.js.map +1 -1
- package/dist/components/forms/md-input/RichMarkdownInput.cjs.js +1 -1
- package/dist/components/forms/md-input/RichMarkdownInput.cjs.js.map +1 -1
- package/dist/components/forms/md-input/RichMarkdownInput.es.js +39 -38
- package/dist/components/forms/md-input/RichMarkdownInput.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),j=require("../../../_virtual/index.cjs.js"),f=require("react"),v=require("react-window"),N=require("@mui/icons-material"),I=require("@mui/material"),w=require("antd"),y=require("../../data-display/typography/Typography.cjs.js"),P=require("../input-field/InputField.cjs.js"),h=require("../../../types/icon-picker.cjs.js"),q=require("../../../utils/countryFlags.cjs.js"),S=require("../shared/InputLabel.cjs.js"),R=require("../../icon/icons.generated.cjs.js");function O(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const s=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(n,a,s.get?s:{enumerable:!0,get:()=>e[a]})}}return n.default=e,Object.freeze(n)}const x=O(N),D=Object.keys(x).filter(e=>e?.endsWith("Rounded")),T=[...D||[],...(h.COUNTRY_CODES||[]).map(e=>`flag-${e}`)],L=e=>{if(e?.startsWith("flag-")){const n=e?.replace("flag-","");return h.countryNameFromCode(n||"")||n}return e.replaceAll(/([A-Z])/g," $1").trim()},F=({onChange:e,selectedIcon:n,setOpen:a})=>{const[s,p]=f.useState(""),c=(T||[]).filter(r=>{if(r?.startsWith("flag-")){const u=r?.replace("flag-","");return u?.toLowerCase()?.includes(s?.trim()?.toLowerCase()||"")||h.countryNameFromCode(u||"")?.toLowerCase()?.includes(s?.trim()?.toLowerCase()||"")}return r?.trim()?.toLowerCase()?.includes(s?.trim()?.toLowerCase()||"")}),m=(r,u)=>{if(u.stopPropagation(),n===r){e?.(null);return}e?.(r),a?.(!1)};return t.jsxs("div",{className:"flex flex-col gap-3",onKeyDown:r=>{r.key==="Enter"&&(r.preventDefault(),r.stopPropagation())},children:[t.jsx(P.InputField,{id:"input-field-icon-picker",placeholder:"Search icons...",onChange:r=>p(r||""),fieldSuffix:t.jsx(x.Search,{className:"!w-4 !h-4 text-neutral-400"})}),t.jsx(v.FixedSizeGrid,{columnCount:5,rowCount:Math.ceil((c?.length||0)/5),columnWidth:40,rowHeight:40,width:220,height:240,children:({columnIndex:r,rowIndex:u,style:l})=>{const g=u*5+r,i=c?.[g];return i?t.jsx("div",{style:l,className:"p-1",children:t.jsx(w.Tooltip,{title:L(i),placement:"bottom",children:t.jsx(I.IconButton,{type:"button",className:j("flex items-center justify-center !rounded-md hover:bg-neutral-200 dark:hover:bg-black-700",{"!bg-primary-50 dark:!bg-black-800":n===i}),onClick:d=>m(i,d),onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),d.stopPropagation())},children:t.jsx(b,{iconName:i,className:"!w-5 !h-5 text-neutral-900 dark:text-white"})})})}):null}})]})},b=({iconName:e,sx:n,className:a,isHovering:s})=>{if(e?.startsWith?.("flag-")){const c=e?.replace("flag-","");return q.getFlagComponent?.(c||"",s||!1)||t.jsx("div",{children:"-"})}const p=x?.[e];return p?t.jsx(p,{sx:n,className:a,isHovering:s}):t.jsx("div",{children:"-"})},z=({selectedIcon:e,onChange:n,label:a,required:s=!1,allowClear:p=!0,disabled:c=!1,errorMessage:m,dropdownPosition:r="bottom",className:u})=>{const[l,g]=f.useState(!1),i=f.useRef(!1),d=f.useRef(null),k=f.useRef(!1);f.useEffect(()=>{k.current&&!l&&d.current?.focus(),k.current=l},[l]);const C=o=>{o.stopPropagation(),n?.("")};return t.jsx(w.Popover,{arrow:!1,placement:r,trigger:"click",getPopupContainer:o=>o?.parentElement||document.body,open:l,onOpenChange:o=>{o?(i.current&&g(!0),i.current=!1):g(!1)},content:t.jsx(F,{onChange:n,selectedIcon:e,setOpen:g}),children:t.jsxs("div",{className:"flex flex-col gap-1",children:[a?t.jsx(S.InputLabel,{label:a||"",required:s||!1}):null,t.jsxs("button",{ref:d,type:"button",id:`btn-icon-picker-icon-${e?"selected":"unselected"}`,className:`lax-form-trigger min-w-[83px] h-8 py-1.5 px-3 rounded-md border ${c?"cursor-not-allowed opacity-60 bg-neutral-50 dark:bg-black-800":"bg-white dark:bg-black-800"} ${m?"border-red-500":"focus:border-primary-600 dark:focus:border-primary-400"} flex items-center justify-between gap-2 ${u}`,disabled:c,"aria-haspopup":"dialog","aria-expanded":l,onClick:o=>{if(c){o.preventDefault(),o.stopPropagation();return}o.detail>0&&(i.current=!0)},onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),l||o.currentTarget.closest("form")?.querySelector('button[type="submit"]')?.click())},children:[e?t.jsx(b,{iconName:e,className:"!w-5 !h-5 text-neutral-900 dark:text-white"}):t.jsx(y.Typography,{size:"small",variant:"regular",appearance:"subtitle",children:"Select Icon"}),t.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e&&p&&!c?t.jsx(x.CloseRounded,{className:"!w-5 !h-5 hover:bg-neutral-100 dark:hover:bg-black-800 rounded-full transition-colors cursor-pointer text-neutral-400 dark:text-neutral-500",onClick:C}):null,t.jsx(R.KeyboardArrowDownIcon,{size:16,className:j("shrink-0 text-neutral-400 dark:text-neutral-500 transition-transform duration-200",{"rotate-180":l})})]})]}),m&&t.jsx(y.Typography,{size:"extra-small",className:"text-red-500 font-medium",children:m})]})})},E=f.lazy(()=>Promise.resolve({default:e=>t.jsx(f.Suspense,{fallback:t.jsx("div",{className:"min-w-20 h-8 animate-pulse bg-neutral-100 dark:bg-black-800 rounded-md"}),children:t.jsx(z,{...e})})}));exports.IconPicker=E;exports.IconRenderer=b;
|
|
2
2
|
//# sourceMappingURL=IconPicker.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconPicker.cjs.js","sources":["../../../../src/components/forms/icon-picker/IconPicker.tsx"],"sourcesContent":["import classNames from 'classnames';\nimport React, { Suspense, useEffect, useRef, useState } from 'react';\nimport { FixedSizeGrid, type GridChildComponentProps } from 'react-window';\nimport * as AllIcons from '@mui/icons-material';\nimport { IconButton, type SvgIconOwnProps } from '@mui/material';\nimport { Popover, Tooltip } from \"antd\";\nimport { Typography } from \"../../data-display/typography/Typography\";\nimport { InputField } from \"../input-field/InputField\";\nimport { COUNTRY_CODES, countryNameFromCode } from \"../../../types/icon-picker\";\nimport { getFlagComponent } from \"../../../utils/countryFlags\";\nimport { InputLabel } from '../shared/InputLabel';\n\nconst roundedIconNames = Object.keys(AllIcons).filter((name) =>\n name?.endsWith(\"Rounded\")\n);\n\n// Merge icon names and country codes for the picker\nconst mergedIconNames = [\n ...(roundedIconNames || []),\n ...(COUNTRY_CODES || []).map((code) => `flag-${code}`),\n];\n\n// Utility function to convert camelCase to human-readable format\nconst formatIconName = (iconName: string): string => {\n // Handle flag icons\n if (iconName?.startsWith(\"flag-\")) {\n const code = iconName?.replace(\"flag-\", \"\");\n return countryNameFromCode(code || \"\") || code;\n }\n\n // Convert camelCase to space-separated words\n // e.g., \"PersonRounded\" -> \"Person Rounded\"\n return iconName.replaceAll(/([A-Z])/g, \" $1\").trim();\n};\n\n/** Ant Design `Popover` placement for the icon panel (bottom edge of the trigger). */\nexport type IconPickerDropdownPosition = 'bottom' | 'bottomLeft' | 'bottomRight';\n\nexport interface IconPickerContentProps {\n selectedIcon: string | null;\n onChange: (iconName: string | null) => void;\n label?: string;\n required?: boolean;\n allowClear?: boolean;\n disabled?: boolean;\n errorMessage?: string;\n /** Popover placement: `bottom` | `bottomLeft` | `bottomRight`. Default: `bottom`. */\n dropdownPosition?: IconPickerDropdownPosition;\n className?: string\n}\n\ninterface IconPickerContentInternalProps {\n onChange: (iconName: string | null) => void;\n selectedIcon: string | null;\n setOpen?: React.Dispatch<React.SetStateAction<boolean>>;\n}\n\nconst IconPickerContent = ({\n onChange,\n selectedIcon,\n setOpen,\n}: IconPickerContentInternalProps) => {\n const [searchTerm, setSearchTerm] = useState<string>(\"\");\n\n // Filter both icons and flags\n const filteredIcons = (mergedIconNames || []).filter((name) => {\n if (name?.startsWith(\"flag-\")) {\n // For flags, allow search by country code or country name\n const code = name?.replace(\"flag-\", \"\");\n return (\n code\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\") ||\n countryNameFromCode(code || \"\")\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\")\n );\n }\n return name\n ?.trim()\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\");\n });\n\n const handleClick = (icon: string, event: React.MouseEvent) => {\n event.stopPropagation();\n if (selectedIcon === icon) {\n onChange?.(null);\n return;\n }\n onChange?.(icon);\n setOpen?.(false);\n };\n\n return (\n <div \n className=\"flex flex-col gap-3\"\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n }}\n >\n <InputField\n id={`input-field-icon-picker`}\n placeholder=\"Search icons...\"\n onChange={(value) => setSearchTerm(value || \"\")}\n fieldSuffix={\n <AllIcons.Search className=\"!w-4 !h-4 text-neutral-400\" />\n }\n />\n <FixedSizeGrid\n columnCount={5}\n rowCount={Math.ceil((filteredIcons?.length || 0) / 5)}\n columnWidth={40}\n rowHeight={40}\n width={220}\n height={240}\n >\n {({ columnIndex, rowIndex, style }: GridChildComponentProps) => {\n const itemIndex = rowIndex * 5 + columnIndex;\n const iconName = filteredIcons?.[itemIndex];\n return iconName ? (\n <div style={style} className=\"p-1\">\n <Tooltip title={formatIconName(iconName)} placement='bottom'>\n <IconButton\n type='button'\n className={classNames(\n \"flex items-center justify-center !rounded-md hover:bg-neutral-200 dark:hover:bg-black-700\",\n {\n \"!bg-primary-50 dark:!bg-black-800\":\n selectedIcon === iconName,\n }\n )}\n onClick={(event) => handleClick(iconName, event)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n }}\n >\n <IconRenderer\n iconName={iconName}\n className=\"!w-5 !h-5 text-neutral-900 dark:text-white\"\n />\n </IconButton>\n </Tooltip>\n </div>\n ) : null;\n }}\n </FixedSizeGrid>\n </div>\n );\n};\n\ninterface IconRendererProps {\n iconName: string;\n sx?: SvgIconOwnProps['sx'];\n className?: string;\n isHovering?: boolean;\n}\n\nexport const IconRenderer = ({ iconName, sx, className, isHovering }: IconRendererProps) => {\n // Render flag if iconName starts with 'flag-'\n if (iconName?.startsWith?.('flag-')) {\n const code = iconName?.replace('flag-', '');\n return getFlagComponent?.(code || '', isHovering || false) || <div>-</div>;\n }\n const Icon = AllIcons?.[iconName as keyof typeof AllIcons] as React.ComponentType<{\n sx?: SvgIconOwnProps['sx'];\n className?: string;\n isHovering?: boolean;\n }>;\n\n if (!Icon) {\n return <div>-</div>;\n }\n\n return <Icon sx={sx} className={className} isHovering={isHovering} />;\n};\n\nconst IconPickerBase = ({\n selectedIcon,\n onChange,\n label,\n required = false,\n allowClear = true,\n disabled = false,\n errorMessage,\n dropdownPosition = 'bottom',\n className\n}: IconPickerContentProps) => {\n const [open, setOpen] = useState(false);\n const mouseClickRef = useRef(false);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const wasOpenRef = useRef(false);\n\n useEffect(() => {\n if (wasOpenRef.current && !open) {\n buttonRef.current?.focus();\n }\n wasOpenRef.current = open;\n }, [open]);\n const handleClearIcon = (e: React.MouseEvent) => {\n e.stopPropagation();\n onChange?.('');\n };\n\n return (\n <Popover\n arrow={false}\n placement={dropdownPosition}\n trigger='click'\n getPopupContainer={(triggerNode) => triggerNode?.parentElement || document.body}\n open={open}\n onOpenChange={(newOpen) => {\n if (newOpen) {\n if (mouseClickRef.current) {\n setOpen(true);\n }\n mouseClickRef.current = false;\n } else {\n setOpen(false);\n }\n }}\n content={<IconPickerContent onChange={onChange} selectedIcon={selectedIcon} setOpen={setOpen} />}\n >\n <div className='flex flex-col gap-1'>\n {label ? (\n <InputLabel label={label || \"\"} required={required || false} />\n ) : null}\n <button\n ref={buttonRef}\n type='button'\n id={`btn-icon-picker-icon-${selectedIcon ? 'selected' : 'unselected'}`}\n className={`lax-form-trigger min-w-[83px] h-8 py-1.5 px-3 rounded-md border ${\n disabled ? 'cursor-not-allowed opacity-60 bg-neutral-50 dark:bg-black-800' : 'bg-white dark:bg-black-800'\n } ${errorMessage ? 'border-red-500' : 'focus:border-primary-600 dark:focus:border-primary-400'} flex items-center justify-between gap-2 ${className}`}\n disabled={disabled}\n onClick={(e) => {\n if (disabled) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n if (e.detail > 0) {\n mouseClickRef.current = true;\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n if (!open) {\n const form = (e.currentTarget as HTMLElement).closest('form');\n const submitBtn = form?.querySelector('button[type=\"submit\"]') as HTMLButtonElement | null;\n submitBtn?.click();\n }\n }\n }}\n >\n {selectedIcon ? (\n <IconRenderer iconName={selectedIcon} className='!w-5 !h-5 text-neutral-900 dark:text-white' />\n ) : (\n <Typography\n size='small'\n variant='regular'\n appearance='subtitle'\n >\n Select Icon\n </Typography>\n )}\n {selectedIcon && allowClear && !disabled ? (\n <AllIcons.CloseRounded\n className='!w-5 !h-5 hover:bg-neutral-100 dark:hover:bg-black-800 rounded-full transition-colors cursor-pointer text-neutral-400 dark:text-neutral-500'\n onClick={handleClearIcon}\n />\n ) : (\n null\n )}\n </button>\n {errorMessage && (\n <Typography size='extra-small' className='text-red-500 font-medium'>\n {errorMessage}\n </Typography>\n )}\n </div>\n </Popover>\n );\n};\n\nexport const IconPicker = React.lazy(() =>\n Promise.resolve({\n default: (props: IconPickerContentProps) => (\n <Suspense fallback={<div className='min-w-20 h-8 animate-pulse bg-neutral-100 dark:bg-black-800 rounded-md' />}>\n <IconPickerBase {...props} />\n </Suspense>\n ),\n }),\n);\n\n"],"names":["roundedIconNames","AllIcons","name","mergedIconNames","COUNTRY_CODES","code","formatIconName","iconName","countryNameFromCode","IconPickerContent","onChange","selectedIcon","setOpen","searchTerm","setSearchTerm","useState","filteredIcons","handleClick","icon","event","jsxs","e","jsx","InputField","value","FixedSizeGrid","columnIndex","rowIndex","style","itemIndex","Tooltip","IconButton","classNames","IconRenderer","sx","className","isHovering","getFlagComponent","Icon","IconPickerBase","label","required","allowClear","disabled","errorMessage","dropdownPosition","open","mouseClickRef","useRef","buttonRef","wasOpenRef","useEffect","handleClearIcon","Popover","triggerNode","newOpen","InputLabel","Typography","IconPicker","React","props","Suspense"],"mappings":"yyBAYMA,EAAmB,OAAO,KAAKC,CAAQ,EAAE,OAAQC,GACrDA,GAAM,SAAS,SAAS,CAC1B,EAGMC,EAAkB,CACtB,GAAIH,GAAoB,CAAA,EACxB,IAAII,EAAAA,eAAiB,CAAA,GAAI,IAAKC,GAAS,QAAQA,CAAI,EAAE,CACvD,EAGMC,EAAkBC,GAA6B,CAEnD,GAAIA,GAAU,WAAW,OAAO,EAAG,CACjC,MAAMF,EAAOE,GAAU,QAAQ,QAAS,EAAE,EAC1C,OAAOC,sBAAoBH,GAAQ,EAAE,GAAKA,CAC5C,CAIA,OAAOE,EAAS,WAAW,WAAY,KAAK,EAAE,KAAA,CAChD,EAwBME,EAAoB,CAAC,CACzB,SAAAC,EACA,aAAAC,EACA,QAAAC,CACF,IAAsC,CACpC,KAAM,CAACC,EAAYC,CAAa,EAAIC,EAAAA,SAAiB,EAAE,EAGjDC,GAAiBb,GAAmB,CAAA,GAAI,OAAQD,GAAS,CA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gB+B,GAAc,CAACC,EAC9BrB,EAAAA,IAACrB,EAAS,aAAT,CACC,UAAU,8IACV,QAASmD,CAAA,CAAA,EAGZ,IAAA,CAAA,CAAA,EAGFR,GACCtB,EAAAA,IAACmC,EAAAA,WAAA,CAAW,KAAK,cAAc,UAAU,2BACtC,SAAAb,CAAA,CACH,CAAA,CAAA,CAEJ,CAAA,CAAA,CAGN,EAEac,EAAaC,EAAM,KAAK,IACnC,QAAQ,QAAQ,CACd,QAAUC,GACRtC,EAAAA,IAACuC,EAAAA,UAAS,SAAUvC,EAAAA,IAAC,MAAA,CAAI,UAAU,yEAAyE,EAC1G,SAAAA,EAAAA,IAACiB,EAAA,CAAgB,GAAGqB,EAAO,CAAA,CAC7B,CAAA,CAEH,CACH"}
|
|
1
|
+
{"version":3,"file":"IconPicker.cjs.js","sources":["../../../../src/components/forms/icon-picker/IconPicker.tsx"],"sourcesContent":["import classNames from 'classnames';\nimport React, { Suspense, useEffect, useRef, useState } from 'react';\nimport { FixedSizeGrid, type GridChildComponentProps } from 'react-window';\nimport * as AllIcons from '@mui/icons-material';\nimport { IconButton, type SvgIconOwnProps } from '@mui/material';\nimport { Popover, Tooltip } from \"antd\";\nimport { Typography } from \"../../data-display/typography/Typography\";\nimport { InputField } from \"../input-field/InputField\";\nimport { COUNTRY_CODES, countryNameFromCode } from \"../../../types/icon-picker\";\nimport { getFlagComponent } from \"../../../utils/countryFlags\";\nimport { KeyboardArrowDownIcon } from \"../../icon\";\nimport { InputLabel } from '../shared/InputLabel';\n\nconst roundedIconNames = Object.keys(AllIcons).filter((name) =>\n name?.endsWith(\"Rounded\")\n);\n\n// Merge icon names and country codes for the picker\nconst mergedIconNames = [\n ...(roundedIconNames || []),\n ...(COUNTRY_CODES || []).map((code) => `flag-${code}`),\n];\n\n// Utility function to convert camelCase to human-readable format\nconst formatIconName = (iconName: string): string => {\n // Handle flag icons\n if (iconName?.startsWith(\"flag-\")) {\n const code = iconName?.replace(\"flag-\", \"\");\n return countryNameFromCode(code || \"\") || code;\n }\n\n // Convert camelCase to space-separated words\n // e.g., \"PersonRounded\" -> \"Person Rounded\"\n return iconName.replaceAll(/([A-Z])/g, \" $1\").trim();\n};\n\n/** Ant Design `Popover` placement for the icon panel (bottom edge of the trigger). */\nexport type IconPickerDropdownPosition = 'bottom' | 'bottomLeft' | 'bottomRight';\n\nexport interface IconPickerContentProps {\n selectedIcon: string | null;\n onChange: (iconName: string | null) => void;\n label?: string;\n required?: boolean;\n allowClear?: boolean;\n disabled?: boolean;\n errorMessage?: string;\n /** Popover placement: `bottom` | `bottomLeft` | `bottomRight`. Default: `bottom`. */\n dropdownPosition?: IconPickerDropdownPosition;\n className?: string\n}\n\ninterface IconPickerContentInternalProps {\n onChange: (iconName: string | null) => void;\n selectedIcon: string | null;\n setOpen?: React.Dispatch<React.SetStateAction<boolean>>;\n}\n\nconst IconPickerContent = ({\n onChange,\n selectedIcon,\n setOpen,\n}: IconPickerContentInternalProps) => {\n const [searchTerm, setSearchTerm] = useState<string>(\"\");\n\n // Filter both icons and flags\n const filteredIcons = (mergedIconNames || []).filter((name) => {\n if (name?.startsWith(\"flag-\")) {\n // For flags, allow search by country code or country name\n const code = name?.replace(\"flag-\", \"\");\n return (\n code\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\") ||\n countryNameFromCode(code || \"\")\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\")\n );\n }\n return name\n ?.trim()\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\");\n });\n\n const handleClick = (icon: string, event: React.MouseEvent) => {\n event.stopPropagation();\n if (selectedIcon === icon) {\n onChange?.(null);\n return;\n }\n onChange?.(icon);\n setOpen?.(false);\n };\n\n return (\n <div \n className=\"flex flex-col gap-3\"\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n }}\n >\n <InputField\n id={`input-field-icon-picker`}\n placeholder=\"Search icons...\"\n onChange={(value) => setSearchTerm(value || \"\")}\n fieldSuffix={\n <AllIcons.Search className=\"!w-4 !h-4 text-neutral-400\" />\n }\n />\n <FixedSizeGrid\n columnCount={5}\n rowCount={Math.ceil((filteredIcons?.length || 0) / 5)}\n columnWidth={40}\n rowHeight={40}\n width={220}\n height={240}\n >\n {({ columnIndex, rowIndex, style }: GridChildComponentProps) => {\n const itemIndex = rowIndex * 5 + columnIndex;\n const iconName = filteredIcons?.[itemIndex];\n return iconName ? (\n <div style={style} className=\"p-1\">\n <Tooltip title={formatIconName(iconName)} placement='bottom'>\n <IconButton\n type='button'\n className={classNames(\n \"flex items-center justify-center !rounded-md hover:bg-neutral-200 dark:hover:bg-black-700\",\n {\n \"!bg-primary-50 dark:!bg-black-800\":\n selectedIcon === iconName,\n }\n )}\n onClick={(event) => handleClick(iconName, event)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n }}\n >\n <IconRenderer\n iconName={iconName}\n className=\"!w-5 !h-5 text-neutral-900 dark:text-white\"\n />\n </IconButton>\n </Tooltip>\n </div>\n ) : null;\n }}\n </FixedSizeGrid>\n </div>\n );\n};\n\ninterface IconRendererProps {\n iconName: string;\n sx?: SvgIconOwnProps['sx'];\n className?: string;\n isHovering?: boolean;\n}\n\nexport const IconRenderer = ({ iconName, sx, className, isHovering }: IconRendererProps) => {\n // Render flag if iconName starts with 'flag-'\n if (iconName?.startsWith?.('flag-')) {\n const code = iconName?.replace('flag-', '');\n return getFlagComponent?.(code || '', isHovering || false) || <div>-</div>;\n }\n const Icon = AllIcons?.[iconName as keyof typeof AllIcons] as React.ComponentType<{\n sx?: SvgIconOwnProps['sx'];\n className?: string;\n isHovering?: boolean;\n }>;\n\n if (!Icon) {\n return <div>-</div>;\n }\n\n return <Icon sx={sx} className={className} isHovering={isHovering} />;\n};\n\nconst IconPickerBase = ({\n selectedIcon,\n onChange,\n label,\n required = false,\n allowClear = true,\n disabled = false,\n errorMessage,\n dropdownPosition = 'bottom',\n className\n}: IconPickerContentProps) => {\n const [open, setOpen] = useState(false);\n const mouseClickRef = useRef(false);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const wasOpenRef = useRef(false);\n\n useEffect(() => {\n if (wasOpenRef.current && !open) {\n buttonRef.current?.focus();\n }\n wasOpenRef.current = open;\n }, [open]);\n const handleClearIcon = (e: React.MouseEvent) => {\n e.stopPropagation();\n onChange?.('');\n };\n\n return (\n <Popover\n arrow={false}\n placement={dropdownPosition}\n trigger='click'\n getPopupContainer={(triggerNode) => triggerNode?.parentElement || document.body}\n open={open}\n onOpenChange={(newOpen) => {\n if (newOpen) {\n if (mouseClickRef.current) {\n setOpen(true);\n }\n mouseClickRef.current = false;\n } else {\n setOpen(false);\n }\n }}\n content={<IconPickerContent onChange={onChange} selectedIcon={selectedIcon} setOpen={setOpen} />}\n >\n <div className='flex flex-col gap-1'>\n {label ? (\n <InputLabel label={label || \"\"} required={required || false} />\n ) : null}\n <button\n ref={buttonRef}\n type='button'\n id={`btn-icon-picker-icon-${selectedIcon ? 'selected' : 'unselected'}`}\n className={`lax-form-trigger min-w-[83px] h-8 py-1.5 px-3 rounded-md border ${\n disabled ? 'cursor-not-allowed opacity-60 bg-neutral-50 dark:bg-black-800' : 'bg-white dark:bg-black-800'\n } ${errorMessage ? 'border-red-500' : 'focus:border-primary-600 dark:focus:border-primary-400'} flex items-center justify-between gap-2 ${className}`}\n disabled={disabled}\n aria-haspopup='dialog'\n aria-expanded={open}\n onClick={(e) => {\n if (disabled) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n if (e.detail > 0) {\n mouseClickRef.current = true;\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n if (!open) {\n const form = (e.currentTarget as HTMLElement).closest('form');\n const submitBtn = form?.querySelector('button[type=\"submit\"]') as HTMLButtonElement | null;\n submitBtn?.click();\n }\n }\n }}\n >\n {selectedIcon ? (\n <IconRenderer iconName={selectedIcon} className='!w-5 !h-5 text-neutral-900 dark:text-white' />\n ) : (\n <Typography\n size='small'\n variant='regular'\n appearance='subtitle'\n >\n Select Icon\n </Typography>\n )}\n <span className='flex shrink-0 items-center gap-1'>\n {selectedIcon && allowClear && !disabled ? (\n <AllIcons.CloseRounded\n className='!w-5 !h-5 hover:bg-neutral-100 dark:hover:bg-black-800 rounded-full transition-colors cursor-pointer text-neutral-400 dark:text-neutral-500'\n onClick={handleClearIcon}\n />\n ) : (\n null\n )}\n <KeyboardArrowDownIcon\n size={16}\n className={classNames(\n 'shrink-0 text-neutral-400 dark:text-neutral-500 transition-transform duration-200',\n { 'rotate-180': open }\n )}\n />\n </span>\n </button>\n {errorMessage && (\n <Typography size='extra-small' className='text-red-500 font-medium'>\n {errorMessage}\n </Typography>\n )}\n </div>\n </Popover>\n );\n};\n\nexport const IconPicker = React.lazy(() =>\n Promise.resolve({\n default: (props: IconPickerContentProps) => (\n <Suspense fallback={<div className='min-w-20 h-8 animate-pulse bg-neutral-100 dark:bg-black-800 rounded-md' />}>\n <IconPickerBase {...props} />\n </Suspense>\n ),\n }),\n);\n\n"],"names":["roundedIconNames","AllIcons","name","mergedIconNames","COUNTRY_CODES","code","formatIconName","iconName","countryNameFromCode","IconPickerContent","onChange","selectedIcon","setOpen","searchTerm","setSearchTerm","useState","filteredIcons","handleClick","icon","event","jsxs","e","jsx","InputField","value","FixedSizeGrid","columnIndex","rowIndex","style","itemIndex","Tooltip","IconButton","classNames","IconRenderer","sx","className","isHovering","getFlagComponent","Icon","IconPickerBase","label","required","allowClear","disabled","errorMessage","dropdownPosition","open","mouseClickRef","useRef","buttonRef","wasOpenRef","useEffect","handleClearIcon","Popover","triggerNode","newOpen","InputLabel","Typography","KeyboardArrowDownIcon","IconPicker","React","props","Suspense"],"mappings":"w1BAaMA,EAAmB,OAAO,KAAKC,CAAQ,EAAE,OAAQC,GACrDA,GAAM,SAAS,SAAS,CAC1B,EAGMC,EAAkB,CACtB,GAAIH,GAAoB,CAA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, { Suspense as P, useState as
|
|
4
|
-
import { FixedSizeGrid as
|
|
5
|
-
import * as
|
|
6
|
-
import { IconButton as
|
|
1
|
+
import { jsx as t, jsxs as h } from "react/jsx-runtime";
|
|
2
|
+
import w from "../../../_virtual/index.es.js";
|
|
3
|
+
import I, { Suspense as P, useState as y, useRef as b, useEffect as S } from "react";
|
|
4
|
+
import { FixedSizeGrid as D } from "react-window";
|
|
5
|
+
import * as g from "@mui/icons-material";
|
|
6
|
+
import { IconButton as R } from "@mui/material";
|
|
7
7
|
import { Popover as L, Tooltip as E } from "antd";
|
|
8
|
-
import { Typography as
|
|
8
|
+
import { Typography as x } from "../../data-display/typography/Typography.es.js";
|
|
9
9
|
import { InputField as O } from "../input-field/InputField.es.js";
|
|
10
|
-
import { COUNTRY_CODES as T, countryNameFromCode as
|
|
10
|
+
import { COUNTRY_CODES as T, countryNameFromCode as C } from "../../../types/icon-picker.es.js";
|
|
11
11
|
import { getFlagComponent as $ } from "../../../utils/countryFlags.es.js";
|
|
12
12
|
import { InputLabel as j } from "../shared/InputLabel.es.js";
|
|
13
|
-
|
|
13
|
+
import { KeyboardArrowDownIcon as z } from "../../icon/icons.generated.es.js";
|
|
14
|
+
const W = Object.keys(g).filter(
|
|
14
15
|
(e) => e?.endsWith("Rounded")
|
|
15
|
-
),
|
|
16
|
+
), A = [
|
|
16
17
|
...W || [],
|
|
17
18
|
...(T || []).map((e) => `flag-${e}`)
|
|
18
19
|
], B = (e) => {
|
|
19
20
|
if (e?.startsWith("flag-")) {
|
|
20
21
|
const n = e?.replace("flag-", "");
|
|
21
|
-
return
|
|
22
|
+
return C(n || "") || n;
|
|
22
23
|
}
|
|
23
24
|
return e.replaceAll(/([A-Z])/g, " $1").trim();
|
|
24
25
|
}, F = ({
|
|
25
26
|
onChange: e,
|
|
26
27
|
selectedIcon: n,
|
|
27
|
-
setOpen:
|
|
28
|
+
setOpen: m
|
|
28
29
|
}) => {
|
|
29
|
-
const [c,
|
|
30
|
+
const [c, f] = y(""), a = (A || []).filter((r) => {
|
|
30
31
|
if (r?.startsWith("flag-")) {
|
|
31
|
-
const
|
|
32
|
-
return
|
|
32
|
+
const s = r?.replace("flag-", "");
|
|
33
|
+
return s?.toLowerCase()?.includes(c?.trim()?.toLowerCase() || "") || C(s || "")?.toLowerCase()?.includes(c?.trim()?.toLowerCase() || "");
|
|
33
34
|
}
|
|
34
35
|
return r?.trim()?.toLowerCase()?.includes(c?.trim()?.toLowerCase() || "");
|
|
35
|
-
}), d = (r,
|
|
36
|
-
if (
|
|
36
|
+
}), d = (r, s) => {
|
|
37
|
+
if (s.stopPropagation(), n === r) {
|
|
37
38
|
e?.(null);
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
|
-
e?.(r),
|
|
41
|
+
e?.(r), m?.(!1);
|
|
41
42
|
};
|
|
42
|
-
return /* @__PURE__ */
|
|
43
|
+
return /* @__PURE__ */ h(
|
|
43
44
|
"div",
|
|
44
45
|
{
|
|
45
46
|
className: "flex flex-col gap-3",
|
|
@@ -52,12 +53,12 @@ const W = Object.keys(h).filter(
|
|
|
52
53
|
{
|
|
53
54
|
id: "input-field-icon-picker",
|
|
54
55
|
placeholder: "Search icons...",
|
|
55
|
-
onChange: (r) =>
|
|
56
|
-
fieldSuffix: /* @__PURE__ */ t(
|
|
56
|
+
onChange: (r) => f(r || ""),
|
|
57
|
+
fieldSuffix: /* @__PURE__ */ t(g.Search, { className: "!w-4 !h-4 text-neutral-400" })
|
|
57
58
|
}
|
|
58
59
|
),
|
|
59
60
|
/* @__PURE__ */ t(
|
|
60
|
-
|
|
61
|
+
D,
|
|
61
62
|
{
|
|
62
63
|
columnCount: 5,
|
|
63
64
|
rowCount: Math.ceil((a?.length || 0) / 5),
|
|
@@ -65,26 +66,26 @@ const W = Object.keys(h).filter(
|
|
|
65
66
|
rowHeight: 40,
|
|
66
67
|
width: 220,
|
|
67
68
|
height: 240,
|
|
68
|
-
children: ({ columnIndex: r, rowIndex:
|
|
69
|
-
const p =
|
|
70
|
-
return
|
|
71
|
-
|
|
69
|
+
children: ({ columnIndex: r, rowIndex: s, style: l }) => {
|
|
70
|
+
const p = s * 5 + r, i = a?.[p];
|
|
71
|
+
return i ? /* @__PURE__ */ t("div", { style: l, className: "p-1", children: /* @__PURE__ */ t(E, { title: B(i), placement: "bottom", children: /* @__PURE__ */ t(
|
|
72
|
+
R,
|
|
72
73
|
{
|
|
73
74
|
type: "button",
|
|
74
|
-
className:
|
|
75
|
+
className: w(
|
|
75
76
|
"flex items-center justify-center !rounded-md hover:bg-neutral-200 dark:hover:bg-black-700",
|
|
76
77
|
{
|
|
77
|
-
"!bg-primary-50 dark:!bg-black-800": n ===
|
|
78
|
+
"!bg-primary-50 dark:!bg-black-800": n === i
|
|
78
79
|
}
|
|
79
80
|
),
|
|
80
|
-
onClick: (
|
|
81
|
-
onKeyDown: (
|
|
82
|
-
|
|
81
|
+
onClick: (u) => d(i, u),
|
|
82
|
+
onKeyDown: (u) => {
|
|
83
|
+
u.key === "Enter" && (u.preventDefault(), u.stopPropagation());
|
|
83
84
|
},
|
|
84
85
|
children: /* @__PURE__ */ t(
|
|
85
|
-
|
|
86
|
+
v,
|
|
86
87
|
{
|
|
87
|
-
iconName:
|
|
88
|
+
iconName: i,
|
|
88
89
|
className: "!w-5 !h-5 text-neutral-900 dark:text-white"
|
|
89
90
|
}
|
|
90
91
|
)
|
|
@@ -96,29 +97,29 @@ const W = Object.keys(h).filter(
|
|
|
96
97
|
]
|
|
97
98
|
}
|
|
98
99
|
);
|
|
99
|
-
},
|
|
100
|
+
}, v = ({ iconName: e, sx: n, className: m, isHovering: c }) => {
|
|
100
101
|
if (e?.startsWith?.("flag-")) {
|
|
101
102
|
const a = e?.replace("flag-", "");
|
|
102
103
|
return $?.(a || "", c || !1) || /* @__PURE__ */ t("div", { children: "-" });
|
|
103
104
|
}
|
|
104
|
-
const
|
|
105
|
-
return
|
|
106
|
-
},
|
|
105
|
+
const f = g?.[e];
|
|
106
|
+
return f ? /* @__PURE__ */ t(f, { sx: n, className: m, isHovering: c }) : /* @__PURE__ */ t("div", { children: "-" });
|
|
107
|
+
}, K = ({
|
|
107
108
|
selectedIcon: e,
|
|
108
109
|
onChange: n,
|
|
109
|
-
label:
|
|
110
|
+
label: m,
|
|
110
111
|
required: c = !1,
|
|
111
|
-
allowClear:
|
|
112
|
+
allowClear: f = !0,
|
|
112
113
|
disabled: a = !1,
|
|
113
114
|
errorMessage: d,
|
|
114
115
|
dropdownPosition: r = "bottom",
|
|
115
|
-
className:
|
|
116
|
+
className: s
|
|
116
117
|
}) => {
|
|
117
|
-
const [
|
|
118
|
+
const [l, p] = y(!1), i = b(!1), u = b(null), k = b(!1);
|
|
118
119
|
S(() => {
|
|
119
|
-
k.current && !
|
|
120
|
-
}, [
|
|
121
|
-
const
|
|
120
|
+
k.current && !l && u.current?.focus(), k.current = l;
|
|
121
|
+
}, [l]);
|
|
122
|
+
const N = (o) => {
|
|
122
123
|
o.stopPropagation(), n?.("");
|
|
123
124
|
};
|
|
124
125
|
return /* @__PURE__ */ t(
|
|
@@ -128,34 +129,36 @@ const W = Object.keys(h).filter(
|
|
|
128
129
|
placement: r,
|
|
129
130
|
trigger: "click",
|
|
130
131
|
getPopupContainer: (o) => o?.parentElement || document.body,
|
|
131
|
-
open:
|
|
132
|
+
open: l,
|
|
132
133
|
onOpenChange: (o) => {
|
|
133
|
-
o ? (
|
|
134
|
+
o ? (i.current && p(!0), i.current = !1) : p(!1);
|
|
134
135
|
},
|
|
135
136
|
content: /* @__PURE__ */ t(F, { onChange: n, selectedIcon: e, setOpen: p }),
|
|
136
|
-
children: /* @__PURE__ */
|
|
137
|
-
|
|
138
|
-
/* @__PURE__ */
|
|
137
|
+
children: /* @__PURE__ */ h("div", { className: "flex flex-col gap-1", children: [
|
|
138
|
+
m ? /* @__PURE__ */ t(j, { label: m || "", required: c || !1 }) : null,
|
|
139
|
+
/* @__PURE__ */ h(
|
|
139
140
|
"button",
|
|
140
141
|
{
|
|
141
|
-
ref:
|
|
142
|
+
ref: u,
|
|
142
143
|
type: "button",
|
|
143
144
|
id: `btn-icon-picker-icon-${e ? "selected" : "unselected"}`,
|
|
144
|
-
className: `lax-form-trigger min-w-[83px] h-8 py-1.5 px-3 rounded-md border ${a ? "cursor-not-allowed opacity-60 bg-neutral-50 dark:bg-black-800" : "bg-white dark:bg-black-800"} ${d ? "border-red-500" : "focus:border-primary-600 dark:focus:border-primary-400"} flex items-center justify-between gap-2 ${
|
|
145
|
+
className: `lax-form-trigger min-w-[83px] h-8 py-1.5 px-3 rounded-md border ${a ? "cursor-not-allowed opacity-60 bg-neutral-50 dark:bg-black-800" : "bg-white dark:bg-black-800"} ${d ? "border-red-500" : "focus:border-primary-600 dark:focus:border-primary-400"} flex items-center justify-between gap-2 ${s}`,
|
|
145
146
|
disabled: a,
|
|
147
|
+
"aria-haspopup": "dialog",
|
|
148
|
+
"aria-expanded": l,
|
|
146
149
|
onClick: (o) => {
|
|
147
150
|
if (a) {
|
|
148
151
|
o.preventDefault(), o.stopPropagation();
|
|
149
152
|
return;
|
|
150
153
|
}
|
|
151
|
-
o.detail > 0 && (
|
|
154
|
+
o.detail > 0 && (i.current = !0);
|
|
152
155
|
},
|
|
153
156
|
onKeyDown: (o) => {
|
|
154
|
-
o.key === "Enter" && (o.preventDefault(),
|
|
157
|
+
o.key === "Enter" && (o.preventDefault(), l || o.currentTarget.closest("form")?.querySelector('button[type="submit"]')?.click());
|
|
155
158
|
},
|
|
156
159
|
children: [
|
|
157
|
-
e ? /* @__PURE__ */ t(
|
|
158
|
-
|
|
160
|
+
e ? /* @__PURE__ */ t(v, { iconName: e, className: "!w-5 !h-5 text-neutral-900 dark:text-white" }) : /* @__PURE__ */ t(
|
|
161
|
+
x,
|
|
159
162
|
{
|
|
160
163
|
size: "small",
|
|
161
164
|
variant: "regular",
|
|
@@ -163,27 +166,39 @@ const W = Object.keys(h).filter(
|
|
|
163
166
|
children: "Select Icon"
|
|
164
167
|
}
|
|
165
168
|
),
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
/* @__PURE__ */ h("span", { className: "flex shrink-0 items-center gap-1", children: [
|
|
170
|
+
e && f && !a ? /* @__PURE__ */ t(
|
|
171
|
+
g.CloseRounded,
|
|
172
|
+
{
|
|
173
|
+
className: "!w-5 !h-5 hover:bg-neutral-100 dark:hover:bg-black-800 rounded-full transition-colors cursor-pointer text-neutral-400 dark:text-neutral-500",
|
|
174
|
+
onClick: N
|
|
175
|
+
}
|
|
176
|
+
) : null,
|
|
177
|
+
/* @__PURE__ */ t(
|
|
178
|
+
z,
|
|
179
|
+
{
|
|
180
|
+
size: 16,
|
|
181
|
+
className: w(
|
|
182
|
+
"shrink-0 text-neutral-400 dark:text-neutral-500 transition-transform duration-200",
|
|
183
|
+
{ "rotate-180": l }
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
] })
|
|
173
188
|
]
|
|
174
189
|
}
|
|
175
190
|
),
|
|
176
|
-
d && /* @__PURE__ */ t(
|
|
191
|
+
d && /* @__PURE__ */ t(x, { size: "extra-small", className: "text-red-500 font-medium", children: d })
|
|
177
192
|
] })
|
|
178
193
|
}
|
|
179
194
|
);
|
|
180
|
-
},
|
|
195
|
+
}, re = I.lazy(
|
|
181
196
|
() => Promise.resolve({
|
|
182
|
-
default: (e) => /* @__PURE__ */ t(P, { fallback: /* @__PURE__ */ t("div", { className: "min-w-20 h-8 animate-pulse bg-neutral-100 dark:bg-black-800 rounded-md" }), children: /* @__PURE__ */ t(
|
|
197
|
+
default: (e) => /* @__PURE__ */ t(P, { fallback: /* @__PURE__ */ t("div", { className: "min-w-20 h-8 animate-pulse bg-neutral-100 dark:bg-black-800 rounded-md" }), children: /* @__PURE__ */ t(K, { ...e }) })
|
|
183
198
|
})
|
|
184
199
|
);
|
|
185
200
|
export {
|
|
186
|
-
|
|
187
|
-
|
|
201
|
+
re as IconPicker,
|
|
202
|
+
v as IconRenderer
|
|
188
203
|
};
|
|
189
204
|
//# sourceMappingURL=IconPicker.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconPicker.es.js","sources":["../../../../src/components/forms/icon-picker/IconPicker.tsx"],"sourcesContent":["import classNames from 'classnames';\nimport React, { Suspense, useEffect, useRef, useState } from 'react';\nimport { FixedSizeGrid, type GridChildComponentProps } from 'react-window';\nimport * as AllIcons from '@mui/icons-material';\nimport { IconButton, type SvgIconOwnProps } from '@mui/material';\nimport { Popover, Tooltip } from \"antd\";\nimport { Typography } from \"../../data-display/typography/Typography\";\nimport { InputField } from \"../input-field/InputField\";\nimport { COUNTRY_CODES, countryNameFromCode } from \"../../../types/icon-picker\";\nimport { getFlagComponent } from \"../../../utils/countryFlags\";\nimport { InputLabel } from '../shared/InputLabel';\n\nconst roundedIconNames = Object.keys(AllIcons).filter((name) =>\n name?.endsWith(\"Rounded\")\n);\n\n// Merge icon names and country codes for the picker\nconst mergedIconNames = [\n ...(roundedIconNames || []),\n ...(COUNTRY_CODES || []).map((code) => `flag-${code}`),\n];\n\n// Utility function to convert camelCase to human-readable format\nconst formatIconName = (iconName: string): string => {\n // Handle flag icons\n if (iconName?.startsWith(\"flag-\")) {\n const code = iconName?.replace(\"flag-\", \"\");\n return countryNameFromCode(code || \"\") || code;\n }\n\n // Convert camelCase to space-separated words\n // e.g., \"PersonRounded\" -> \"Person Rounded\"\n return iconName.replaceAll(/([A-Z])/g, \" $1\").trim();\n};\n\n/** Ant Design `Popover` placement for the icon panel (bottom edge of the trigger). */\nexport type IconPickerDropdownPosition = 'bottom' | 'bottomLeft' | 'bottomRight';\n\nexport interface IconPickerContentProps {\n selectedIcon: string | null;\n onChange: (iconName: string | null) => void;\n label?: string;\n required?: boolean;\n allowClear?: boolean;\n disabled?: boolean;\n errorMessage?: string;\n /** Popover placement: `bottom` | `bottomLeft` | `bottomRight`. Default: `bottom`. */\n dropdownPosition?: IconPickerDropdownPosition;\n className?: string\n}\n\ninterface IconPickerContentInternalProps {\n onChange: (iconName: string | null) => void;\n selectedIcon: string | null;\n setOpen?: React.Dispatch<React.SetStateAction<boolean>>;\n}\n\nconst IconPickerContent = ({\n onChange,\n selectedIcon,\n setOpen,\n}: IconPickerContentInternalProps) => {\n const [searchTerm, setSearchTerm] = useState<string>(\"\");\n\n // Filter both icons and flags\n const filteredIcons = (mergedIconNames || []).filter((name) => {\n if (name?.startsWith(\"flag-\")) {\n // For flags, allow search by country code or country name\n const code = name?.replace(\"flag-\", \"\");\n return (\n code\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\") ||\n countryNameFromCode(code || \"\")\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\")\n );\n }\n return name\n ?.trim()\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\");\n });\n\n const handleClick = (icon: string, event: React.MouseEvent) => {\n event.stopPropagation();\n if (selectedIcon === icon) {\n onChange?.(null);\n return;\n }\n onChange?.(icon);\n setOpen?.(false);\n };\n\n return (\n <div \n className=\"flex flex-col gap-3\"\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n }}\n >\n <InputField\n id={`input-field-icon-picker`}\n placeholder=\"Search icons...\"\n onChange={(value) => setSearchTerm(value || \"\")}\n fieldSuffix={\n <AllIcons.Search className=\"!w-4 !h-4 text-neutral-400\" />\n }\n />\n <FixedSizeGrid\n columnCount={5}\n rowCount={Math.ceil((filteredIcons?.length || 0) / 5)}\n columnWidth={40}\n rowHeight={40}\n width={220}\n height={240}\n >\n {({ columnIndex, rowIndex, style }: GridChildComponentProps) => {\n const itemIndex = rowIndex * 5 + columnIndex;\n const iconName = filteredIcons?.[itemIndex];\n return iconName ? (\n <div style={style} className=\"p-1\">\n <Tooltip title={formatIconName(iconName)} placement='bottom'>\n <IconButton\n type='button'\n className={classNames(\n \"flex items-center justify-center !rounded-md hover:bg-neutral-200 dark:hover:bg-black-700\",\n {\n \"!bg-primary-50 dark:!bg-black-800\":\n selectedIcon === iconName,\n }\n )}\n onClick={(event) => handleClick(iconName, event)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n }}\n >\n <IconRenderer\n iconName={iconName}\n className=\"!w-5 !h-5 text-neutral-900 dark:text-white\"\n />\n </IconButton>\n </Tooltip>\n </div>\n ) : null;\n }}\n </FixedSizeGrid>\n </div>\n );\n};\n\ninterface IconRendererProps {\n iconName: string;\n sx?: SvgIconOwnProps['sx'];\n className?: string;\n isHovering?: boolean;\n}\n\nexport const IconRenderer = ({ iconName, sx, className, isHovering }: IconRendererProps) => {\n // Render flag if iconName starts with 'flag-'\n if (iconName?.startsWith?.('flag-')) {\n const code = iconName?.replace('flag-', '');\n return getFlagComponent?.(code || '', isHovering || false) || <div>-</div>;\n }\n const Icon = AllIcons?.[iconName as keyof typeof AllIcons] as React.ComponentType<{\n sx?: SvgIconOwnProps['sx'];\n className?: string;\n isHovering?: boolean;\n }>;\n\n if (!Icon) {\n return <div>-</div>;\n }\n\n return <Icon sx={sx} className={className} isHovering={isHovering} />;\n};\n\nconst IconPickerBase = ({\n selectedIcon,\n onChange,\n label,\n required = false,\n allowClear = true,\n disabled = false,\n errorMessage,\n dropdownPosition = 'bottom',\n className\n}: IconPickerContentProps) => {\n const [open, setOpen] = useState(false);\n const mouseClickRef = useRef(false);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const wasOpenRef = useRef(false);\n\n useEffect(() => {\n if (wasOpenRef.current && !open) {\n buttonRef.current?.focus();\n }\n wasOpenRef.current = open;\n }, [open]);\n const handleClearIcon = (e: React.MouseEvent) => {\n e.stopPropagation();\n onChange?.('');\n };\n\n return (\n <Popover\n arrow={false}\n placement={dropdownPosition}\n trigger='click'\n getPopupContainer={(triggerNode) => triggerNode?.parentElement || document.body}\n open={open}\n onOpenChange={(newOpen) => {\n if (newOpen) {\n if (mouseClickRef.current) {\n setOpen(true);\n }\n mouseClickRef.current = false;\n } else {\n setOpen(false);\n }\n }}\n content={<IconPickerContent onChange={onChange} selectedIcon={selectedIcon} setOpen={setOpen} />}\n >\n <div className='flex flex-col gap-1'>\n {label ? (\n <InputLabel label={label || \"\"} required={required || false} />\n ) : null}\n <button\n ref={buttonRef}\n type='button'\n id={`btn-icon-picker-icon-${selectedIcon ? 'selected' : 'unselected'}`}\n className={`lax-form-trigger min-w-[83px] h-8 py-1.5 px-3 rounded-md border ${\n disabled ? 'cursor-not-allowed opacity-60 bg-neutral-50 dark:bg-black-800' : 'bg-white dark:bg-black-800'\n } ${errorMessage ? 'border-red-500' : 'focus:border-primary-600 dark:focus:border-primary-400'} flex items-center justify-between gap-2 ${className}`}\n disabled={disabled}\n onClick={(e) => {\n if (disabled) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n if (e.detail > 0) {\n mouseClickRef.current = true;\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n if (!open) {\n const form = (e.currentTarget as HTMLElement).closest('form');\n const submitBtn = form?.querySelector('button[type=\"submit\"]') as HTMLButtonElement | null;\n submitBtn?.click();\n }\n }\n }}\n >\n {selectedIcon ? (\n <IconRenderer iconName={selectedIcon} className='!w-5 !h-5 text-neutral-900 dark:text-white' />\n ) : (\n <Typography\n size='small'\n variant='regular'\n appearance='subtitle'\n >\n Select Icon\n </Typography>\n )}\n {selectedIcon && allowClear && !disabled ? (\n <AllIcons.CloseRounded\n className='!w-5 !h-5 hover:bg-neutral-100 dark:hover:bg-black-800 rounded-full transition-colors cursor-pointer text-neutral-400 dark:text-neutral-500'\n onClick={handleClearIcon}\n />\n ) : (\n null\n )}\n </button>\n {errorMessage && (\n <Typography size='extra-small' className='text-red-500 font-medium'>\n {errorMessage}\n </Typography>\n )}\n </div>\n </Popover>\n );\n};\n\nexport const IconPicker = React.lazy(() =>\n Promise.resolve({\n default: (props: IconPickerContentProps) => (\n <Suspense fallback={<div className='min-w-20 h-8 animate-pulse bg-neutral-100 dark:bg-black-800 rounded-md' />}>\n <IconPickerBase {...props} />\n </Suspense>\n ),\n }),\n);\n\n"],"names":["roundedIconNames","AllIcons","name","mergedIconNames","COUNTRY_CODES","code","formatIconName","iconName","countryNameFromCode","IconPickerContent","onChange","selectedIcon","setOpen","searchTerm","setSearchTerm","useState","filteredIcons","handleClick","icon","event","jsxs","e","jsx","InputField","value","FixedSizeGrid","columnIndex","rowIndex","style","itemIndex","Tooltip","IconButton","classNames","IconRenderer","sx","className","isHovering","getFlagComponent","Icon","IconPickerBase","label","required","allowClear","disabled","errorMessage","dropdownPosition","open","mouseClickRef","useRef","buttonRef","wasOpenRef","useEffect","handleClearIcon","Popover","triggerNode","newOpen","InputLabel","Typography","IconPicker","React","props","Suspense"],"mappings":";;;;;;;;;;;;AAYA,MAAMA,IAAmB,OAAO,KAAKC,CAAQ,EAAE;AAAA,EAAO,CAACC,MACrDA,GAAM,SAAS,SAAS;AAC1B,GAGMC,IAAkB;AAAA,EACtB,GAAIH,KAAoB,CAAA;AAAA,EACxB,IAAII,KAAiB,CAAA,GAAI,IAAI,CAACC,MAAS,QAAQA,CAAI,EAAE;AACvD,GAGMC,IAAiB,CAACC,MAA6B;AAEnD,MAAIA,GAAU,WAAW,OAAO,GAAG;AACjC,UAAMF,IAAOE,GAAU,QAAQ,SAAS,EAAE;AAC1C,WAAOC,EAAoBH,KAAQ,EAAE,KAAKA;AAAA,EAC5C;AAIA,SAAOE,EAAS,WAAW,YAAY,KAAK,EAAE,KAAA;AAChD,GAwBME,IAAoB,CAAC;AAAA,EACzB,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,SAAAC;AACF,MAAsC;AACpC,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAiB,EAAE,GAGjDC,KAAiBb,KAAmB,CAAA,GAAI,OAAO,CAACD,MAAS;AAC7D,QAAIA,GAAM,WAAW,OAAO,GAAG;AAE7B,YAAMG,IAAOH,GAA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ources":["../../../../src/components/forms/icon-picker/IconPicker.tsx"],"sourcesContent":["import classNames from 'classnames';\nimport React, { Suspense, useEffect, useRef, useState } from 'react';\nimport { FixedSizeGrid, type GridChildComponentProps } from 'react-window';\nimport * as AllIcons from '@mui/icons-material';\nimport { IconButton, type SvgIconOwnProps } from '@mui/material';\nimport { Popover, Tooltip } from \"antd\";\nimport { Typography } from \"../../data-display/typography/Typography\";\nimport { InputField } from \"../input-field/InputField\";\nimport { COUNTRY_CODES, countryNameFromCode } from \"../../../types/icon-picker\";\nimport { getFlagComponent } from \"../../../utils/countryFlags\";\nimport { KeyboardArrowDownIcon } from \"../../icon\";\nimport { InputLabel } from '../shared/InputLabel';\n\nconst roundedIconNames = Object.keys(AllIcons).filter((name) =>\n name?.endsWith(\"Rounded\")\n);\n\n// Merge icon names and country codes for the picker\nconst mergedIconNames = [\n ...(roundedIconNames || []),\n ...(COUNTRY_CODES || []).map((code) => `flag-${code}`),\n];\n\n// Utility function to convert camelCase to human-readable format\nconst formatIconName = (iconName: string): string => {\n // Handle flag icons\n if (iconName?.startsWith(\"flag-\")) {\n const code = iconName?.replace(\"flag-\", \"\");\n return countryNameFromCode(code || \"\") || code;\n }\n\n // Convert camelCase to space-separated words\n // e.g., \"PersonRounded\" -> \"Person Rounded\"\n return iconName.replaceAll(/([A-Z])/g, \" $1\").trim();\n};\n\n/** Ant Design `Popover` placement for the icon panel (bottom edge of the trigger). */\nexport type IconPickerDropdownPosition = 'bottom' | 'bottomLeft' | 'bottomRight';\n\nexport interface IconPickerContentProps {\n selectedIcon: string | null;\n onChange: (iconName: string | null) => void;\n label?: string;\n required?: boolean;\n allowClear?: boolean;\n disabled?: boolean;\n errorMessage?: string;\n /** Popover placement: `bottom` | `bottomLeft` | `bottomRight`. Default: `bottom`. */\n dropdownPosition?: IconPickerDropdownPosition;\n className?: string\n}\n\ninterface IconPickerContentInternalProps {\n onChange: (iconName: string | null) => void;\n selectedIcon: string | null;\n setOpen?: React.Dispatch<React.SetStateAction<boolean>>;\n}\n\nconst IconPickerContent = ({\n onChange,\n selectedIcon,\n setOpen,\n}: IconPickerContentInternalProps) => {\n const [searchTerm, setSearchTerm] = useState<string>(\"\");\n\n // Filter both icons and flags\n const filteredIcons = (mergedIconNames || []).filter((name) => {\n if (name?.startsWith(\"flag-\")) {\n // For flags, allow search by country code or country name\n const code = name?.replace(\"flag-\", \"\");\n return (\n code\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\") ||\n countryNameFromCode(code || \"\")\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\")\n );\n }\n return name\n ?.trim()\n ?.toLowerCase()\n ?.includes(searchTerm?.trim()?.toLowerCase() || \"\");\n });\n\n const handleClick = (icon: string, event: React.MouseEvent) => {\n event.stopPropagation();\n if (selectedIcon === icon) {\n onChange?.(null);\n return;\n }\n onChange?.(icon);\n setOpen?.(false);\n };\n\n return (\n <div \n className=\"flex flex-col gap-3\"\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n }}\n >\n <InputField\n id={`input-field-icon-picker`}\n placeholder=\"Search icons...\"\n onChange={(value) => setSearchTerm(value || \"\")}\n fieldSuffix={\n <AllIcons.Search className=\"!w-4 !h-4 text-neutral-400\" />\n }\n />\n <FixedSizeGrid\n columnCount={5}\n rowCount={Math.ceil((filteredIcons?.length || 0) / 5)}\n columnWidth={40}\n rowHeight={40}\n width={220}\n height={240}\n >\n {({ columnIndex, rowIndex, style }: GridChildComponentProps) => {\n const itemIndex = rowIndex * 5 + columnIndex;\n const iconName = filteredIcons?.[itemIndex];\n return iconName ? (\n <div style={style} className=\"p-1\">\n <Tooltip title={formatIconName(iconName)} placement='bottom'>\n <IconButton\n type='button'\n className={classNames(\n \"flex items-center justify-center !rounded-md hover:bg-neutral-200 dark:hover:bg-black-700\",\n {\n \"!bg-primary-50 dark:!bg-black-800\":\n selectedIcon === iconName,\n }\n )}\n onClick={(event) => handleClick(iconName, event)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n }}\n >\n <IconRenderer\n iconName={iconName}\n className=\"!w-5 !h-5 text-neutral-900 dark:text-white\"\n />\n </IconButton>\n </Tooltip>\n </div>\n ) : null;\n }}\n </FixedSizeGrid>\n </div>\n );\n};\n\ninterface IconRendererProps {\n iconName: string;\n sx?: SvgIconOwnProps['sx'];\n className?: string;\n isHovering?: boolean;\n}\n\nexport const IconRenderer = ({ iconName, sx, className, isHovering }: IconRendererProps) => {\n // Render flag if iconName starts with 'flag-'\n if (iconName?.startsWith?.('flag-')) {\n const code = iconName?.replace('flag-', '');\n return getFlagComponent?.(code || '', isHovering || false) || <div>-</div>;\n }\n const Icon = AllIcons?.[iconName as keyof typeof AllIcons] as React.ComponentType<{\n sx?: SvgIconOwnProps['sx'];\n className?: string;\n isHovering?: boolean;\n }>;\n\n if (!Icon) {\n return <div>-</div>;\n }\n\n return <Icon sx={sx} className={className} isHovering={isHovering} />;\n};\n\nconst IconPickerBase = ({\n selectedIcon,\n onChange,\n label,\n required = false,\n allowClear = true,\n disabled = false,\n errorMessage,\n dropdownPosition = 'bottom',\n className\n}: IconPickerContentProps) => {\n const [open, setOpen] = useState(false);\n const mouseClickRef = useRef(false);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const wasOpenRef = useRef(false);\n\n useEffect(() => {\n if (wasOpenRef.current && !open) {\n buttonRef.current?.focus();\n }\n wasOpenRef.current = open;\n }, [open]);\n const handleClearIcon = (e: React.MouseEvent) => {\n e.stopPropagation();\n onChange?.('');\n };\n\n return (\n <Popover\n arrow={false}\n placement={dropdownPosition}\n trigger='click'\n getPopupContainer={(triggerNode) => triggerNode?.parentElement || document.body}\n open={open}\n onOpenChange={(newOpen) => {\n if (newOpen) {\n if (mouseClickRef.current) {\n setOpen(true);\n }\n mouseClickRef.current = false;\n } else {\n setOpen(false);\n }\n }}\n content={<IconPickerContent onChange={onChange} selectedIcon={selectedIcon} setOpen={setOpen} />}\n >\n <div className='flex flex-col gap-1'>\n {label ? (\n <InputLabel label={label || \"\"} required={required || false} />\n ) : null}\n <button\n ref={buttonRef}\n type='button'\n id={`btn-icon-picker-icon-${selectedIcon ? 'selected' : 'unselected'}`}\n className={`lax-form-trigger min-w-[83px] h-8 py-1.5 px-3 rounded-md border ${\n disabled ? 'cursor-not-allowed opacity-60 bg-neutral-50 dark:bg-black-800' : 'bg-white dark:bg-black-800'\n } ${errorMessage ? 'border-red-500' : 'focus:border-primary-600 dark:focus:border-primary-400'} flex items-center justify-between gap-2 ${className}`}\n disabled={disabled}\n aria-haspopup='dialog'\n aria-expanded={open}\n onClick={(e) => {\n if (disabled) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n if (e.detail > 0) {\n mouseClickRef.current = true;\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n if (!open) {\n const form = (e.currentTarget as HTMLElement).closest('form');\n const submitBtn = form?.querySelector('button[type=\"submit\"]') as HTMLButtonElement | null;\n submitBtn?.click();\n }\n }\n }}\n >\n {selectedIcon ? (\n <IconRenderer iconName={selectedIcon} className='!w-5 !h-5 text-neutral-900 dark:text-white' />\n ) : (\n <Typography\n size='small'\n variant='regular'\n appearance='subtitle'\n >\n Select Icon\n </Typography>\n )}\n <span className='flex shrink-0 items-center gap-1'>\n {selectedIcon && allowClear && !disabled ? (\n <AllIcons.CloseRounded\n className='!w-5 !h-5 hover:bg-neutral-100 dark:hover:bg-black-800 rounded-full transition-colors cursor-pointer text-neutral-400 dark:text-neutral-500'\n onClick={handleClearIcon}\n />\n ) : (\n null\n )}\n <KeyboardArrowDownIcon\n size={16}\n className={classNames(\n 'shrink-0 text-neutral-400 dark:text-neutral-500 transition-transform duration-200',\n { 'rotate-180': open }\n )}\n />\n </span>\n </button>\n {errorMessage && (\n <Typography size='extra-small' className='text-red-500 font-medium'>\n {errorMessage}\n </Typography>\n )}\n </div>\n </Popover>\n );\n};\n\nexport const IconPicker = React.lazy(() =>\n Promise.resolve({\n default: (props: IconPickerContentProps) => (\n <Suspense fallback={<div className='min-w-20 h-8 animate-pulse bg-neutral-100 dark:bg-black-800 rounded-md' />}>\n <IconPickerBase {...props} />\n </Suspense>\n ),\n }),\n);\n\n"],"names":["roundedIconNames","AllIcons","name","mergedIconNames","COUNTRY_CODES","code","formatIconName","iconName","countryNameFromCode","IconPickerContent","onChange","selectedIcon","setOpen","searchTerm","setSearchTerm","useState","filteredIcons","handleClick","icon","event","jsxs","e","jsx","InputField","value","FixedSizeGrid","columnIndex","rowIndex","style","itemIndex","Tooltip","IconButton","classNames","IconRenderer","sx","className","isHovering","getFlagComponent","Icon","IconPickerBase","label","required","allowClear","disabled","errorMessage","dropdownPosition","open","mouseClickRef","useRef","buttonRef","wasOpenRef","useEffect","handleClearIcon","Popover","triggerNode","newOpen","InputLabel","Typography","KeyboardArrowDownIcon","IconPicker","React","props","Suspense"],"mappings":";;;;;;;;;;;;;AAaA,MAAMA,IAAmB,OAAO,KAAKC,CAAQ,EAAE;AAAA,EAAO,CAACC,MACrDA,GAAM,SAAS,SAAS;AAC1B,GAGMC,IAAkB;AAAA,EACtB,GAAIH,KAAoB,CAAA;AAAA,EACxB,IAAII,KAAiB,CAAA,GAAI,IAAI,CAACC,MAAS,QAAQA,CAAI,EAAE;AACvD,GAGMC,IAAiB,CAACC,MAA6B;AAEnD,MAAIA,GAAU,WAAW,OAAO,GAAG;AACjC,UAAMF,IAAOE,GAAU,QAAQ,SAAS,EAAE;AAC1C,WAAOC,EAAoBH,KAAQ,EAAE,KAAKA;AAAA,EAC5C;AAIA,SAAOE,EAAS,WAAW,YAAY,KAAK,EAAE,KAAA;AAChD,GAwBME,IAAoB,CAAC;AAAA,EACzB,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,SAAAC;AACF,MAAsC;AACpC,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAiB,EAAE,GAGjDC,KAAiBb,KAAmB,CAAA,GA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Ac,WAAU,4BACtC,UAAAb,EAAA,CACH;AAAA,MAAA,EAAA,CAEJ;AAAA,IAAA;AAAA,EAAA;AAGN,GAEae,KAAaC,EAAM;AAAA,EAAK,MACnC,QAAQ,QAAQ;AAAA,IACd,SAAS,CAACC,MACR,gBAAAvC,EAACwC,KAAS,UAAU,gBAAAxC,EAAC,OAAA,EAAI,WAAU,0EAAyE,GAC1G,UAAA,gBAAAA,EAACiB,GAAA,EAAgB,GAAGsB,GAAO,EAAA,CAC7B;AAAA,EAAA,CAEH;AACH;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("../../../_virtual/index.cjs.js"),N=require("react"),d=require("@mui/icons-material"),xe=require("../../data-display/modal/Modal.cjs.js"),u=require("../../button/Button.cjs.js"),ue=require("../../navigation/tabs/Tabs.cjs.js"),K=require("./MarkdownPreview.cjs.js"),O=require("./listEditing.cjs.js"),L=require("../../tooltip/Tooltip.cjs.js"),A=require("framer-motion"),H=require("../../data-display/typography/Typography.cjs.js"),me=require("../shared/InputLabel.cjs.js"),fe=["edit","preview"],he=({className:p,size:n=16})=>e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:p,children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),U=N.forwardRef(({id:p,value:n="",defaultValue:V,onChange:m,placeholder:D="Enter markdown content...",minRows:W=4,maxRows:G=20,isDisabled:l=!1,className:J,textareaClassName:Q,previewClassName:E,label:v,labelClassName:X,isRequiredConditional:Y,required:F=!1,showPreviewOnModal:Z=!1,maxLength:a,linkTarget:q="_blank",errorMessage:k,tooltip:R,originalCase:_,suffixIcon:j,isClearable:y,inputref:C,showFormattingHelp:ee=!0,onKeyDown:te,noIndent:T=!1,showMinimalPreview:M=!1,acceptAdvanceContent:g=!0},i)=>{const[c,se]=N.useState("edit"),[ne,I]=N.useState(!1),f=N.useRef(null),r=p||`rich-md-input-${Math.random().toString(36).slice(2,11)}`,ae=n.length,o=(t,s="",x="")=>{const h=i?.current||f.current;if(!h)return;const S=h.selectionStart,P=h.selectionEnd,w=n.substring(S,P),oe=w||x,de=n.substring(0,S)+t+oe+s+n.substring(P);m(de),setTimeout(()=>{const B=S+t.length+(w?w.length:0);h.focus(),h.setSelectionRange(B,B+(w?0:x.length))},0)},z=t=>{const s=i?.current||f.current;if(!s)return;const x=O.toggleList(n,s.selectionStart,s.selectionEnd,t);a&&x.value.length>a||(m(x.value),setTimeout(()=>{s.focus(),s.setSelectionRange(x.caret,x.caret)},0))},re=()=>{const t=i?.current||f.current;if(!t)return!1;const s=O.continueList(n,t.selectionStart,t.selectionEnd);return!s||a&&s.value.length>a?!1:(m(s.value),setTimeout(()=>{t.focus(),t.setSelectionRange(s.caret,s.caret)},0),!0)},le=t=>{if(te?.(t),t.key==="Enter"&&!t.shiftKey&&!t.altKey&&!t.metaKey&&!t.ctrlKey&&!t.defaultPrevented){re()&&t.preventDefault();return}if(t.metaKey||t.ctrlKey)switch(t.key.toLowerCase()){case"b":t.preventDefault(),o("**","**","bold text");break;case"i":t.preventDefault(),o("*","*","italic text");break;case"u":t.preventDefault(),o("<u>","</u>","underlined text");break;case"k":t.preventDefault(),o("[","](url)","link text");break;case"e":t.preventDefault(),o("```","```","code");break}},ie=()=>{m(""),(i?.current||f.current)?.focus()},ce=(()=>{const t=(n.match(/\n/g)||[]).length+1;return Math.min(G,Math.max(W,t))})(),$=e.jsxs("div",{className:b("flex flex-col",J),children:[e.jsxs("div",{className:`flex flex-row items-center ${v?"justify-between":"justify-end"} w-full`,children:[v&&e.jsx("label",{id:r,htmlFor:r,className:`mb-1 text-xs font-medium text-gray-600 inline-flex items-center gap-1 ${_?"":"capitalize"} ${X||"!uppercse"}`,children:e.jsx("div",{className:"flex flex-wrap items-center justify-between w-full",children:e.jsx("div",{className:"inline-flex flex-wrap items-center gap-1",children:e.jsx(me.InputLabel,{label:v||"",required:F||!1,isRequiredConditional:Y||!1})})})}),ee&&e.jsx(L,{placement:"bottom-end",title:e.jsxs("div",{className:"flex flex-col items-start justify-center py-2 px-3 min-w-[220px] gap-2 bg-neutral-900 rounded-lg",children:[e.jsxs("div",{className:"flex flex-col items-start justify-start gap-1 w-full",children:[e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"**bold**"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("strong",{children:"bold"})," text"]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"*italic*"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("em",{children:"italic"})," text"]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"`code`"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("code",{children:"inline code"})]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"<u>text</u>"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("u",{children:"underline"})]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"~~strike~~"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("del",{children:"strike"})]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"- item"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ bullet list"})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"1. item"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ numbered list"})]}),g&&e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"## heading"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ heading 2"})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"[link](url)"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ hyperlink"})]})]}),g&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-start justify-start gap-1 w-full",children:[e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"> quote"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ blockquote"})]}),e.jsxs("div",{className:"flex flex-col items-start justify-start gap-0.5 w-full mt-0.5",children:[e.jsxs("div",{className:"flex flex-row items-center gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"Table:"})]}),e.jsxs("div",{className:"flex flex-col px-1 py-0.5 bg-neutral-700 ml-2 rounded-sm gap-0",children:[e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter whitespace-nowrap",children:"| Header 1 | Header 2 | Header 3 |"}),e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter whitespace-nowrap",children:"| :--- | :---: | ---: |"}),e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter whitespace-nowrap",children:"| Left | Center | Right |"})]})]})]})})]}),children:e.jsx(H.Typography,{className:"mb-2 text-xs font-medium text-primary-700 inline-flex items-center gap-1 cursor-pointer",children:"Formatting help ?"})})]}),e.jsxs("div",{className:b("flex flex-col border shadow-[0px_1px_2px_rgba(0,0,0,0.05)] rounded-lg bg-white dark:bg-black-700 w-full",k?"border-red-300 focus-within:border-red-500 focus-within:shadow-[0_0_0_1.5px_var(--color-red-200)]":"border-[#EAECF0] dark:border-black-600 focus-within:border-primary-600 dark:focus-within:border-primary-400 focus-within:shadow-[0_0_0_1.5px_var(--color-primary-100)] dark:focus-within:shadow-[0_0_0_1.5px_var(--color-primary-950)]"),children:[e.jsxs("div",{className:b("flex flex-row justify-between items-center px-3 py-2 gap-2 h-11 rounded-t-lg bg-[#F9FAFB] dark:bg-black-600 border-b border-[#EAECF0] dark:border-black-600"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{id:`${r}-bold`,type:"button",onClick:()=>o("**","**","bold text"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Bold (Ctrl+B)",children:e.jsx(d.FormatBold,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})}),e.jsx(u,{id:`${r}-italic`,type:"button",onClick:()=>o("*","*","italic text"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Italic (Ctrl+I)",children:e.jsx(d.FormatItalic,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})}),e.jsx(u,{id:`${r}-underline`,type:"button",onClick:()=>o("<u>","</u>","underlined text"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Underline (Ctrl+U)",children:e.jsx(d.FormatUnderlined,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})}),e.jsx("div",{className:"w-px h-5 bg-[#EAECF0] dark:bg-black-500 rounded-full"}),e.jsx(u,{id:`${r}-numbered-list`,type:"button",onClick:()=>z("ordered"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Numbered List",children:e.jsx(d.FormatListNumbered,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})}),e.jsx(u,{id:`${r}-bullet-list`,type:"button",onClick:()=>z("bullet"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Bullet List",children:e.jsx(d.FormatListBulleted,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-sm font-medium text-[#475467] dark:text-neutral-400",children:[ae,"/",a]}),e.jsx("div",{className:"w-px h-6 bg-[#EAECF0] dark:bg-black-500 rounded-full"})]}),Z?e.jsx(u,{id:`${r}-expand`,type:"button",onClick:()=>I(!0),disabled:l,className:"!p-0.5 !min-w-0 !h-auto ml-1 !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Expand Preview",children:e.jsx(d.OpenInFull,{sx:{fontSize:16,color:"#667085"},className:"dark:text-neutral-400"})}):e.jsx(ue.Tabs,{variant:"switch",tabs:fe,activeTab:c,onTabClick:t=>se(t),height:"h-5",iconsOnly:!0,tabIcons:{edit:e.jsx(d.Edit,{sx:{fontSize:16,color:"#667085"},className:"dark:text-neutral-400"}),preview:e.jsx(d.VisibilityOutlined,{sx:{fontSize:16,color:"#667085"},className:"dark:text-neutral-400"})},className:"rounded-lg"})]})]}),e.jsx("div",{className:"px-3 py-2 relative",children:c==="edit"?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{ref:t=>{typeof i=="function"?i(t):i&&(i.current=t),f.current=t,C&&(C.current=t)},id:r,value:n,defaultValue:V,onChange:t=>{const s=t.target.value;(!a||s.length<=a)&&m(s)},onKeyDown:le,placeholder:D,rows:ce,disabled:l,required:F,maxLength:a,className:b("w-full bg-transparent !focus:ring-0 !focus:border-none","font-inter font-medium text-sm leading-5","text-[#101828] dark:text-neutral-100","placeholder:text-neutral-400 dark:placeholder:text-neutral-500","focus:outline-none resize-none","scrollbar-none","[&::-webkit-scrollbar]:hidden","[-ms-overflow-style:none]","[scrollbar-width:none]",{"text-neutral-400 dark:text-neutral-500 cursor-not-allowed":l},{"pr-20":y||j},Q)}),(y||j)&&c==="edit"&&e.jsxs("div",{className:"absolute right-1 top-2 flex items-center gap-1",children:[y&&n&&e.jsx("button",{id:`btn-input-field-clear-${p}`,className:"absolute inset-y-0 flex items-center cursor-pointer top-2 right-1 focus:outline-none",onClick:ie,type:"button",children:e.jsx(he,{className:"text-neutral-300 dark:text-black-500 hover:text-neutral-400 dark:hover:text-black-400 transition-colors",size:16})}),j&&e.jsx("div",{className:"flex items-center",children:j})]})]}):e.jsx("div",{className:"w-full min-h-[92px] max-h-[400px] overflow-y-auto",children:e.jsx(K.MarkdownPreview,{content:n,linkTarget:q,className:E,noIndent:T,showMinimalPreview:M,acceptAdvanceContent:g})})})]}),e.jsx(xe.Modal,{open:ne,onCancel:()=>I(!1),title:"Markdown Preview",width:900,footer:null,children:e.jsx("div",{className:"max-h-[calc(100vh-200px)] overflow-y-auto p-4",children:e.jsx(K.MarkdownPreview,{content:n,linkTarget:q,className:E,noIndent:T,showMinimalPreview:M,acceptAdvanceContent:g})})}),e.jsx(A.AnimatePresence,{children:k&&e.jsx(A.motion.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.2},children:e.jsx(H.Typography,{className:"mt-1 text-error-500",appearance:"custom",size:"extra-small",variant:"medium",children:k})})})]});return R?e.jsx(L,{title:R,children:$}):$});U.displayName="RichMarkdownInput";exports.RichMarkdownInput=U;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("../../../_virtual/index.cjs.js"),N=require("react"),x=require("@mui/icons-material"),ue=require("../../data-display/modal/Modal.cjs.js"),u=require("../../button/Button.cjs.js"),me=require("../../navigation/tabs/Tabs.cjs.js"),K=require("./MarkdownPreview.cjs.js"),L=require("./listEditing.cjs.js"),O=require("../../tooltip/Tooltip.cjs.js"),A=require("framer-motion"),H=require("../../data-display/typography/Typography.cjs.js"),he=require("../shared/InputLabel.cjs.js"),U=require("../../icon/icons.generated.cjs.js"),fe=["edit","preview"],pe=({className:p,size:n=16})=>e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:p,children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),V=N.forwardRef(({id:p,value:n="",defaultValue:D,onChange:m,placeholder:W="Enter markdown content...",minRows:G=4,maxRows:J=20,isDisabled:l=!1,className:Q,textareaClassName:X,previewClassName:E,label:v,labelClassName:Y,isRequiredConditional:Z,required:F=!1,showPreviewOnModal:ee=!1,maxLength:a,linkTarget:S="_blank",errorMessage:k,tooltip:_,originalCase:R,suffixIcon:j,isClearable:y,inputref:C,showFormattingHelp:te=!0,onKeyDown:se,noIndent:I=!1,showMinimalPreview:T=!1,acceptAdvanceContent:g=!0},i)=>{const[c,ne]=N.useState("edit"),[ae,M]=N.useState(!1),h=N.useRef(null),r=p||`rich-md-input-${Math.random().toString(36).slice(2,11)}`,re=n.length,d=(t,s="",o="")=>{const f=i?.current||h.current;if(!f)return;const q=f.selectionStart,z=f.selectionEnd,w=n.substring(q,z),oe=w||o,xe=n.substring(0,q)+t+oe+s+n.substring(z);m(xe),setTimeout(()=>{const B=q+t.length+(w?w.length:0);f.focus(),f.setSelectionRange(B,B+(w?0:o.length))},0)},$=t=>{const s=i?.current||h.current;if(!s)return;const o=L.toggleList(n,s.selectionStart,s.selectionEnd,t);a&&o.value.length>a||(m(o.value),setTimeout(()=>{s.focus(),s.setSelectionRange(o.caret,o.caret)},0))},le=()=>{const t=i?.current||h.current;if(!t)return!1;const s=L.continueList(n,t.selectionStart,t.selectionEnd);return!s||a&&s.value.length>a?!1:(m(s.value),setTimeout(()=>{t.focus(),t.setSelectionRange(s.caret,s.caret)},0),!0)},ie=t=>{if(se?.(t),t.key==="Enter"&&!t.shiftKey&&!t.altKey&&!t.metaKey&&!t.ctrlKey&&!t.defaultPrevented){le()&&t.preventDefault();return}if(t.metaKey||t.ctrlKey)switch(t.key.toLowerCase()){case"b":t.preventDefault(),d("**","**","bold text");break;case"i":t.preventDefault(),d("*","*","italic text");break;case"u":t.preventDefault(),d("<u>","</u>","underlined text");break;case"k":t.preventDefault(),d("[","](url)","link text");break;case"e":t.preventDefault(),d("```","```","code");break}},ce=()=>{m(""),(i?.current||h.current)?.focus()},de=(()=>{const t=(n.match(/\n/g)||[]).length+1;return Math.min(J,Math.max(G,t))})(),P=e.jsxs("div",{className:b("flex flex-col",Q),children:[e.jsxs("div",{className:`flex flex-row items-center ${v?"justify-between":"justify-end"} w-full`,children:[v&&e.jsx("label",{id:r,htmlFor:r,className:`mb-1 text-xs font-medium text-gray-600 inline-flex items-center gap-1 ${R?"":"capitalize"} ${Y||"!uppercse"}`,children:e.jsx("div",{className:"flex flex-wrap items-center justify-between w-full",children:e.jsx("div",{className:"inline-flex flex-wrap items-center gap-1",children:e.jsx(he.InputLabel,{label:v||"",required:F||!1,isRequiredConditional:Z||!1})})})}),te&&e.jsx(O,{placement:"bottom-end",title:e.jsxs("div",{className:"flex flex-col items-start justify-center py-2 px-3 min-w-[220px] gap-2 bg-neutral-900 rounded-lg",children:[e.jsxs("div",{className:"flex flex-col items-start justify-start gap-1 w-full",children:[e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"**bold**"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("strong",{children:"bold"})," text"]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"*italic*"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("em",{children:"italic"})," text"]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"`code`"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("code",{children:"inline code"})]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"<u>text</u>"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("u",{children:"underline"})]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"~~strike~~"})}),e.jsxs("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:["→ ",e.jsx("del",{children:"strike"})]})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"- item"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ bullet list"})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"1. item"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ numbered list"})]}),g&&e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"## heading"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ heading 2"})]}),e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"[link](url)"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ hyperlink"})]})]}),g&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-col items-start justify-start gap-1 w-full",children:[e.jsxs("div",{className:"flex flex-row items-start gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("div",{className:"flex flex-row justify-center items-center px-[3px] bg-neutral-700 rounded-sm",children:e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter",children:"> quote"})}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"→ blockquote"})]}),e.jsxs("div",{className:"flex flex-col items-start justify-start gap-0.5 w-full mt-0.5",children:[e.jsxs("div",{className:"flex flex-row items-center gap-1 ml-1",children:[e.jsx("span",{className:"text-white text-[18px] leading-4",children:"•"}),e.jsx("span",{className:"text-white text-xs font-medium leading-4 font-inter",children:"Table:"})]}),e.jsxs("div",{className:"flex flex-col px-1 py-0.5 bg-neutral-700 ml-2 rounded-sm gap-0",children:[e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter whitespace-nowrap",children:"| Header 1 | Header 2 | Header 3 |"}),e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter whitespace-nowrap",children:"| :--- | :---: | ---: |"}),e.jsx("span",{className:"text-neutral-300 text-xs font-medium leading-4 font-inter whitespace-nowrap",children:"| Left | Center | Right |"})]})]})]})})]}),children:e.jsx(H.Typography,{className:"mb-2 text-xs font-medium text-primary-700 inline-flex items-center gap-1 cursor-pointer",children:"Formatting help ?"})})]}),e.jsxs("div",{className:b("flex flex-col border shadow-[0px_1px_2px_rgba(0,0,0,0.05)] rounded-lg bg-white dark:bg-black-700 w-full",k?"border-red-300 focus-within:border-red-500 focus-within:shadow-[0_0_0_1.5px_var(--color-red-200)]":"border-[#EAECF0] dark:border-black-600 focus-within:border-primary-600 dark:focus-within:border-primary-400 focus-within:shadow-[0_0_0_1.5px_var(--color-primary-100)] dark:focus-within:shadow-[0_0_0_1.5px_var(--color-primary-950)]"),children:[e.jsxs("div",{className:b("flex flex-row justify-between items-center px-3 py-2 gap-2 h-11 rounded-t-lg bg-[#F9FAFB] dark:bg-black-600 border-b border-[#EAECF0] dark:border-black-600"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{id:`${r}-bold`,type:"button",onClick:()=>d("**","**","bold text"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Bold (Ctrl+B)",children:e.jsx(x.FormatBold,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})}),e.jsx(u,{id:`${r}-italic`,type:"button",onClick:()=>d("*","*","italic text"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Italic (Ctrl+I)",children:e.jsx(x.FormatItalic,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})}),e.jsx(u,{id:`${r}-underline`,type:"button",onClick:()=>d("<u>","</u>","underlined text"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Underline (Ctrl+U)",children:e.jsx(x.FormatUnderlined,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})}),e.jsx("div",{className:"w-px h-5 bg-[#EAECF0] dark:bg-black-500 rounded-full"}),e.jsx(u,{id:`${r}-numbered-list`,type:"button",onClick:()=>$("ordered"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Numbered List",children:e.jsx(x.FormatListNumbered,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})}),e.jsx(u,{id:`${r}-bullet-list`,type:"button",onClick:()=>$("bullet"),disabled:l||c==="preview",className:"!p-0.5 !min-w-0 !h-auto !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Bullet List",children:e.jsx(x.FormatListBulleted,{sx:{fontSize:20,color:"#667085"},className:"dark:text-neutral-400"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-sm font-medium text-[#475467] dark:text-neutral-400",children:[re,"/",a]}),e.jsx("div",{className:"w-px h-6 bg-[#EAECF0] dark:bg-black-500 rounded-full"})]}),ee?e.jsx(u,{id:`${r}-expand`,type:"button",onClick:()=>M(!0),disabled:l,className:"!p-0.5 !min-w-0 !h-auto ml-1 !rounded-md hover:!bg-neutral-200 dark:hover:!bg-black-500 hover:!scale-110 !transition-all !duration-200",appearance:"ghost",status:"no-background",title:"Expand Preview",children:e.jsx(x.OpenInFull,{sx:{fontSize:16,color:"#667085"},className:"dark:text-neutral-400"})}):e.jsx(me.Tabs,{variant:"switch",tabs:fe,activeTab:c,onTabClick:t=>ne(t),height:"h-5",iconsOnly:!0,tabIcons:{edit:e.jsx(U.EditIcon,{className:"h-md w-md dark:text-neutral-400"}),preview:e.jsx(U.VisibilityIcon,{className:"h-md w-md dark:text-neutral-400"})},className:"rounded-lg"})]})]}),e.jsx("div",{className:"px-3 py-2 relative",children:c==="edit"?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{ref:t=>{typeof i=="function"?i(t):i&&(i.current=t),h.current=t,C&&(C.current=t)},id:r,value:n,defaultValue:D,onChange:t=>{const s=t.target.value;(!a||s.length<=a)&&m(s)},onKeyDown:ie,placeholder:W,rows:de,disabled:l,required:F,maxLength:a,className:b("w-full bg-transparent !focus:ring-0 !focus:border-none","font-inter font-medium text-sm leading-5","text-[#101828] dark:text-neutral-100","placeholder:text-neutral-400 dark:placeholder:text-neutral-500","focus:outline-none resize-none","scrollbar-none","[&::-webkit-scrollbar]:hidden","[-ms-overflow-style:none]","[scrollbar-width:none]",{"text-neutral-400 dark:text-neutral-500 cursor-not-allowed":l},{"pr-20":y||j},X)}),(y||j)&&c==="edit"&&e.jsxs("div",{className:"absolute right-1 top-2 flex items-center gap-1",children:[y&&n&&e.jsx("button",{id:`btn-input-field-clear-${p}`,className:"absolute inset-y-0 flex items-center cursor-pointer top-2 right-1 focus:outline-none",onClick:ce,type:"button",children:e.jsx(pe,{className:"text-neutral-300 dark:text-black-500 hover:text-neutral-400 dark:hover:text-black-400 transition-colors",size:16})}),j&&e.jsx("div",{className:"flex items-center",children:j})]})]}):e.jsx("div",{className:"w-full min-h-[92px] max-h-[400px] overflow-y-auto",children:e.jsx(K.MarkdownPreview,{content:n,linkTarget:S,className:E,noIndent:I,showMinimalPreview:T,acceptAdvanceContent:g})})})]}),e.jsx(ue.Modal,{open:ae,onCancel:()=>M(!1),title:"Markdown Preview",width:900,footer:null,children:e.jsx("div",{className:"max-h-[calc(100vh-200px)] overflow-y-auto p-4",children:e.jsx(K.MarkdownPreview,{content:n,linkTarget:S,className:E,noIndent:I,showMinimalPreview:T,acceptAdvanceContent:g})})}),e.jsx(A.AnimatePresence,{children:k&&e.jsx(A.motion.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.2},children:e.jsx(H.Typography,{className:"mt-1 text-error-500",appearance:"custom",size:"extra-small",variant:"medium",children:k})})})]});return _?e.jsx(O,{title:_,children:P}):P});V.displayName="RichMarkdownInput";exports.RichMarkdownInput=V;
|
|
2
2
|
//# sourceMappingURL=RichMarkdownInput.cjs.js.map
|