@nexusui/components
Version:
These are custom components specially-developed for NexusUI applications. They will make your life easier by giving you out-of-the-box implementations for various high-level UI elements that you can drop directly into your application.
2 lines (1 loc) • 1.33 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("@lexical/react/LexicalComposerContext"),i=require("lexical"),a=require("uuid"),n=require("../components/AttachmentGroup.js"),s=require("../command/index.js"),c=require("@lexical/utils"),o=require("@lexical/rich-text");const m=["*"];exports.ACCEPTABLE_IMAGE_TYPES=m,exports.AttachmentsPlugin=l=>{const{editable:u,attachments:p,onAttachmentsChange:h,acceptableMimeTypes:x=m,...A}=l,[d]=r.useLexicalComposerContext();return t.useEffect((()=>{if(u){const e=x.map((e=>e.endsWith("*")?e.replace("*",""):e)),t=e=>{const t=[...p||[],...e.map((e=>({id:a.v4(),size:e.size,name:e.name,type:e.type,file:e})))];h?.(t)};return c.mergeRegister(d.registerCommand(s.TOGGLE_ATTACH_FILE_COMMAND,(r=>{const i=[];return Array.from(r.target.files||[]).forEach((t=>{c.isMimeType(t,e)&&i.push(t)})),i.length>0&&t(i),!1}),i.COMMAND_PRIORITY_LOW),d.registerCommand(o.DRAG_DROP_PASTE,(r=>((async()=>{const i=await c.mediaFileReader(r,e),a=[];for(const{file:t}of i)c.isMimeType(t,e)&&a.push(t);a.length>0&&t(a)})(),!0)),i.COMMAND_PRIORITY_LOW))}}),[x,p,u,d,h]),p&&p.length?e.jsx(n.AttachmentGroup,{attachments:p,editable:u,onAttachmentsChange:h,clientWidth:d.getRootElement()?.clientWidth||200,...A}):e.jsx(e.Fragment,{})};