@innoviatech/lexical-text-editor 0.0.4 → 0.0.6

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/index.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("@lexical/react/LexicalComposer"),n=require("react"),r=require("@lexical/rich-text"),i=require("@lexical/code"),o=require("@lexical/react/LexicalRichTextPlugin"),a=require("@lexical/react/LexicalContentEditable"),s=require("@lexical/react/LexicalErrorBoundary"),l=require("@lexical/react/LexicalHistoryPlugin"),c=require("@lexical/react/LexicalListPlugin"),d=require("@lexical/list"),u=require("react-icons/rx"),f=require("react-icons/tb"),h=require("react-icons/bs"),p=require("react-icons/ai"),g=require("react-icons/io5"),m=require("react-icons/pi"),x=require("@lexical/react/LexicalComposerContext"),v=require("lexical"),b=require("@lexical/link"),y=require("class-variance-authority"),N=require("clsx"),j=require("tailwind-merge"),w=require("@radix-ui/react-tooltip"),C=require("@radix-ui/react-popover"),_=require("react-icons/hi2"),k=require("react-icons/io"),O=require("react-icons/ti"),A=require("react-color"),S=require("react-dom"),T=require("@radix-ui/react-dialog"),E=require("react-icons/fa"),M=require("react-icons/vsc"),L=require("@lexical/react/LexicalLinkPlugin"),R=require("@lexical/react/LexicalOnChangePlugin");function D(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var $=D(n),z=D(w),P=D(C),B=D(T),F=function(e,t){return F=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},F(e,t)};function I(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}F(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var H,U,q=function(){return q=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},q.apply(this,arguments)};function K(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}"function"==typeof SuppressedError&&SuppressedError,function(e){e.Bold="bold",e.Italics="italics",e.Underline="underline",e.Quote="quote",e.Lowercase="lowercase",e.Uppercase="uppercase",e.Capitalize="capitalize",e.Strikethrough="strikethrough",e.Superscript="superscript",e.Subscript="subscript",e.Highlight="highlight",e.Code="code",e.Link="link",e.LeftAlign="leftAlign",e.CenterAlign="centerAlign",e.RightAlign="rightAlign",e.JustifyAlign="justifyAlign",e.Divider="divider",e.Undo="undo",e.Redo="redo"}(H||(H={})),function(e){e.Normal="normal",e.H1="h1",e.H2="h2",e.H3="h3",e.H4="h4",e.H5="h5",e.H6="h6"}(U||(U={}));var W=[{id:H.Lowercase,icon:e.jsx(u.RxLetterCaseLowercase,{}),label:"Lowercase"},{id:H.Uppercase,icon:e.jsx(u.RxLetterCaseUppercase,{}),label:"Uppercase"},{id:H.Capitalize,icon:e.jsx(u.RxLetterCaseCapitalize,{}),label:"Capitalize"},{id:H.Strikethrough,icon:e.jsx(p.AiOutlineStrikethrough,{}),label:"Strikethrough"},{id:H.Highlight,icon:e.jsx(m.PiHighlighterLight,{}),label:"Highlight",fontSize:10},{id:H.Superscript,icon:e.jsx(h.BsSuperscript,{}),label:"Superscript"},{id:H.Subscript,icon:e.jsx(h.BsSubscript,{}),label:"Subscript"}],J=[{id:H.Bold,icon:e.jsx(f.TbBold,{}),label:"Bold"},{id:H.Italics,icon:e.jsx(f.TbItalic,{}),label:"Italics"},{id:H.Underline,icon:e.jsx(f.TbUnderline,{}),label:"Underline"},{id:H.Divider},{id:H.Quote,icon:e.jsx(h.BsChatSquareQuote,{}),label:"Quote"},{id:H.Code,icon:e.jsx(g.IoCodeSlashOutline,{}),label:"Code"}],X=[{id:H.Undo,icon:e.jsx(h.BsArrowCounterclockwise,{}),label:"Undo"},{id:H.Redo,icon:e.jsx(h.BsArrowClockwise,{}),label:"Redo"},{id:H.Divider}],G=[{id:H.LeftAlign,icon:e.jsx(h.BsJustifyLeft,{}),label:"Left Align"},{id:H.CenterAlign,icon:e.jsx(h.BsTextCenter,{}),label:"Center Align"},{id:H.RightAlign,icon:e.jsx(h.BsJustifyRight,{}),label:"Right Align"},{id:H.JustifyAlign,icon:e.jsx(h.BsJustify,{}),label:"Justify Align"}],Q=[{id:"normal",label:"Normal",icon:e.jsx(h.BsTextParagraph,{})},{id:"h1",label:"Heading 1",icon:e.jsx(h.BsTypeH1,{})},{id:"h2",label:"Heading 2",icon:e.jsx(h.BsTypeH2,{})},{id:"h3",label:"Heading 3",icon:e.jsx(h.BsTypeH3,{})},{id:"h4",label:"Heading 4",icon:e.jsx(h.BsTypeH4,{})},{id:"h5",label:"Heading 5",icon:e.jsx(h.BsTypeH5,{})},{id:"h6",label:"Heading 6",icon:e.jsx(h.BsTypeH6,{})}];function V(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const Y=new Map;function Z(e){let t=Y.get(e);return void 0===t&&(t=function(e){const t={};if(!e)return t;const n=e.split(";");for(const e of n)if(""!==e){const[n,r]=e.split(/:([^]+)/);n&&r&&(t[n.trim()]=r.trim())}return t}(e),Y.set(e,t)),t}function ee(e,t){(v.$isRangeSelection(e)?e.isCollapsed():v.$isTextNode(e)||v.$isElementNode(e))||V(280);const n=Z(v.$isRangeSelection(e)?e.style:v.$isTextNode(e)?e.getStyle():e.getTextStyle()),r=Object.entries(t).reduce((t,[r,i])=>("function"==typeof i?t[r]=i(n[r],e):null===i?delete t[r]:t[r]=i,t),{...n}),i=function(e){let t="";for(const n in e)n&&(t+=`${n}: ${e[n]};`);return t}(r);v.$isRangeSelection(e)||v.$isTextNode(e)?e.setStyle(i):e.setTextStyle(i),Y.set(i,r)}function te(e,t){if(v.$isRangeSelection(e)&&e.isCollapsed()){ee(e,t);const n=e.anchor.getNode();v.$isElementNode(n)&&n.isEmpty()&&ee(n,t)}!function(e){const t=v.$getSelection();if(!t)return;const n=new Map,r=e=>n.get(e.getKey())||[0,e.getTextContentSize()];if(v.$isRangeSelection(t))for(const e of v.$caretRangeFromSelection(t).getTextSlices())e&&n.set(e.caret.origin.getKey(),e.getSliceIndices());const i=t.getNodes();for(const t of i){if(!v.$isTextNode(t)||!t.canHaveFormat())continue;const[n,i]=r(t);i!==n&&(v.$isTokenOrSegmented(t)||0===n&&i===t.getTextContentSize()?e(t):e(t.splitText(n,i)[0===n?0:1]))}v.$isRangeSelection(t)&&"text"===t.anchor.type&&"text"===t.focus.type&&t.anchor.key===t.focus.key&&function(e){if(e.isBackward()){const{anchor:t,focus:n}=e,{key:r,offset:i,type:o}=t;t.set(n.key,n.offset,n.type),n.set(r,i,o)}}(t)}(e=>{ee(e,t)})}function ne(e,t){const n=e.getFormatType(),r=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),r!==t.getIndent()&&t.setIndent(r)}function re(e){return e.getNode().isAttached()}function ie(e){let t=e;for(;null!==t&&!v.$isRootOrShadowRoot(t);){const e=t.getLatest(),n=t.getParent();0===e.getChildrenSize()&&t.remove(!0),t=n}}function oe(e,t,n=null){const r=e.getStartEndPoints(),i=r?r[0]:null,o=e.getNodes(),a=o.length;if(null!==i&&(0===a||1===a&&"element"===i.type&&0===i.getNode().getChildrenSize())){const e="text"===i.type?i.getNode().getParentOrThrow():i.getNode(),r=e.getChildren();let o=t();return o.setFormat(e.getFormatType()),o.setIndent(e.getIndent()),r.forEach(e=>o.append(e)),n&&(o=n.append(o)),void e.replace(o)}let s=null,l=[];for(let r=0;r<a;r++){const i=o[r];v.$isRootOrShadowRoot(i)?(ae(e,l,l.length,t,n),l=[],s=i):null===s||null!==s&&v.$hasAncestor(i,s)?l.push(i):(ae(e,l,l.length,t,n),l=[i])}ae(e,l,l.length,t,n)}function ae(e,t,n,r,i=null){if(0===t.length)return;const o=t[0],a=new Map,s=[];let l=v.$isElementNode(o)?o:o.getParentOrThrow();l.isInline()&&(l=l.getParentOrThrow());let c=!1;for(;null!==l;){const e=l.getPreviousSibling();if(null!==e){l=e,c=!0;break}if(l=l.getParentOrThrow(),v.$isRootOrShadowRoot(l))break}const d=new Set;for(let e=0;e<n;e++){const n=t[e];v.$isElementNode(n)&&0===n.getChildrenSize()&&d.add(n.getKey())}const u=new Set;for(let e=0;e<n;e++){const n=t[e];let i=n.getParent();if(null!==i&&i.isInline()&&(i=i.getParent()),null!==i&&v.$isLeafNode(n)&&!u.has(n.getKey())){const e=i.getKey();if(void 0===a.get(e)){const t=r();t.setFormat(i.getFormatType()),t.setIndent(i.getIndent()),s.push(t),a.set(e,t),i.getChildren().forEach(e=>{t.append(e),u.add(e.getKey()),v.$isElementNode(e)&&e.getChildrenKeys().forEach(e=>u.add(e))}),ie(i)}}else if(d.has(n.getKey())){v.$isElementNode(n)||V(179);const e=r();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),s.push(e),n.remove(!0)}}if(null!==i)for(let e=0;e<s.length;e++){const t=s[e];i.append(t)}let f=null;if(v.$isRootOrShadowRoot(l))if(c)if(null!==i)l.insertAfter(i);else for(let e=s.length-1;e>=0;e--){const t=s[e];l.insertAfter(t)}else{const e=l.getFirstChild();if(v.$isElementNode(e)&&(l=e),null===e)if(i)l.append(i);else for(let e=0;e<s.length;e++){const t=s[e];l.append(t),f=t}else if(null!==i)e.insertBefore(i);else for(let t=0;t<s.length;t++){const n=s[t];e.insertBefore(n),f=n}}else if(i)l.insertAfter(i);else for(let e=s.length-1;e>=0;e--){const t=s[e];l.insertAfter(t),f=t}const h=v.$getPreviousSelection();v.$isRangeSelection(h)&&re(h.anchor)&&re(h.focus)?v.$setSelection(h.clone()):null!==f?f.selectEnd():e.dirty=!0}function se(e,t,n){const r=Z(e.getStyle());return null!==r&&r[t]||n}function le(e,t,n=""){let r=null;const i=e.getNodes(),o=e.anchor,a=e.focus,s=e.isBackward(),l=s?a.offset:o.offset,c=s?a.getNode():o.getNode();if(v.$isRangeSelection(e)&&e.isCollapsed()&&""!==e.style){const n=Z(e.style);if(null!==n&&t in n)return n[t]}for(let e=0;e<i.length;e++){const o=i[e];if((0===e||0!==l||!o.is(c))&&v.$isTextNode(o)){const e=se(o,t,n);if(null===r)r=e;else if(r!==e){r="";break}}}return null===r?n:r}const ce="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,de=ce&&"documentMode"in document?document.documentMode:null;function ue(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function fe(e,t){if("function"==typeof e)return e(t);null!=e&&(e.current=t)}function he(t){const n=ge(t),r=$.forwardRef((t,r)=>{const{children:i,...o}=t,a=$.Children.toArray(i),s=a.find(xe);if(s){const t=s.props.children,i=a.map(e=>e===s?$.Children.count(t)>1?$.Children.only(null):$.isValidElement(t)?t.props.children:null:e);return e.jsx(n,{...o,ref:r,children:$.isValidElement(t)?$.cloneElement(t,void 0,i):null})}return e.jsx(n,{...o,ref:r,children:i})});return r.displayName=`${t}.Slot`,r}ce&&"InputEvent"in window&&!de&&new window.InputEvent("input");var pe=he("Slot");function ge(e){const t=$.forwardRef((e,t)=>{const{children:n,...r}=e;if($.isValidElement(n)){const e=function(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;if(n)return e.ref;if(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n)return e.props.ref;return e.props.ref||e.ref}(n),i=function(e,t){const n={...t};for(const r in t){const i=e[r],o=t[r];/^on[A-Z]/.test(r)?i&&o?n[r]=(...e)=>{const t=o(...e);return i(...e),t}:i&&(n[r]=i):"style"===r?n[r]={...i,...o}:"className"===r&&(n[r]=[i,o].filter(Boolean).join(" "))}return{...e,...n}}(r,n.props);return n.type!==$.Fragment&&(i.ref=t?function(...e){return t=>{let n=!1;const r=e.map(e=>{const r=fe(e,t);return n||"function"!=typeof r||(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){const n=r[t];"function"==typeof n?n():fe(e[t],null)}}}}(t,e):e),$.cloneElement(n,i)}return $.Children.count(n)>1?$.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var me=Symbol("radix.slottable");function xe(e){return $.isValidElement(e)&&"function"==typeof e.type&&"__radixId"in e.type&&e.type.__radixId===me}function ve(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return j.twMerge(N.clsx(e))}var be=y.cva("cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",toolbar:"bg-transparent hover:bg-slate-100/80 text-gray-600",toolbarActive:"bg-slate-100 text-gray-900 ",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-2",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9"}},defaultVariants:{variant:"default",size:"default"}});function ye(t){var n=t.className,r=t.variant,i=t.size,o=t.asChild,a=void 0!==o&&o,s=K(t,["className","variant","size","asChild"]),l=a?pe:"button";return e.jsx(l,q({"data-slot":"button",className:ve(be({variant:r,size:i,className:n}))},s))}function Ne(t){var n=t.delayDuration,r=void 0===n?0:n,i=K(t,["delayDuration"]);return e.jsx(z.Provider,q({"data-slot":"tooltip-provider",delayDuration:r},i))}function je(t){var n=K(t,[]);return e.jsx(Ne,{children:e.jsx(z.Root,q({"data-slot":"tooltip"},n))})}function we(t){var n=K(t,[]);return e.jsx(z.Trigger,q({"data-slot":"tooltip-trigger"},n))}function Ce(t){var n=t.className,r=t.sideOffset,i=void 0===r?0:r,o=t.children,a=K(t,["className","sideOffset","children"]);return e.jsx(z.Portal,{children:e.jsxs(z.Content,q({"data-slot":"tooltip-content",sideOffset:i,className:ve("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",n)},a,{children:[o,e.jsx(z.Arrow,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]}))})}function _e(t){var n=K(t,[]);return e.jsx(P.Root,q({"data-slot":"popover"},n))}function ke(t){var n=K(t,[]);return e.jsx(P.Trigger,q({"data-slot":"popover-trigger"},n))}function Oe(t){var n=t.className,r=t.align,i=void 0===r?"center":r,o=t.sideOffset,a=void 0===o?4:o,s=K(t,["className","align","sideOffset"]);return e.jsx(P.Portal,{children:e.jsx(P.Content,q({"data-slot":"popover-content",align:i,sideOffset:a,className:ve("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",n)},s))})}function Ae(t){var r=t.onAction,i=t.selectionMap,o=n.useState(!1),a=o[0],s=o[1];return e.jsxs(_e,{open:a,onOpenChange:function(e){return s(e)},children:[e.jsx(ke,{asChild:!0,children:e.jsxs(ye,{variant:a?"toolbarActive":"toolbar",onClick:function(){return s(!a)},size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e.jsx("span",{children:"Aa"})," ",e.jsx(_.HiChevronDown,{className:" transition-normal duration-100 ".concat(a?"rotate-180":"rotate-0")})]})}),e.jsx(Oe,{className:"p-2 w-fit flex flex-col items-start gap-1",children:W.map(function(t){var n=t.id,o=t.label,a=t.icon;return e.jsxs(ye,{variant:i[n]?"toolbarActive":"toolbar",onClick:function(){return r(n)},size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[a," ",e.jsx("span",{className:"ml-2",children:o})]},n)})})]})}function Se(){return e.jsx("div",{className:"w-[1px] h-[20px] mx-[2px] bg-gray-300 shrink-0"})}function Te(t){var r=t.updateHeading,i=t.headingSelectionMap,o=Q.find(function(e){return i[e.id]}),a=n.useState(!1),s=a[0],l=a[1];return e.jsxs(_e,{open:s,onOpenChange:function(e){return l(e)},children:[e.jsx(ke,{asChild:!0,children:e.jsxs(ye,{variant:s?"toolbarActive":"toolbar",onClick:function(){return l(!s)},size:"icon",className:"size-8 w-fit p-2 select-none min-w-[130px] border-[1px] border-gray-100",children:[null==o?void 0:o.icon,e.jsx("span",{children:null==o?void 0:o.label})," ",e.jsx(_.HiChevronDown,{className:" transition-normal duration-100 ".concat(s?"rotate-180":"rotate-0")})]})}),e.jsx(Oe,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:Q.map(function(t){var n=t.id,o=t.label,a=t.icon;return e.jsxs(ye,{variant:i[n]?"toolbarActive":"toolbar",onClick:function(){return r(n)},size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[a," ",e.jsx("span",{className:"ml-2",children:o})]},n)})})]})}function Ee(t){var n=t.className,r=t.type,i=K(t,["className","type"]);return e.jsx("input",q({type:r,"data-slot":"input",className:ve("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",n)},i))}
2
- /**
3
- * @license lucide-react v0.546.0 - ISC
4
- *
5
- * This source code is licensed under the ISC license.
6
- * See the LICENSE file in the root directory of this source tree.
7
- */const Me=e=>{const t=(e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()))(e);return t.charAt(0).toUpperCase()+t.slice(1)},Le=(...e)=>e.filter((e,t,n)=>Boolean(e)&&""!==e.trim()&&n.indexOf(e)===t).join(" ").trim(),Re=e=>{for(const t in e)if(t.startsWith("aria-")||"role"===t||"title"===t)return!0};
8
- /**
9
- * @license lucide-react v0.546.0 - ISC
10
- *
11
- * This source code is licensed under the ISC license.
12
- * See the LICENSE file in the root directory of this source tree.
13
- */
14
- var De={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};
15
- /**
16
- * @license lucide-react v0.546.0 - ISC
17
- *
18
- * This source code is licensed under the ISC license.
19
- * See the LICENSE file in the root directory of this source tree.
20
- */const $e=n.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:r=2,absoluteStrokeWidth:i,className:o="",children:a,iconNode:s,...l},c)=>n.createElement("svg",{ref:c,...De,width:t,height:t,stroke:e,strokeWidth:i?24*Number(r)/Number(t):r,className:Le("lucide",o),...!a&&!Re(l)&&{"aria-hidden":"true"},...l},[...s.map(([e,t])=>n.createElement(e,t)),...Array.isArray(a)?a:[a]])),ze=(e,t)=>{const r=n.forwardRef(({className:r,...i},o)=>{return n.createElement($e,{ref:o,iconNode:t,className:Le(`lucide-${a=Me(e),a.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}`,`lucide-${e}`,r),...i});var a});return r.displayName=Me(e),r},Pe=ze("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]),Be=ze("pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]),Fe=ze("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]),Ie=ze("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);
21
- /**
22
- * @license lucide-react v0.546.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */function He(t){var r=t.linkUrl,i=t.setLinkUrl,o=t.onConfirm,a=t.onCancel,s=t.removeLink,l=n.useState(!1),c=l[0],d=l[1],u=n.useRef(null),f=n.useRef(null);return n.useEffect(function(){"https://"===r&&d(!0)},[r]),n.useEffect(function(){var e;c&&(null===(e=f.current)||void 0===e||e.focus())},[c]),n.useEffect(function(){var e=function(e){u.current&&!u.current.contains(e.target)&&a()};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}},[a]),e.jsxs("div",{ref:u,className:ve("absolute z-[9999] top-[100px] right-[20px]","bg-white shadow-lg rounded-xl px-1.5 py-1 sm:px-3 sm:py-2 flex items-center space-x-2","border border-gray-200"),children:[e.jsx("div",{className:"flex-1 min-w-[200px]",children:c?e.jsx(Ee,{ref:f,className:"h-8 text-sm",value:r,onChange:function(e){return i(e.target.value)},onKeyDown:function(e){"Enter"===e.key?(e.preventDefault(),o(r),d(!1)):"Escape"===e.key&&(e.preventDefault(),d(!1),a())}}):e.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 text-sm underline truncate block max-w-full text-start",children:r})}),e.jsxs("div",{children:[e.jsx(ye,{variant:"ghost",size:"icon",onMouseDown:function(e){return e.preventDefault()},onClick:function(){c?(o(r),d(!1)):d(!0)},className:"h-8 w-8",children:c?e.jsx(Pe,{className:"h-4 w-4"}):e.jsx(Be,{className:"h-4 w-4"})}),e.jsx(ye,{variant:"ghost",size:"icon",onMouseDown:function(e){return e.preventDefault()},onClick:s,className:"h-8 w-8",children:e.jsx(O.TiDeleteOutline,{className:"h-4 w-4"})})]})]})}function Ue(t){var r=t.onAction,i=t.alignmentSelectionMap,o=G.find(function(e){return i[e.id]}),a=n.useState(!1),s=a[0],l=a[1];return e.jsxs(_e,{open:s,onOpenChange:function(e){return l(e)},children:[e.jsx(ke,{asChild:!0,children:e.jsxs(ye,{variant:s?"toolbarActive":"toolbar",onClick:function(){return l(!s)},size:"icon",className:"size-8 w-fit p-2 select-none min-w-[145px] border-[1px] border-gray-100",children:[null==o?void 0:o.icon,e.jsx("span",{children:null==o?void 0:o.label})," ",e.jsx(_.HiChevronDown,{className:" transition-normal duration-100 ".concat(s?"rotate-180":"rotate-0")})]})}),e.jsx(Oe,{align:"start",className:"p-2 w-fit flex flex-col items-start gap-1",children:G.map(function(t){var n=t.id,o=t.label,a=t.icon;return e.jsxs(ye,{variant:i[n]?"toolbarActive":"toolbar",onClick:function(){return r(n)},size:"icon",className:"size-8 w-full flex justify-start py-2 px-3 select-none",children:[a," ",e.jsx("span",{className:"ml-2",children:o})]},n)})})]})}function qe(t){var r,i,o=t.color,a=t.onChange,s=t.icon,l=n.useState(!1),c=l[0],d=l[1],u=n.useRef(null),f=n.useRef(null);n.useEffect(function(){var e=function(e){f.current&&!f.current.contains(e.target)&&u.current&&!u.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}},[]);return e.jsxs("div",{className:"relative inline-block",children:[e.jsx(ye,{ref:u,variant:"ghost",size:"icon",className:"rounded-md text-gray-700 hover:bg-gray-200","aria-label":"Change Color",onClick:function(){return d(function(e){return!e})},children:s}),c&&S.createPortal(e.jsx("div",{ref:f,className:"\n absolute z-50 p-2 bg-transparent rounded-md select-none\n transition-all duration-200\n origin-top-left w-fit\n ".concat(c?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"),style:{top:null===(r=u.current)||void 0===r?void 0:r.getBoundingClientRect().bottom,left:null===(i=u.current)||void 0===i?void 0:i.getBoundingClientRect().left,position:"absolute"},onMouseDown:function(e){return e.preventDefault()},children:e.jsx(A.SketchPicker,{color:o,onChangeComplete:function(e){a(e.hex)}})}),document.body)]})}function Ke(){var t=x.useLexicalComposerContext()[0],r=n.useState({color:"#000",bgColor:"#fff"}),i=r[0],o=i.color,a=i.bgColor,s=r[1],l=function(){var e=v.$getSelection();if(v.$isRangeSelection(e)){var t=le(e,"color","#000"),n=le(e,"background","#fff");s({color:t,bgColor:n})}};n.useEffect(function(){return ue(t.registerUpdateListener(function(e){e.editorState.read(function(){l()})}),t.registerCommand(v.SELECTION_CHANGE_COMMAND,function(){return l(),!1},1))},[t]);var c=function(e){var n=e.property,r=e.color;t.update(function(){var e,t=v.$getSelection();t&&te(t,((e={})[n]=r,e))})};return e.jsxs(e.Fragment,{children:[e.jsx(qe,{color:o,onChange:function(e){c({property:"color",color:e})},icon:e.jsx(p.AiOutlineFontColors,{})}),e.jsx(qe,{color:a,onChange:function(e){c({property:"background",color:e})},icon:e.jsx(p.AiOutlineBgColors,{})})]})}function We(t){var n=t.blockType,r=x.useLexicalComposerContext()[0];return e.jsxs(e.Fragment,{children:[e.jsxs(je,{delayDuration:700,children:[e.jsx(we,{asChild:!0,children:e.jsx(ye,{variant:"ol"===n?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add ordered list",onClick:function(){"ol"===n?r.dispatchCommand(d.REMOVE_LIST_COMMAND,void 0):r.dispatchCommand(d.INSERT_ORDERED_LIST_COMMAND,void 0)},children:e.jsx(h.BsListOl,{})})}),e.jsx(Ce,{side:"bottom",children:"Ordered list"})]}),e.jsxs(je,{delayDuration:700,children:[e.jsx(we,{asChild:!0,children:e.jsx(ye,{variant:"ul"===n?"toolbarActive":"toolbar",size:"icon",className:"size-8","aria-label":"Add unordered list",onClick:function(){"ul"===n?r.dispatchCommand(d.REMOVE_LIST_COMMAND,void 0):r.dispatchCommand(d.INSERT_UNORDERED_LIST_COMMAND,void 0)},children:e.jsx(h.BsListUl,{})})}),e.jsx(Ce,{side:"bottom",children:"Unordered list"})]})]})}var Je=function(t){var r=t.src,i=t.altText,o=t.nodeKey,a=t.width,s=t.height,l=t.maxWidth,c=x.useLexicalComposerContext()[0],d=n.useState({width:"number"==typeof a?a:l,height:"number"==typeof s?s:"auto"}),u=d[0],f=d[1],h=n.useRef(null),p=n.useRef(null),g=function(e){if(p.current){var t=e.clientX-p.current.x,n=Math.min(l,Math.max(50,p.current.width+t)),r=n/p.current.width*p.current.height||"auto";f({width:n,height:r})}},m=function(){p.current&&(c.update(function(){var e=v.$getNodeByKey(o);e&&e instanceof Qe&&e.updateDimensions(u.width,u.height)}),window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",m))};return e.jsxs("div",{ref:h,style:{display:"inline-block",position:"relative",maxWidth:l},children:[e.jsx("img",{src:r,alt:i,style:{width:u.width,height:u.height,maxWidth:"100%",display:"block"}}),e.jsx("div",{onMouseDown:function(e){var t,n;e.preventDefault(),e.stopPropagation(),p.current={x:e.clientX,y:e.clientY,width:u.width,height:null!==(n=null===(t=h.current)||void 0===t?void 0:t.offsetHeight)&&void 0!==n?n:0},window.addEventListener("mousemove",g),window.addEventListener("mouseup",m)},style:{position:"absolute",bottom:0,right:0,width:14,height:14,background:"white",border:"1px solid #999",cursor:"nwse-resize",borderRadius:2}})]})},Xe=function(e){return v.$applyNodeReplacement(new Qe(e))},Ge=function(e){if(e instanceof HTMLImageElement){var t=e.src,n=e.alt;return{node:Xe({src:t,altText:n})}}return null},Qe=function(t){function n(e){var n=void 0===e?{}:e,r=n.src,i=void 0===r?"":r,o=n.altText,a=void 0===o?"":o,s=n.maxWidth,l=void 0===s?1080:s,c=n.width,d=n.height,u=n.key,f=t.call(this,u)||this;return f.__altText=a,f.__src=i,f.__maxWidth=l,f.__height=d,f.__width=c,f}return I(n,t),n.getType=function(){return"image"},n.clone=function(e){return new n({altText:e.__altText,src:e.__src,height:e.__height,width:e.__width,maxWidth:e.__maxWidth,key:e.getKey()})},n.prototype.createDOM=function(){return document.createElement("span")},n.prototype.exportDOM=function(){var e=document.createElement("img");return e.setAttribute("src",this.__src),e.setAttribute("alt",this.__altText),this.__width&&"inherit"!==this.__width&&e.setAttribute("width",String(this.__width)),this.__height&&"inherit"!==this.__height&&e.setAttribute("height",String(this.__height)),{element:e}},n.importDOM=function(){return{img:function(){return{conversion:Ge,priority:0}}}},n.prototype.exportJSON=function(){return{type:"image",version:1,src:this.__src,altText:this.__altText,maxWidth:this.__maxWidth,width:this.__width,height:this.__height}},n.importJSON=function(e){return new n({src:e.src,altText:e.altText,maxWidth:e.maxWidth,width:e.width,height:e.height})},n.prototype.updateDimensions=function(e,t){var n=this.getWritable();n.__width=e,n.__height=t},n.prototype.updateDOM=function(){return!1},n.prototype.decorate=function(){return e.jsx(Je,{src:this.__src,altText:this.__altText,nodeKey:this.getKey(),width:this.__width,height:this.__height,maxWidth:this.__maxWidth})},n}(v.DecoratorNode);function Ve(t){var n=K(t,[]);return e.jsx(B.Root,q({"data-slot":"dialog"},n))}function Ye(t){var n=K(t,[]);return e.jsx(B.Trigger,q({"data-slot":"dialog-trigger"},n))}function Ze(t){var n=K(t,[]);return e.jsx(B.Portal,q({"data-slot":"dialog-portal"},n))}function et(t){var n=t.className,r=K(t,["className"]);return e.jsx(B.Overlay,q({"data-slot":"dialog-overlay",className:ve("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",n)},r))}function tt(t){var n=t.className,r=t.children,i=t.showCloseButton,o=void 0===i||i,a=K(t,["className","children","showCloseButton"]);return e.jsxs(Ze,{"data-slot":"dialog-portal",children:[e.jsx(et,{}),e.jsxs(B.Content,q({"data-slot":"dialog-content","aria-describedby":"",className:ve("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",n)},a,{children:[r,o&&e.jsxs(B.Close,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[e.jsx(Ie,{}),e.jsx("span",{className:"sr-only",children:"Close"})]})]}))]})}function nt(t){var n=t.className,r=K(t,["className"]);return e.jsx("div",q({"data-slot":"dialog-header",className:ve("flex flex-col gap-2 text-center sm:text-left",n)},r))}function rt(t){var n=t.className,r=K(t,["className"]);return e.jsx("div",q({"data-slot":"dialog-footer",className:ve("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",n)},r))}function it(t){var n=t.className,r=K(t,["className"]);return e.jsx(B.Title,q({"data-slot":"dialog-title",className:ve("text-lg leading-none font-semibold",n)},r))}function ot(){var t=n.useState(!1),r=t[0],i=t[1],o=n.useState(""),a=o[0],s=o[1],l=n.useState(""),c=l[0],d=l[1],u=n.useState(),f=u[0],h=u[1],p=n.useRef(null),m=x.useLexicalComposerContext()[0];return e.jsxs("div",{children:[e.jsx("input",{type:"file",ref:p,accept:"image/*",className:"hidden",onChange:function(e){var t,n=null===(t=e.target.files)||void 0===t?void 0:t[0];n&&h(n),e.target.value=""}}),e.jsxs(Ve,{open:r,onOpenChange:i,children:[e.jsx(Ye,{asChild:!0,children:e.jsx(ye,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e.jsx(g.IoImageOutline,{})})}),e.jsxs(tt,{className:"sm:max-w-md",children:[e.jsx(nt,{children:e.jsx(it,{className:"!text-lg text-gray-800",children:"Add Image"})}),e.jsx("div",{className:"flex flex-col gap-4 py-2",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(Ee,{value:c,onChange:function(e){return d(e.target.value)},placeholder:"Alt text"}),e.jsx(Ee,{value:a,onChange:function(e){return s(e.target.value)},placeholder:"Add Image by URL"}),e.jsxs("div",{className:"flex items-center w-full text-gray-500 text-sm",children:[e.jsx("div",{className:"flex-grow border-t border-gray-300"}),e.jsx("span",{className:"mx-2",children:"or"}),e.jsx("div",{className:"flex-grow border-t border-gray-300"})]}),e.jsxs("div",{className:"flex flex-col gap-2 w-fit",children:[e.jsxs(ye,{variant:"outline",className:"flex items-center gap-2 bg-gray-50 hover:bg-gray-100",onClick:function(){var e;return null===(e=p.current)||void 0===e?void 0:e.click()},children:[e.jsx(Fe,{className:"h-4 w-4"})," Upload Image"]}),f&&e.jsx("span",{className:"text-sm text-gray-600",children:f.name})]})]})}),e.jsx(rt,{children:e.jsx(ye,{onClick:function(){var e="";a&&(e=a),f&&(e=URL.createObjectURL(f)),m.update(function(){var t=Xe({src:e,altText:c});v.$insertNodes([t])}),h(void 0),d(""),s(""),i(!1)},disabled:!a&&!f,className:"!bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Add Image"})})]})]})]})}var at=function(e){var t=e.id,n=e.provider;return new ht({id:t,provider:n})},st="data-lexical-video",lt="data-provider",ct="315px",dt="560px",ut=function(e,t){return"drive"===t?"https://drive.google.com/file/d/".concat(e,"/preview"):"https://www.youtube-nocookie.com/embed/".concat(e)},ft=function(e){var t,n=null==e?void 0:e.getAttribute(st),r=null!==(t=null==e?void 0:e.getAttribute(lt))&&void 0!==t?t:"youtube";return n?{node:at({id:n,provider:r})}:null},ht=function(t){function n(e){var n=e.id,r=e.provider,i=e.key,o=t.call(this,i)||this;return o.__id=n,o.__provider=r,o}return I(n,t),n.getType=function(){return"video"},n.clone=function(e){return new n({id:e.__id,provider:e.__provider,key:e.getKey()})},n.importJSON=function(e){return at({id:e.id,provider:e.provider})},n.prototype.exportJSON=function(){return{id:this.__id,provider:this.__provider,type:"video",version:1}},n.prototype.updateDOM=function(){return!1},n.prototype.decorate=function(){return e.jsx("iframe",{height:ct,width:dt,src:ut(this.__id,this.__provider),frameBorder:"0",allowFullScreen:!0})},n.prototype.createDOM=function(){return document.createElement("div")},n.prototype.exportDOM=function(){var e=document.createElement("iframe");return e.setAttribute(st,this.__id),e.setAttribute(lt,this.__provider),e.setAttribute("height",ct),e.setAttribute("width",dt),e.setAttribute("src",ut(this.__id,this.__provider)),{element:e}},n.importDOM=function(){return{iframe:function(){return{conversion:ft,priority:0}}}},n}(v.DecoratorNode);function pt(){var t=n.useState(!1),r=t[0],i=t[1],o=n.useState(!1),a=o[0],s=o[1],l=n.useState(""),c=l[0],d=l[1],u=x.useLexicalComposerContext()[0];return n.useEffect(function(){r||(d(""),s(!1))},[r]),e.jsx("div",{children:e.jsxs(Ve,{open:r,onOpenChange:i,children:[e.jsx(Ye,{asChild:!0,children:e.jsx(ye,{size:"icon",variant:"ghost",className:"rounded-md text-gray-700 hover:bg-gray-200",children:e.jsx(E.FaYoutube,{})})}),e.jsxs(tt,{className:"sm:max-w-md",children:[e.jsx(nt,{children:e.jsx(it,{className:"!text-lg text-gray-800",children:"Embed Video"})}),e.jsxs("div",{className:"py-2",children:[e.jsx(Ee,{value:c,onChange:function(e){return d(e.target.value)},placeholder:"Add YouTube or Google Drive URL"}),a&&e.jsx("p",{className:"mt-1.5 text-red-800/80 text-[0.8rem]",children:"It's not a valid youtube or google drive URL"})]}),e.jsx(rt,{children:e.jsx(ye,{onClick:function(){var e;if(c){var t=null,n=null,r=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(c);r&&11===(null===(e=r[2])||void 0===e?void 0:e.length)&&(t="youtube",n=r[2]);var o=/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)\//.exec(c);o&&o[1]&&(t="drive",n=o[1]),n&&t?(u.update(function(){var e=at({id:n,provider:t});v.$insertNodes([e])}),d(""),s(!1),i(!1)):s(!0)}},disabled:!c,className:"bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:"Embed"})})]})]})})}function gt(t){var n=t.value;return e.jsx("div",{className:"prose max-w-none",dangerouslySetInnerHTML:{__html:n}})}function mt(t){var r=t.value,i=t.triggerLabel,o=void 0===i?"Preview":i,a=n.useState(!1),s=a[0],l=a[1];return e.jsxs(Ve,{open:s,onOpenChange:l,children:[e.jsx(Ye,{asChild:!0,children:e.jsxs(ye,{variant:s?"toolbarActive":"toolbar",size:"icon",className:"size-8 w-fit p-2 select-none border-[1px] border-gray-100",children:[e.jsx(M.VscPreview,{})," ",o]})}),e.jsxs(tt,{className:"w-[90vw] md:w-[80vw] lg:w-[70vw] max-w-4xl max-h-[90vh] sm:max-w-[1000px] overflow-y-auto bg-white",children:[e.jsx(nt,{children:e.jsx(it,{className:"!text-xl",children:"Content Preview"})}),e.jsxs("div",{className:" p-[2vw] rounded-lg border min-h-[400px] w-full text-start bg-white",children:[e.jsx("div",{className:"py-1 border-b-2 mb-4 font-medium",children:"CONTENT"}),e.jsx(gt,{value:r})]})]})]})}var xt=function(t){var i,o,a,s=t.value,l=x.useLexicalComposerContext()[0],c=n.useState(((i={})[H.Undo]=!0,i[H.Redo]=!0,i)),u=c[0],f=c[1],h=n.useState(!1),p=h[0],g=h[1],m=n.useState(((o={})[H.LeftAlign]=!0,o)),y=m[0],N=m[1],j=n.useState(((a={})[U.Normal]=!0,a)),w=j[0],C=j[1],_=n.useState("paragraph"),O=_[0],A=_[1],S=n.useState("https://"),T=S[0],E=S[1],M=!0,L=function(){var e,t;if(M){var n=l.getRootElement();n&&(n.scrollTop=0,M=!1)}var i=v.$getSelection();if(v.$isRangeSelection(i)){var o=((e={})[H.Bold]=i.hasFormat("bold"),e[H.Italics]=i.hasFormat("italic"),e[H.Underline]=i.hasFormat("underline"),e[H.Uppercase]=i.hasFormat("uppercase"),e[H.Lowercase]=i.hasFormat("lowercase"),e[H.Capitalize]=i.hasFormat("capitalize"),e[H.Strikethrough]=i.hasFormat("strikethrough"),e[H.Superscript]=i.hasFormat("superscript"),e[H.Subscript]=i.hasFormat("subscript"),e[H.Code]=i.hasFormat("code"),e[H.Highlight]=i.hasFormat("highlight"),e);N(o);var a=i.anchor.getNode(),s="root"===a.getKey()?a:a.getTopLevelElementOrThrow(),c=s.getKey();if(!l.getElementByKey(c))return;if(d.$isListNode(s)){var u=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}(a,d.ListNode),f=u?u.getTag():s.getTag();A(f)}else if("paragraph"===s.getType()||r.$isHeadingNode(s)){var h=null;r.$isHeadingNode(s)&&(h=s.getTag());var p=((t={})[U.H1]="h1"===h,t[U.H2]="h2"===h,t[U.H3]="h3"===h,t[U.H4]="h4"===h,t[U.H5]="h5"===h,t[U.H6]="h6"===h,t[U.Normal]="paragraph"===s.getType(),t);C(p)}else A(s.getType());var m=(v.$isElementNode(a)?a:s).getFormat();N(function(e){var t;return q(q({},e),((t={})[H.LeftAlign]=0===m||1===m,t[H.CenterAlign]=2===m,t[H.RightAlign]=3===m,t[H.JustifyAlign]=4===m,t))}),"quote"===s.getType()?N(function(e){var t;return q(q({},e),((t={})[H.Quote]=!0,t))}):N(function(e){var t;return q(q({},e),((t={})[H.Quote]=!1,t))});var x=i.anchor.getNode(),y=x.getParent();b.$isLinkNode(y)?(N(function(e){var t;return q(q({},e),((t={})[H.Link]=!0,t))}),E(y.getURL()),g(!0)):b.$isLinkNode(x)?(N(function(e){var t;return q(q({},e),((t={})[H.Link]=!0,t))}),E(x.getURL()),g(!0)):(N(function(e){var t;return q(q({},e),((t={})[H.Link]=!1,t))}),E("https://"),g(!1))}};n.useEffect(function(){return ue(l.registerUpdateListener(function(e){e.editorState.read(function(){L()})}),l.registerCommand(v.SELECTION_CHANGE_COMMAND,function(){return L(),!1},1),l.registerCommand(v.CAN_UNDO_COMMAND,function(e){return f(function(t){return q(q({},t),{undo:!e})}),!1},1),l.registerCommand(v.CAN_REDO_COMMAND,function(e){return f(function(t){return q(q({},t),{redo:!e})}),!1},1))},[]);var R=function(e){switch(e){case H.Bold:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"bold");break;case H.Italics:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"italic");break;case H.Underline:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"underline");break;case H.Lowercase:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"lowercase");break;case H.Uppercase:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"uppercase");break;case H.Capitalize:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"capitalize");break;case H.Strikethrough:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"strikethrough");break;case H.Superscript:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"superscript");break;case H.Subscript:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"subscript");break;case H.Highlight:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"highlight");break;case H.Code:l.dispatchCommand(v.FORMAT_TEXT_COMMAND,"code");break;case H.Quote:l.update(function(){var e=v.$getSelection();if(v.$isRangeSelection(e)){var t=e.anchor.getNode().getParent();t&&r.$isQuoteNode(t)?function(e,t,n=ne){if(null===e)return;const r=e.getStartEndPoints(),i=new Map;let o=null;if(r){const[e,t]=r;o=v.$createRangeSelection(),o.anchor.set(e.key,e.offset,e.type),o.focus.set(t.key,t.offset,t.type);const n=v.$findMatchingParent(e.getNode(),v.INTERNAL_$isBlock),a=v.$findMatchingParent(t.getNode(),v.INTERNAL_$isBlock);v.$isElementNode(n)&&i.set(n.getKey(),n),v.$isElementNode(a)&&i.set(a.getKey(),a)}for(const t of e.getNodes())if(v.$isElementNode(t)&&v.INTERNAL_$isBlock(t))i.set(t.getKey(),t);else if(null===r){const e=v.$findMatchingParent(t,v.INTERNAL_$isBlock);v.$isElementNode(e)&&i.set(e.getKey(),e)}for(const[e,r]of i){const i=t();n(r,i),r.replace(i,!0),o&&(e===o.anchor.key&&o.anchor.set(i.getKey(),o.anchor.offset,o.anchor.type),e===o.focus.key&&o.focus.set(i.getKey(),o.focus.offset,o.focus.type))}o&&e.is(v.$getSelection())&&v.$setSelection(o)}(e,function(){return v.$createParagraphNode()}):oe(e,function(){return r.$createQuoteNode()})}});break;case H.Link:D(),g(!0);break;case H.LeftAlign:l.dispatchCommand(v.FORMAT_ELEMENT_COMMAND,"left");break;case H.RightAlign:l.dispatchCommand(v.FORMAT_ELEMENT_COMMAND,"right");break;case H.CenterAlign:l.dispatchCommand(v.FORMAT_ELEMENT_COMMAND,"center");break;case H.JustifyAlign:l.dispatchCommand(v.FORMAT_ELEMENT_COMMAND,"justify");break;case H.Undo:l.dispatchCommand(v.UNDO_COMMAND,void 0);break;case H.Redo:l.dispatchCommand(v.REDO_COMMAND,void 0)}},D=n.useCallback(function(){console.log("insertlink"),p?l.dispatchCommand(b.TOGGLE_LINK_COMMAND,null):""!==T&&l.dispatchCommand(b.TOGGLE_LINK_COMMAND,T)},[l,p]),$=n.useCallback(function(){E(""),l.dispatchCommand(b.TOGGLE_LINK_COMMAND,null),g(!1)},[l]);return e.jsxs("div",{className:"relative flex gap-1.5 flex-wrap justify-center items-center p-1.5 pb-2 mb-1 border-b-[1px]",children:[X.map(function(t){var n=t.id,r=t.label,i=t.icon;return n===H.Divider?e.jsx(Se,{},n):e.jsxs(je,{delayDuration:700,children:[e.jsx(we,{asChild:!0,children:e.jsx(ye,{variant:y[n]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:function(){return R(n)},disabled:!!u[n],children:i})}),e.jsx(Ce,{side:"bottom",children:r})]},n)}),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(Te,{updateHeading:function(e){l.update(function(){var t=v.$getSelection();v.$isRangeSelection(t)&&oe(t,"normal"===e?function(){return v.$createParagraphNode()}:function(){return r.$createHeadingNode(e)})})},headingSelectionMap:w}),e.jsx(Se,{})]}),J.map(function(t){var n=t.id,r=t.label,i=t.icon;return n===H.Divider?e.jsx(Se,{},n):e.jsxs(je,{delayDuration:700,children:[e.jsx(we,{asChild:!0,children:e.jsx(ye,{variant:y[n]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:function(){return R(n)},disabled:!!u[n],children:i})}),e.jsx(Ce,{side:"bottom",children:r})]},n)}),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(We,{blockType:O}),e.jsx(Se,{})]}),e.jsx(Ke,{}),e.jsx(Ae,{onAction:R,selectionMap:y}),e.jsxs("div",{className:"flex gap-1.5 justify-start items-center",children:[e.jsx(Ue,{onAction:R,alignmentSelectionMap:y}),e.jsx(Se,{})]}),e.jsxs(je,{delayDuration:700,children:[e.jsx(we,{asChild:!0,children:e.jsx(ye,{variant:y[H.Link]?"toolbarActive":"toolbar",size:"icon",className:"size-8",onClick:function(){return R(H.Link)},disabled:!!u[H.Link],children:e.jsx(k.IoIosLink,{})})}),e.jsx(Ce,{side:"bottom",children:"Link"})]}),p&&e.jsx(He,{linkUrl:T,setLinkUrl:E,removeLink:$,onConfirm:function(e){l.dispatchCommand(b.TOGGLE_LINK_COMMAND,{url:e,target:"_blank"}),E(e),g(!1)},onCancel:function(){E(""),g(!1)}}),e.jsx(ot,{}),e.jsx(pt,{}),e.jsx(mt,{value:s})]})};function vt(e,t){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const n=document.createElement("div"),r=v.$getRoot().getChildren();for(let i=0;i<r.length;i++)bt(e,r[i],n,t);return n.innerHTML}function bt(e,t,n,r=null){let i=null===r||t.isSelected(r);const o=v.$isElementNode(t)&&t.excludeFromCopy("html");let a=t;if(null!==r){let e=v.$cloneWithProperties(t);e=v.$isTextNode(e)&&null!==r?function(e,t){const n=e.getStartEndPoints();if(t.isSelected(e)&&!v.$isTokenOrSegmented(t)&&null!==n){const[r,i]=n,o=e.isBackward(),a=r.getNode(),s=i.getNode(),l=t.is(a),c=t.is(s);if(l||c){const[n,r]=v.$getCharacterOffsets(e),i=a.is(s),l=t.is(o?s:a),c=t.is(o?a:s);let d,u=0;i?(u=n>r?r:n,d=n>r?n:r):l?(u=o?r:n,d=void 0):c&&(u=0,d=o?n:r),t.__text=t.__text.slice(u,d)}}return t}(r,e):e,a=e}const s=v.$isElementNode(a)?a.getChildren():[],l=v.getRegisteredNode(e,a.getType());let c;c=l&&void 0!==l.exportDOM?l.exportDOM(e,a):a.exportDOM(e);const{element:d,after:u}=c;if(!d)return!1;const f=document.createDocumentFragment();for(let n=0;n<s.length;n++){const o=s[n],a=bt(e,o,f,r);!i&&v.$isElementNode(t)&&a&&t.extractWithChild(o,r,"html")&&(i=!0)}if(i&&!o){if((v.isHTMLElement(d)||v.isDocumentFragment(d))&&d.append(f),n.append(d),u){const e=u.call(a,d);e&&(v.isDocumentFragment(d)?d.replaceChildren(e):d.replaceWith(e))}}else n.append(f);return i}const yt=new Set(["STYLE","SCRIPT"]);function Nt(e,t,n,r,i=new Map,o){let a=[];if(yt.has(e.nodeName))return a;let s=null;const l=function(e,t){const{nodeName:n}=e,r=t._htmlConversions.get(n.toLowerCase());let i=null;if(void 0!==r)for(const t of r){const n=t(e);null!==n&&(null===i||(i.priority||0)<=(n.priority||0))&&(i=n)}return null!==i?i.conversion:null}(e,t),c=l?l(e):null;let d=null;if(null!==c){d=c.after;const t=c.node;if(s=Array.isArray(t)?t[t.length-1]:t,null!==s){for(const[,e]of i)if(s=e(s,o),!s)break;s&&a.push(...Array.isArray(t)?t:[s])}null!=c.forChild&&i.set(e.nodeName,c.forChild)}const u=e.childNodes;let f=[];const h=(null==s||!v.$isRootOrShadowRoot(s))&&(null!=s&&v.$isBlockElementNode(s)||r);for(let e=0;e<u.length;e++)f.push(...Nt(u[e],t,n,h,new Map(i),s));return null!=d&&(f=d(f)),v.isBlockDomNode(e)&&(f=function(e,t,n){const r=e.style.textAlign,i=[];let o=[];for(let e=0;e<t.length;e++){const a=t[e];if(v.$isBlockElementNode(a))r&&!a.getFormat()&&a.setFormat(r),i.push(a);else if(o.push(a),e===t.length-1||e<t.length-1&&v.$isBlockElementNode(t[e+1])){const e=n();e.setFormat(r),e.append(...o),i.push(e),o=[]}}return i}(e,f,h?()=>{const e=new v.ArtificialNode__DO_NOT_USE;return n.push(e),e}:v.$createParagraphNode)),null==s?f.length>0?a=a.concat(f):v.isBlockDomNode(e)&&function(e){return null!=e.nextSibling&&null!=e.previousSibling&&(v.isInlineDomNode(e.nextSibling)&&v.isInlineDomNode(e.previousSibling))}(e)&&(a=a.concat(v.$createLineBreakNode())):v.$isElementNode(s)&&s.append(...f),a}function jt(t){var r=t.value,i=t.onChange,o=x.useLexicalComposerContext()[0],a=n.useState(!0),s=a[0],l=a[1];return n.useEffect(function(){r&&s&&(l(!1),o.update(function(){if(vt(o)!==r){v.$getRoot().clear();var e=(new DOMParser).parseFromString(r,"text/html"),t=function(e,t){const n=v.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let r=[];const i=[];for(const t of n)if(!yt.has(t.nodeName)){const n=Nt(t,e,i,!1);null!==n&&(r=r.concat(n))}return function(e){for(const t of e)t.getNextSibling()instanceof v.ArtificialNode__DO_NOT_USE&&t.insertAfter(v.$createLineBreakNode());for(const t of e){const e=t.getChildren();for(const n of e)t.insertBefore(n);t.remove()}}(i),r}(o,e);v.$insertNodes(t)}}))},[o,r,s]),n.useEffect(function(){l(!0)},[r]),e.jsx(R.OnChangePlugin,{onChange:function(e){e.read(function(){i(vt(o))})}})}var wt=function(e){var t=e.id;return new St({id:t})},Ct="data-lexical-youtube",_t="315px",kt="560px",Ot=function(e){return"https://www.youtube-nocookie.com/embed/".concat(e)},At=function(e){var t=null==e?void 0:e.getAttribute(Ct);return t?{node:wt({id:t})}:null},St=function(t){function n(e){var n=e.id,r=e.key,i=t.call(this,r)||this;return i.__id=n,i}return I(n,t),n.getType=function(){return"youtube"},n.clone=function(e){return new n({id:e.__id,key:e.getKey()})},n.importJSON=function(e){return wt({id:e.id})},n.prototype.exportJSON=function(){return{id:this.__id,type:"youtube",version:1}},n.prototype.decorate=function(){return e.jsx("iframe",{height:_t,width:kt,src:Ot(this.__id),frameBorder:"0",allowFullScreen:!0})},n.prototype.createDOM=function(){return document.createElement("div")},n.prototype.exportDOM=function(){var e=document.createElement("iframe");return e.setAttribute(Ct,this.__id),e.setAttribute("height",_t),e.setAttribute("width",kt),e.setAttribute("src",Ot(this.__id)),{element:e}},n.importDOM=function(){return{iframe:function(){return{conversion:At,priority:0}}}},n}(v.DecoratorNode),Tt={text:{bold:"font-bold",underline:"underline",italic:"italic",strikethrough:"line-through",underlineStrikethrough:"underline line-through",uppercase:"uppercase",lowercase:"lowercase",capitalize:"capitalize",code:"bg-gray-100 border border-gray-300 px-1 rounded text-sm font-mono text-black"},paragraph:"mb-2",list:{ul:"list-disc list-inside pl-6",ol:"list-decimal list-inside pl-6",listitem:"mb-1"},quote:"border-l-4 border-gray-400 pl-4 italic text-gray-800 bg-gray-50 py-2 rounded-r",link:"text-blue-600 underline hover:text-blue-800"},Et=n.memo(function(u){var f=u.name,h=u.value,p=u.onChange,g=u.placeholder,m=n.useMemo(function(){return{namespace:f,theme:Tt,onError:function(e){console.error("Lexical error:",e)},nodes:[r.HeadingNode,i.CodeHighlightNode,i.CodeNode,d.ListNode,d.ListItemNode,r.QuoteNode,b.LinkNode,Qe,St,ht]}},[f]);return e.jsx("div",{className:"border-[1px] rounded-lg w-full max-w-[900px] pb-2 scrollbar-thin",children:e.jsxs(t.LexicalComposer,{initialConfig:m,children:[e.jsx("div",{className:"px-2",children:e.jsx(xt,{value:h})}),e.jsx("div",{className:"relative",children:e.jsx(o.RichTextPlugin,{contentEditable:e.jsx(a.ContentEditable,{className:"h-[400px] text-start w-full text-[14px] p-[8px] overflow-auto outline-0"}),placeholder:e.jsx("div",{className:"absolute text-[#999] top-[8px] left-[10px] text-[14px]",children:g||"Some Text"}),ErrorBoundary:s.LexicalErrorBoundary})}),e.jsx(l.HistoryPlugin,{}),e.jsx(c.ListPlugin,{}),e.jsx(L.LinkPlugin,{}),e.jsx(jt,{value:h,onChange:p})]})})});module.exports=Et;
27
- //# sourceMappingURL=index.js.map