UNPKG

@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.28 kB
import{jsx as t,Fragment as e}from"react/jsx-runtime";import{useEffect as o}from"react";import{useLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{COMMAND_PRIORITY_LOW as m}from"lexical";import{v4 as i}from"uuid";import{AttachmentGroup as n}from"../components/AttachmentGroup.js";import{TOGGLE_ATTACH_FILE_COMMAND as a}from"../command/index.js";import{mergeRegister as c,isMimeType as s,mediaFileReader as l}from"@lexical/utils";import{DRAG_DROP_PASTE as p}from"@lexical/rich-text";const f=["*"],h=h=>{const{editable:d,attachments:u,onAttachmentsChange:x,acceptableMimeTypes:g=f,...C}=h,[y]=r();return o((()=>{if(d){const t=g.map((t=>t.endsWith("*")?t.replace("*",""):t)),e=t=>{const e=[...u||[],...t.map((t=>({id:i(),size:t.size,name:t.name,type:t.type,file:t})))];x?.(e)};return c(y.registerCommand(a,(o=>{const r=[];return Array.from(o.target.files||[]).forEach((e=>{s(e,t)&&r.push(e)})),r.length>0&&e(r),!1}),m),y.registerCommand(p,(o=>((async()=>{const r=await l(o,t),m=[];for(const{file:e}of r)s(e,t)&&m.push(e);m.length>0&&e(m)})(),!0)),m))}}),[g,u,d,y,x]),u&&u.length?t(n,{attachments:u,editable:d,onAttachmentsChange:x,clientWidth:y.getRootElement()?.clientWidth||200,...C}):t(e,{})};export{f as ACCEPTABLE_IMAGE_TYPES,h as AttachmentsPlugin};