@remarkablejames/editor 0.0.6 → 0.0.7
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/README.md +1 -1
- package/lib/ActionMenuButton-D9o3Kwmv.cjs +1 -0
- package/lib/{ActionMenuButton-CpmEfz31.js → ActionMenuButton-nxV91Fqo.js} +10 -9
- package/lib/Attachment.cjs +19 -1
- package/lib/Attachment.js +270 -7
- package/lib/Blockquote.cjs +2 -2
- package/lib/Blockquote.js +12 -13
- package/lib/Bold.cjs +1 -1
- package/lib/Bold.js +10 -11
- package/lib/BulletList.cjs +1 -1
- package/lib/BulletList.js +8 -9
- package/lib/Callout.cjs +1 -1
- package/lib/Callout.js +45 -40
- package/lib/Clear.cjs +1 -1
- package/lib/Clear.js +14 -13
- package/lib/Code.cjs +1 -1
- package/lib/Code.js +5 -6
- package/lib/CodeBlock.cjs +1 -1
- package/lib/CodeBlock.js +33 -31
- package/lib/CodeView.cjs +1 -1
- package/lib/CodeView.js +8 -9
- package/lib/Color.cjs +1 -1
- package/lib/Color.js +19 -18
- package/lib/Column.cjs +1 -1
- package/lib/Column.js +8 -9
- package/lib/Drawer-Bh-y5bs8.cjs +2 -0
- package/lib/{Drawer-CayP4Ww4.js → Drawer-CF6Z_IA2.js} +36 -30
- package/lib/Drawer.cjs +1 -1
- package/lib/Drawer.js +3 -3
- package/lib/Emoji.cjs +1 -1
- package/lib/Emoji.js +18 -17
- package/lib/Excalidraw.cjs +1 -1
- package/lib/Excalidraw.js +37 -32
- package/lib/ExportPdf.cjs +3 -3
- package/lib/ExportPdf.js +13 -14
- package/lib/ExportWord.cjs +1 -1
- package/lib/ExportWord.js +6 -6
- package/lib/FontFamily.cjs +1 -1
- package/lib/FontFamily.js +6 -7
- package/lib/FontSize.cjs +1 -1
- package/lib/FontSize.js +14 -15
- package/lib/Heading.cjs +1 -1
- package/lib/Heading.js +28 -28
- package/lib/Highlight.cjs +1 -1
- package/lib/Highlight.js +23 -22
- package/lib/History.cjs +1 -1
- package/lib/History.js +11 -11
- package/lib/HorizontalRule.cjs +1 -1
- package/lib/HorizontalRule.js +9 -10
- package/lib/Icon-BvGyfX2j.js +15 -0
- package/lib/Icon-wjwoRc9F.cjs +1 -0
- package/lib/Iframe-BbfZKbPY.cjs +1 -0
- package/lib/{Iframe-C6Sb97KS.js → Iframe-Dfd3LI7b.js} +14 -11
- package/lib/Iframe.cjs +1 -1
- package/lib/Iframe.js +3 -3
- package/lib/Image.cjs +1 -1
- package/lib/Image.js +5 -4
- package/lib/ImageCropper-CY1ETEjC.cjs +10 -0
- package/lib/ImageCropper-DrSdjo9x.js +979 -0
- package/lib/ImageGif.cjs +1 -1
- package/lib/ImageGif.js +83 -80
- package/lib/ImportWord.cjs +1 -1
- package/lib/ImportWord.js +37 -35
- package/lib/{Indent-CcFe8py3.js → Indent-CDVF9DWN.js} +30 -31
- package/lib/Indent-Q1VuhSM2.cjs +1 -0
- package/lib/Indent.cjs +1 -1
- package/lib/Indent.js +2 -2
- package/lib/Italic.cjs +1 -1
- package/lib/Italic.js +11 -12
- package/lib/{Katex-Bp6AnIUF.js → Katex-DqhWWAA-.js} +22 -18
- package/lib/Katex-K1QU2SB2.cjs +4 -0
- package/lib/Katex.cjs +1 -1
- package/lib/Katex.js +2 -2
- package/lib/LineHeight.cjs +1 -1
- package/lib/LineHeight.js +20 -19
- package/lib/Link.cjs +1 -1
- package/lib/Link.js +2 -2
- package/lib/LinkEditBlock-CBYGLs3J.cjs +5 -0
- package/lib/{LinkEditBlock-BiHumIJR.js → LinkEditBlock-xP0pGVhB.js} +27 -22
- package/lib/Mention.js +3 -3
- package/lib/{Mermaid-Dlx0XTJj.js → Mermaid-BJ6ryVdY.js} +59 -55
- package/lib/Mermaid-D3_nLeOW.cjs +2 -0
- package/lib/Mermaid.cjs +1 -1
- package/lib/Mermaid.js +2 -2
- package/lib/MoreMark.cjs +1 -1
- package/lib/MoreMark.js +28 -26
- package/lib/OrderedList.cjs +1 -1
- package/lib/OrderedList.js +10 -11
- package/lib/PaywallSeparator.cjs +1 -1
- package/lib/PaywallSeparator.js +9 -9
- package/lib/SearchAndReplace.cjs +1 -1
- package/lib/SearchAndReplace.js +39 -34
- package/lib/SlashCommand.cjs +1 -1
- package/lib/SlashCommand.js +5 -5
- package/lib/SlashCommandNodeView-CUJrDQS7.cjs +1 -0
- package/lib/{SlashCommandNodeView-DzmsYaNc.js → SlashCommandNodeView-DS9FqMiY.js} +23 -21
- package/lib/Strike.cjs +1 -1
- package/lib/Strike.js +11 -12
- package/lib/Table-CV6pUoVf.cjs +5 -0
- package/lib/{Table-IH34r4jd.js → Table-CcG-JNtV.js} +46 -46
- package/lib/Table.cjs +1 -1
- package/lib/Table.js +1 -1
- package/lib/TaskList.cjs +1 -1
- package/lib/TaskList.js +11 -12
- package/lib/TextAlign.cjs +1 -1
- package/lib/TextAlign.js +27 -26
- package/lib/TextDirection.cjs +1 -1
- package/lib/TextDirection.js +19 -18
- package/lib/TextUnderline.cjs +1 -1
- package/lib/TextUnderline.js +8 -9
- package/lib/{Twitter-FVQKPaq6.js → Twitter-BIL3o833.js} +19 -15
- package/lib/Twitter-BfSTqPDh.cjs +1 -0
- package/lib/Twitter.cjs +1 -1
- package/lib/Twitter.js +2 -2
- package/lib/Video-DAKr90QL.js +231 -0
- package/lib/Video-HAinT0w6.cjs +1 -0
- package/lib/Video.cjs +1 -1
- package/lib/Video.js +5 -4
- package/lib/bubble.cjs +3 -3
- package/lib/bubble.js +112 -101
- package/lib/button-090-I3tp.js +35 -0
- package/lib/button-B4Sz2ZhW.cjs +1 -0
- package/lib/checkbox-BCPsu7yR.cjs +1 -0
- package/lib/checkbox-DiXWHAI0.js +29 -0
- package/lib/{clsx-BUPZHhq3.js → clsx-m_C5j3RU.js} +24 -24
- package/lib/components/RichTextProvider.d.ts +1 -1
- package/lib/dialog-C8J59d2J.cjs +1 -0
- package/lib/dialog-bDkDW-C_.js +95 -0
- package/lib/dom-dataset-BqoJhJXt.cjs +1 -0
- package/lib/dom-dataset-CIEeltF6.js +47 -0
- package/lib/{dropdown-menu-Ce2TorkG.js → dropdown-menu-DWt_xj4h.js} +1 -1
- package/lib/{dropdown-menu-DirUyRAI.cjs → dropdown-menu-tUP872Zv.cjs} +1 -1
- package/lib/events.constant-Bke62qxm.cjs +1 -0
- package/lib/events.constant-CSWD3-ho.js +72 -0
- package/lib/file-i7e4nQY2.cjs +1 -0
- package/lib/file-jDdkhyj7.js +43 -0
- package/lib/{index-RkKGy5oa.js → index-B3Ijnbxs.js} +1 -1
- package/lib/index-BXh8X1ch.cjs +1 -0
- package/lib/{index-Dl3OjzmR.js → index-C1KQsOcg.js} +1 -1
- package/lib/{index-D4M4hrH4.js → index-C8FjP66D.js} +1 -1
- package/lib/index-jMN4V2hr.js +2763 -0
- package/lib/{index-DZj2z9_1.js → index-s3l5RdyW.js} +1 -1
- package/lib/index.cjs +4 -4
- package/lib/index.js +464 -149
- package/lib/input-C_J-pfTx.js +21 -0
- package/lib/input-DwLo4r7V.cjs +1 -0
- package/lib/isNumber-BTYSVlKo.cjs +1 -0
- package/lib/isNumber-WaBzl_0s.js +15 -0
- package/lib/label-BgIVynq3.cjs +1 -0
- package/lib/label-ClsOg9Hr.js +11 -0
- package/lib/{popover-BzJyaFvy.js → popover-BC7FRr8B.js} +1 -1
- package/lib/{popover-BdLwAlrM.cjs → popover-C3A6zzNV.cjs} +1 -1
- package/lib/{renderNodeView-dj6AaFSX.js → renderNodeView-C_hPIdEs.js} +2 -2
- package/lib/select-B8HIWDXf.cjs +1 -0
- package/lib/select-DSKqhVGR.js +120 -0
- package/lib/{separator-D-fyzbfx.js → separator-BJWSNjvr.js} +23 -22
- package/lib/separator-D6ruF682.cjs +1 -0
- package/lib/style.css +1 -1
- package/lib/tabs-D1J1iB7B.js +46 -0
- package/lib/tabs-IEbMQmNX.cjs +1 -0
- package/lib/textarea-Ch5w3PiI.js +20 -0
- package/lib/textarea-CtVdqwSM.cjs +1 -0
- package/lib/theme.cjs +1 -1
- package/lib/theme.js +18 -18
- package/lib/throttle-CRNq0z-O.js +249 -0
- package/lib/throttle-gTTvqDTW.cjs +1 -0
- package/lib/toggle-C9tcMm1r.cjs +1 -0
- package/lib/toggle-CaSwYCk4.js +89 -0
- package/lib/{updatePosition-C294Pixi.js → updatePosition-DvfTZHcH.js} +2 -2
- package/lib/use-toast-C6zPo25l.cjs +1 -0
- package/lib/use-toast-CEOqhXfx.js +97 -0
- package/lib/useButtonProps-D-ruygH7.js +165 -0
- package/lib/useButtonProps-D9ndBdmA.cjs +1 -0
- package/package.json +21 -32
- package/lib/ActionMenuButton-NfiUDE60.cjs +0 -1
- package/lib/Drawer-DlgdaO_B.cjs +0 -2
- package/lib/Iframe-CANdxSpV.cjs +0 -1
- package/lib/Indent-DuB2U6Cs.cjs +0 -1
- package/lib/Katex-DFU1unCm.cjs +0 -4
- package/lib/LinkEditBlock-C2zX0WVK.cjs +0 -5
- package/lib/Mermaid-B8lQSOGn.cjs +0 -2
- package/lib/SlashCommandNodeView-BfWNWGRr.cjs +0 -1
- package/lib/Table-BfM6ywrZ.cjs +0 -5
- package/lib/Twitter-axcoCgD7.cjs +0 -1
- package/lib/index-BynXHtjJ.cjs +0 -28
- package/lib/index-CnKgiZFQ.js +0 -5576
- package/lib/separator-CoQaQmFK.cjs +0 -1
package/lib/ImageGif.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("./clsx-CXbNJWDD.cjs"),N=require("./throttle-gTTvqDTW.cjs"),l=require("react/jsx-runtime"),u=require("react"),G=require("./index-DgOXAdKt.cjs"),L=require("./isNumber-BTYSVlKo.cjs"),W=require("./toggle-C9tcMm1r.cjs"),z=require("./useButtonProps-D9ndBdmA.cjs"),P=require("./popover-C3A6zzNV.cjs"),D=require("./input-DwLo4r7V.cjs"),S={TOP_LEFT:"tl",TOP_RIGHT:"tr",BOTTOM_LEFT:"bl",BOTTOM_RIGHT:"br"};function B(e){var $,q;const[t,r]=u.useState({width:G.IMAGE_MAX_SIZE,height:G.IMAGE_MAX_SIZE}),[c,i]=u.useState({width:0,height:0}),[n]=u.useState([S.TOP_LEFT,S.TOP_RIGHT,S.BOTTOM_LEFT,S.BOTTOM_RIGHT]),[s,a]=u.useState(!1),[h,b]=u.useState({x:0,y:0,w:0,h:0,dir:""}),{align:x}=($=e==null?void 0:e.node)==null?void 0:$.attrs,m=u.useMemo(()=>{var v;const{src:o,alt:f,width:w,height:M}=(v=e==null?void 0:e.node)==null?void 0:v.attrs,A=L.isNumber(w)?`${w}px`:w,d=L.isNumber(M)?`${M}px`:M;return{src:o||void 0,alt:f||void 0,style:{width:A||void 0,height:d||void 0}}},[(q=e==null?void 0:e.node)==null?void 0:q.attrs]),T=u.useMemo(()=>{const{style:{width:o}}=m;return{width:o==="100%"?o:void 0}},[m]);function g(o){i({width:o.target.width,height:o.target.height})}function _(){const{editor:o,getPos:f}=e;o.commands.setNodeSelection(f())}const y=u.useCallback(N.throttle(()=>{const{editor:o}=e,{width:f}=getComputedStyle(o.view.dom);r(w=>({...w,width:Number.parseInt(f,10)}))},G.IMAGE_THROTTLE_WAIT_TIME),[e==null?void 0:e.editor]);function p(o,f){o.preventDefault(),o.stopPropagation();const w=c.width,M=c.height,A=w/M;let d=Number(e.node.attrs.width),v=Number(e.node.attrs.height);const I=t.width;d&&!v?(d=d>I?I:d,v=Math.round(d/A)):v&&!d?(d=Math.round(v*A),d=d>I?I:d):!d&&!v?(d=w>I?I:w,v=Math.round(d/A)):d=d>I?I:d,a(!0),b({x:o.clientX,y:o.clientY,w:d,h:v,dir:f})}const j=u.useCallback(N.throttle(o=>{if(o.preventDefault(),o.stopPropagation(),!s)return;const{x:f,w,dir:M}=h,A=(o.clientX-f)*(/l/.test(M)?-1:1),d=L.clamp(w+A,G.IMAGE_MIN_SIZE,t.width);e.updateAttributes({width:d,height:null})},G.IMAGE_THROTTLE_WAIT_TIME),[s,h,t,e.updateAttributes]),E=u.useCallback(o=>{o.preventDefault(),o.stopPropagation(),s&&(b({x:0,y:0,w:0,h:0,dir:""}),a(!1),_())},[s,_]),C=u.useCallback(()=>{document==null||document.addEventListener("mousemove",j,!0),document==null||document.addEventListener("mouseup",E,!0)},[j,E]),O=u.useCallback(()=>{document==null||document.removeEventListener("mousemove",j,!0),document==null||document.removeEventListener("mouseup",E,!0)},[j,E]);u.useEffect(()=>(s?C():O(),()=>{O()}),[s,C,O]);const R=u.useMemo(()=>new ResizeObserver(()=>y()),[y]);return u.useEffect(()=>(R.observe(e.editor.view.dom),()=>{R.disconnect()}),[e.editor.view.dom,R]),l.jsx(k.NodeViewWrapper,{className:"image-view",style:{...T,width:"100%",textAlign:x},children:l.jsxs("div",{"data-drag-handle":!0,draggable:"true",style:T,className:`image-view__body ${e!=null&&e.selected?"image-view__body--focused":""} ${s?"image-view__body--resizing":""}`,children:[l.jsx("img",{alt:m.alt,className:"image-view__body__image block",height:"auto",onClick:_,onLoad:g,src:m.src,style:m.style}),(e==null?void 0:e.editor.view.editable)&&((e==null?void 0:e.selected)||s)&&l.jsx("div",{className:"image-resizer",children:n==null?void 0:n.map(o=>l.jsx("span",{className:`image-resizer__handler image-resizer__handler--${o}`,onMouseDown:f=>p(f,o)},`image-dir-${o}`))})]})})}async function F(e){var c;const r=await(await fetch(`https://api.giphy.com/v1/gifs/trending?q=&limit=15&api_key=${e}`)).json();return(c=r==null?void 0:r.data)==null?void 0:c.map(i=>{var n,s,a;return{id:i==null?void 0:i.id,src:(n=i==null?void 0:i.images.original)==null?void 0:n.url,width:+((s=i==null?void 0:i.images.original)==null?void 0:s.width),height:+((a=i==null?void 0:i.images.original)==null?void 0:a.width)}})}async function V(e,t){var i;const c=await(await fetch(`https://api.giphy.com/v1/gifs/search?q=${e}&limit=15&api_key=${t}`)).json();return(i=c==null?void 0:c.data)==null?void 0:i.map(n=>{var s,a,h;return{id:n==null?void 0:n.id,src:(s=n==null?void 0:n.images.original)==null?void 0:s.url,width:+((a=n==null?void 0:n.images.original)==null?void 0:a.width),height:+((h=n==null?void 0:n.images.original)==null?void 0:h.width)}})}async function X(e){var n,s;const t=await fetch(`https://tenor.googleapis.com/v2/trending_terms?key=${e}&limit=10`),r=await(t==null?void 0:t.json()),i=await(await fetch(`https://tenor.googleapis.com/v2/search?key=${e}&q=${(n=r==null?void 0:r.results)==null?void 0:n[0]}&limit=15`)).json();return(s=i==null?void 0:i.results)==null?void 0:s.map(a=>{var h,b,x,m,T,g,_,y;return{id:a==null?void 0:a.id,src:(b=(h=a==null?void 0:a.media_formats)==null?void 0:h.gif)==null?void 0:b.url,width:(T=(m=(x=a==null?void 0:a.media_formats)==null?void 0:x.gif)==null?void 0:m.dims)==null?void 0:T[0],height:(y=(_=(g=a==null?void 0:a.media_formats)==null?void 0:g.gif)==null?void 0:_.dims)==null?void 0:y[1]}})}async function Y(e,t){var i;const c=await(await fetch(`https://tenor.googleapis.com/v2/search?key=${t}&q=${e}&limit=15`)).json();return(i=c==null?void 0:c.results)==null?void 0:i.map(n=>{var s,a,h,b,x,m,T,g;return{id:n==null?void 0:n.id,src:(a=(s=n==null?void 0:n.media_formats)==null?void 0:s.gif)==null?void 0:a.url,width:(x=(b=(h=n==null?void 0:n.media_formats)==null?void 0:h.gif)==null?void 0:b.dims)==null?void 0:x[0],height:(g=(T=(m=n==null?void 0:n.media_formats)==null?void 0:m.gif)==null?void 0:T.dims)==null?void 0:g[1]}})}function Z(e,t){return{searchTrending:async()=>t?e==="giphy"?F(t):e==="tenor"?X(t):[]:[],searchWord:async i=>t?e==="giphy"?V(i,t):e==="tenor"?Y(i,t):[]:[]}}function U({selectImage:e,apiKey:t,provider:r,children:c}){const[i,n]=u.useState(!1),[s,a]=u.useState([]),{editorDisabled:h}=z.useToggleActive(),b=u.useRef(null),{searchTrending:x,searchWord:m}=Z(r,t);u.useEffect(()=>{(async()=>{const g=await x();a(g)})()},[]);const T=u.useCallback(N.debounce(async g=>{if(!g.target.value){const y=await x();a(y);return}const _=await m(g.target.value);a(_)},350),[]);return l.jsxs(P.Popover,{modal:!0,onOpenChange:n,open:i,children:[l.jsx(P.PopoverTrigger,{asChild:!0,disabled:h,children:c}),l.jsx(P.PopoverContent,{align:"start",className:"richtext-size-full richtext-p-2",hideWhenDetached:!0,side:"bottom",children:t?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"richtext-mb-[10px] richtext-w-full",children:l.jsx(D.Input,{onChange:T,placeholder:"Search GIF",ref:b,type:"text"})}),l.jsx("div",{className:"richtext-max-h-[280px] !richtext-max-w-[400px] richtext-overflow-y-auto",children:l.jsx("div",{className:"richtext-grid richtext-grid-cols-2 richtext-gap-1",children:s!=null&&s.length?s==null?void 0:s.map(g=>l.jsx("img",{alt:"",className:"richtext-cursor-pointer richtext-object-contain richtext-text-center",src:g.src,onClick:()=>{e(g.src),n(!1)}},g.id)):l.jsx("p",{children:"No GIFs found"})})})]}):l.jsx("div",{children:l.jsx("p",{children:"Missing Giphy API Key"})})})]})}function J(){const e=z.useButtonProps(H.name),{action:t,icon:r,tooltip:c,apiKey:i,provider:n}=(e==null?void 0:e.componentProps)??{},{editorDisabled:s}=z.useToggleActive(),a=h=>{s||t&&t(h)};return l.jsx(U,{apiKey:i,provider:n,selectImage:a,children:l.jsx(W.ActionButton,{disabled:s,icon:r,tooltip:c})})}const H=N.index_default.extend({name:"imageGif",addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),inline:!1,content:"",marks:"",group:"block",API_KEY:"",provider:"giphy",draggable:!1,selectable:!0,atom:!0,button:({editor:t,extension:r,t:c})=>{var s,a;const i=((s=r==null?void 0:r.options)==null?void 0:s.provider)||"",n=((a=r==null?void 0:r.options)==null?void 0:a.API_KEY)||"";return{componentProps:{action:h=>{t.chain().focus().setImageGif({src:h}).run()},isActive:()=>!1,disabled:!1,icon:"GifIcon",tooltip:c("editor.imageGif.tooltip"),apiKey:n,provider:i}}}}},addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),width:{default:null,parseHTML:t=>{const r=t.style.width||t.getAttribute("width")||"10";return r===void 0?null:Number.parseInt(`${r}`,10)},renderHTML:t=>({width:t.width})},align:{default:"center",parseHTML:t=>t.getAttribute("align"),renderHTML:t=>({align:t.align})}}},addNodeView(){return k.ReactNodeViewRenderer(B)},addCommands(){var e;return{...(e=this.parent)==null?void 0:e.call(this),setImageGif:t=>({commands:r})=>r.insertContent({type:this.name,attrs:t}),updateImageGif:t=>({commands:r})=>r.updateAttributes(this.name,t),setAlignImageGif:t=>({commands:r})=>r.updateAttributes(this.name,{align:t})}},renderHTML({HTMLAttributes:e}){const{align:t}=e;return["div",{style:t?`text-align: ${t};`:"",class:"imageGIf"},["img",k.mergeAttributes({height:"auto"},this.options.HTMLAttributes,e)]]},parseHTML(){return[{tag:"div[class=imageGIf]",getAttrs:e=>{const t=e.querySelector("img"),r=t==null?void 0:t.getAttribute("width");return{src:t==null?void 0:t.getAttribute("src"),alt:t==null?void 0:t.getAttribute("alt"),title:t==null?void 0:t.getAttribute("title"),width:r?Number.parseInt(r,10):null,align:(t==null?void 0:t.getAttribute("align"))||e.style.textAlign||null}}}]}});exports.ImageGif=H;exports.RichTextImageGif=J;
|
package/lib/ImageGif.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { h as B, m as q, k as V } from "./clsx-
|
|
2
|
-
import {
|
|
3
|
-
import { jsx as u, jsxs as
|
|
4
|
-
import { useState as G, useMemo as
|
|
5
|
-
import { I as
|
|
6
|
-
import "./
|
|
7
|
-
import {
|
|
1
|
+
import { h as B, m as q, k as V } from "./clsx-m_C5j3RU.js";
|
|
2
|
+
import { a as H, d as X, c as Y } from "./throttle-CRNq0z-O.js";
|
|
3
|
+
import { jsx as u, jsxs as p, Fragment as Z } from "react/jsx-runtime";
|
|
4
|
+
import { useState as G, useMemo as P, useCallback as M, useEffect as z, useRef as U } from "react";
|
|
5
|
+
import { I as C, i as j, j as J } from "./index-BGd2HiwP.js";
|
|
6
|
+
import { i as W, c as Q } from "./isNumber-WaBzl_0s.js";
|
|
7
|
+
import { A as K } from "./toggle-CaSwYCk4.js";
|
|
8
|
+
import { u as ee, c as D } from "./useButtonProps-D-ruygH7.js";
|
|
9
|
+
import { P as te, a as re, b as ne } from "./popover-BC7FRr8B.js";
|
|
10
|
+
import { I as ie } from "./input-C_J-pfTx.js";
|
|
8
11
|
const O = {
|
|
9
12
|
TOP_LEFT: "tl",
|
|
10
13
|
TOP_RIGHT: "tr",
|
|
@@ -12,14 +15,14 @@ const O = {
|
|
|
12
15
|
BOTTOM_RIGHT: "br"
|
|
13
16
|
};
|
|
14
17
|
function ae(e) {
|
|
15
|
-
var
|
|
16
|
-
const [t,
|
|
17
|
-
width:
|
|
18
|
-
height:
|
|
18
|
+
var R, k;
|
|
19
|
+
const [t, n] = G({
|
|
20
|
+
width: C,
|
|
21
|
+
height: C
|
|
19
22
|
}), [c, i] = G({
|
|
20
23
|
width: 0,
|
|
21
24
|
height: 0
|
|
22
|
-
}), [
|
|
25
|
+
}), [r] = G([
|
|
23
26
|
O.TOP_LEFT,
|
|
24
27
|
O.TOP_RIGHT,
|
|
25
28
|
O.BOTTOM_LEFT,
|
|
@@ -30,9 +33,9 @@ function ae(e) {
|
|
|
30
33
|
w: 0,
|
|
31
34
|
h: 0,
|
|
32
35
|
dir: ""
|
|
33
|
-
}), { align: b } = (
|
|
36
|
+
}), { align: b } = (R = e == null ? void 0 : e.node) == null ? void 0 : R.attrs, g = P(() => {
|
|
34
37
|
var w;
|
|
35
|
-
const { src: o, alt: m, width: f, height: x } = (w = e == null ? void 0 : e.node) == null ? void 0 : w.attrs, A =
|
|
38
|
+
const { src: o, alt: m, width: f, height: x } = (w = e == null ? void 0 : e.node) == null ? void 0 : w.attrs, A = W(f) ? `${f}px` : f, d = W(x) ? `${x}px` : x;
|
|
36
39
|
return {
|
|
37
40
|
src: o || void 0,
|
|
38
41
|
alt: m || void 0,
|
|
@@ -41,7 +44,7 @@ function ae(e) {
|
|
|
41
44
|
height: d || void 0
|
|
42
45
|
}
|
|
43
46
|
};
|
|
44
|
-
}, [(k = e == null ? void 0 : e.node) == null ? void 0 : k.attrs]), _ =
|
|
47
|
+
}, [(k = e == null ? void 0 : e.node) == null ? void 0 : k.attrs]), _ = P(() => {
|
|
45
48
|
const {
|
|
46
49
|
style: { width: o }
|
|
47
50
|
} = g;
|
|
@@ -57,22 +60,22 @@ function ae(e) {
|
|
|
57
60
|
const { editor: o, getPos: m } = e;
|
|
58
61
|
o.commands.setNodeSelection(m());
|
|
59
62
|
}
|
|
60
|
-
const
|
|
61
|
-
|
|
63
|
+
const T = M(
|
|
64
|
+
H(() => {
|
|
62
65
|
const { editor: o } = e, { width: m } = getComputedStyle(o.view.dom);
|
|
63
|
-
|
|
66
|
+
n((f) => ({
|
|
64
67
|
...f,
|
|
65
68
|
width: Number.parseInt(m, 10)
|
|
66
69
|
}));
|
|
67
|
-
},
|
|
70
|
+
}, j),
|
|
68
71
|
[e == null ? void 0 : e.editor]
|
|
69
72
|
);
|
|
70
73
|
function F(o, m) {
|
|
71
74
|
o.preventDefault(), o.stopPropagation();
|
|
72
75
|
const f = c.width, x = c.height, A = f / x;
|
|
73
76
|
let d = Number(e.node.attrs.width), w = Number(e.node.attrs.height);
|
|
74
|
-
const
|
|
75
|
-
d && !w ? (d = d >
|
|
77
|
+
const I = t.width;
|
|
78
|
+
d && !w ? (d = d > I ? I : d, w = Math.round(d / A)) : w && !d ? (d = Math.round(w * A), d = d > I ? I : d) : !d && !w ? (d = f > I ? I : f, w = Math.round(d / A)) : d = d > I ? I : d, s(!0), v({
|
|
76
79
|
x: o.clientX,
|
|
77
80
|
y: o.clientY,
|
|
78
81
|
w: d,
|
|
@@ -81,15 +84,15 @@ function ae(e) {
|
|
|
81
84
|
});
|
|
82
85
|
}
|
|
83
86
|
const N = M(
|
|
84
|
-
|
|
87
|
+
H((o) => {
|
|
85
88
|
if (o.preventDefault(), o.stopPropagation(), !a)
|
|
86
89
|
return;
|
|
87
|
-
const { x: m, w: f, dir: x } = l, A = (o.clientX - m) * (/l/.test(x) ? -1 : 1), d =
|
|
90
|
+
const { x: m, w: f, dir: x } = l, A = (o.clientX - m) * (/l/.test(x) ? -1 : 1), d = Q(f + A, J, t.width);
|
|
88
91
|
e.updateAttributes({
|
|
89
92
|
width: d,
|
|
90
93
|
height: null
|
|
91
94
|
});
|
|
92
|
-
},
|
|
95
|
+
}, j),
|
|
93
96
|
[a, l, t, e.updateAttributes]
|
|
94
97
|
), E = M(
|
|
95
98
|
(o) => {
|
|
@@ -104,21 +107,21 @@ function ae(e) {
|
|
|
104
107
|
[a, y]
|
|
105
108
|
), $ = M(() => {
|
|
106
109
|
document == null || document.addEventListener("mousemove", N, !0), document == null || document.addEventListener("mouseup", E, !0);
|
|
107
|
-
}, [N, E]),
|
|
110
|
+
}, [N, E]), S = M(() => {
|
|
108
111
|
document == null || document.removeEventListener("mousemove", N, !0), document == null || document.removeEventListener("mouseup", E, !0);
|
|
109
112
|
}, [N, E]);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}), [a, $,
|
|
113
|
-
const
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
}), [e.editor.view.dom,
|
|
113
|
+
z(() => (a ? $() : S(), () => {
|
|
114
|
+
S();
|
|
115
|
+
}), [a, $, S]);
|
|
116
|
+
const L = P(() => new ResizeObserver(() => T()), [T]);
|
|
117
|
+
return z(() => (L.observe(e.editor.view.dom), () => {
|
|
118
|
+
L.disconnect();
|
|
119
|
+
}), [e.editor.view.dom, L]), /* @__PURE__ */ u(
|
|
117
120
|
B,
|
|
118
121
|
{
|
|
119
122
|
className: "image-view",
|
|
120
123
|
style: { ..._, width: "100%", textAlign: b },
|
|
121
|
-
children: /* @__PURE__ */
|
|
124
|
+
children: /* @__PURE__ */ p(
|
|
122
125
|
"div",
|
|
123
126
|
{
|
|
124
127
|
"data-drag-handle": !0,
|
|
@@ -138,7 +141,7 @@ function ae(e) {
|
|
|
138
141
|
style: g.style
|
|
139
142
|
}
|
|
140
143
|
),
|
|
141
|
-
(e == null ? void 0 : e.editor.view.editable) && ((e == null ? void 0 : e.selected) || a) && /* @__PURE__ */ u("div", { className: "image-resizer", children:
|
|
144
|
+
(e == null ? void 0 : e.editor.view.editable) && ((e == null ? void 0 : e.selected) || a) && /* @__PURE__ */ u("div", { className: "image-resizer", children: r == null ? void 0 : r.map((o) => /* @__PURE__ */ u(
|
|
142
145
|
"span",
|
|
143
146
|
{
|
|
144
147
|
className: `image-resizer__handler image-resizer__handler--${o}`,
|
|
@@ -154,12 +157,12 @@ function ae(e) {
|
|
|
154
157
|
}
|
|
155
158
|
async function se(e) {
|
|
156
159
|
var c;
|
|
157
|
-
const
|
|
158
|
-
return (c =
|
|
159
|
-
var
|
|
160
|
+
const n = await (await fetch(`https://api.giphy.com/v1/gifs/trending?q=&limit=15&api_key=${e}`)).json();
|
|
161
|
+
return (c = n == null ? void 0 : n.data) == null ? void 0 : c.map((i) => {
|
|
162
|
+
var r, a, s;
|
|
160
163
|
return {
|
|
161
164
|
id: i == null ? void 0 : i.id,
|
|
162
|
-
src: (
|
|
165
|
+
src: (r = i == null ? void 0 : i.images.original) == null ? void 0 : r.url,
|
|
163
166
|
width: +((a = i == null ? void 0 : i.images.original) == null ? void 0 : a.width),
|
|
164
167
|
height: +((s = i == null ? void 0 : i.images.original) == null ? void 0 : s.width)
|
|
165
168
|
};
|
|
@@ -170,30 +173,30 @@ async function oe(e, t) {
|
|
|
170
173
|
const c = await (await fetch(
|
|
171
174
|
`https://api.giphy.com/v1/gifs/search?q=${e}&limit=15&api_key=${t}`
|
|
172
175
|
)).json();
|
|
173
|
-
return (i = c == null ? void 0 : c.data) == null ? void 0 : i.map((
|
|
176
|
+
return (i = c == null ? void 0 : c.data) == null ? void 0 : i.map((r) => {
|
|
174
177
|
var a, s, l;
|
|
175
178
|
return {
|
|
176
|
-
id:
|
|
177
|
-
src: (a =
|
|
178
|
-
width: +((s =
|
|
179
|
-
height: +((l =
|
|
179
|
+
id: r == null ? void 0 : r.id,
|
|
180
|
+
src: (a = r == null ? void 0 : r.images.original) == null ? void 0 : a.url,
|
|
181
|
+
width: +((s = r == null ? void 0 : r.images.original) == null ? void 0 : s.width),
|
|
182
|
+
height: +((l = r == null ? void 0 : r.images.original) == null ? void 0 : l.width)
|
|
180
183
|
};
|
|
181
184
|
});
|
|
182
185
|
}
|
|
183
186
|
async function ce(e) {
|
|
184
|
-
var
|
|
187
|
+
var r, a;
|
|
185
188
|
const t = await fetch(
|
|
186
189
|
`https://tenor.googleapis.com/v2/trending_terms?key=${e}&limit=10`
|
|
187
|
-
),
|
|
188
|
-
`https://tenor.googleapis.com/v2/search?key=${e}&q=${(
|
|
190
|
+
), n = await (t == null ? void 0 : t.json()), i = await (await fetch(
|
|
191
|
+
`https://tenor.googleapis.com/v2/search?key=${e}&q=${(r = n == null ? void 0 : n.results) == null ? void 0 : r[0]}&limit=15`
|
|
189
192
|
)).json();
|
|
190
193
|
return (a = i == null ? void 0 : i.results) == null ? void 0 : a.map((s) => {
|
|
191
|
-
var l, v, b, g, _, h, y,
|
|
194
|
+
var l, v, b, g, _, h, y, T;
|
|
192
195
|
return {
|
|
193
196
|
id: s == null ? void 0 : s.id,
|
|
194
197
|
src: (v = (l = s == null ? void 0 : s.media_formats) == null ? void 0 : l.gif) == null ? void 0 : v.url,
|
|
195
198
|
width: (_ = (g = (b = s == null ? void 0 : s.media_formats) == null ? void 0 : b.gif) == null ? void 0 : g.dims) == null ? void 0 : _[0],
|
|
196
|
-
height: (
|
|
199
|
+
height: (T = (y = (h = s == null ? void 0 : s.media_formats) == null ? void 0 : h.gif) == null ? void 0 : y.dims) == null ? void 0 : T[1]
|
|
197
200
|
};
|
|
198
201
|
});
|
|
199
202
|
}
|
|
@@ -202,13 +205,13 @@ async function de(e, t) {
|
|
|
202
205
|
const c = await (await fetch(
|
|
203
206
|
`https://tenor.googleapis.com/v2/search?key=${t}&q=${e}&limit=15`
|
|
204
207
|
)).json();
|
|
205
|
-
return (i = c == null ? void 0 : c.results) == null ? void 0 : i.map((
|
|
208
|
+
return (i = c == null ? void 0 : c.results) == null ? void 0 : i.map((r) => {
|
|
206
209
|
var a, s, l, v, b, g, _, h;
|
|
207
210
|
return {
|
|
208
|
-
id:
|
|
209
|
-
src: (s = (a =
|
|
210
|
-
width: (b = (v = (l =
|
|
211
|
-
height: (h = (_ = (g =
|
|
211
|
+
id: r == null ? void 0 : r.id,
|
|
212
|
+
src: (s = (a = r == null ? void 0 : r.media_formats) == null ? void 0 : a.gif) == null ? void 0 : s.url,
|
|
213
|
+
width: (b = (v = (l = r == null ? void 0 : r.media_formats) == null ? void 0 : l.gif) == null ? void 0 : v.dims) == null ? void 0 : b[0],
|
|
214
|
+
height: (h = (_ = (g = r == null ? void 0 : r.media_formats) == null ? void 0 : g.gif) == null ? void 0 : _.dims) == null ? void 0 : h[1]
|
|
212
215
|
};
|
|
213
216
|
});
|
|
214
217
|
}
|
|
@@ -218,19 +221,19 @@ function le(e, t) {
|
|
|
218
221
|
searchWord: async (i) => t ? e === "giphy" ? oe(i, t) : e === "tenor" ? de(i, t) : [] : []
|
|
219
222
|
};
|
|
220
223
|
}
|
|
221
|
-
function he({ selectImage: e, apiKey: t, provider:
|
|
222
|
-
const [i,
|
|
223
|
-
|
|
224
|
+
function he({ selectImage: e, apiKey: t, provider: n, children: c }) {
|
|
225
|
+
const [i, r] = G(!1), [a, s] = G([]), { editorDisabled: l } = D(), v = U(null), { searchTrending: b, searchWord: g } = le(n, t);
|
|
226
|
+
z(() => {
|
|
224
227
|
(async () => {
|
|
225
228
|
const h = await b();
|
|
226
229
|
s(h);
|
|
227
230
|
})();
|
|
228
231
|
}, []);
|
|
229
232
|
const _ = M(
|
|
230
|
-
|
|
233
|
+
X(async (h) => {
|
|
231
234
|
if (!h.target.value) {
|
|
232
|
-
const
|
|
233
|
-
s(
|
|
235
|
+
const T = await b();
|
|
236
|
+
s(T);
|
|
234
237
|
return;
|
|
235
238
|
}
|
|
236
239
|
const y = await g(h.target.value);
|
|
@@ -239,18 +242,18 @@ function he({ selectImage: e, apiKey: t, provider: r, children: c }) {
|
|
|
239
242
|
// Adjust the debounce delay as needed
|
|
240
243
|
[]
|
|
241
244
|
);
|
|
242
|
-
return /* @__PURE__ */
|
|
245
|
+
return /* @__PURE__ */ p(te, { modal: !0, onOpenChange: r, open: i, children: [
|
|
243
246
|
/* @__PURE__ */ u(re, { asChild: !0, disabled: l, children: c }),
|
|
244
247
|
/* @__PURE__ */ u(
|
|
245
|
-
|
|
248
|
+
ne,
|
|
246
249
|
{
|
|
247
250
|
align: "start",
|
|
248
251
|
className: "richtext-size-full richtext-p-2",
|
|
249
252
|
hideWhenDetached: !0,
|
|
250
253
|
side: "bottom",
|
|
251
|
-
children: t ? /* @__PURE__ */
|
|
254
|
+
children: t ? /* @__PURE__ */ p(Z, { children: [
|
|
252
255
|
/* @__PURE__ */ u("div", { className: "richtext-mb-[10px] richtext-w-full", children: /* @__PURE__ */ u(
|
|
253
|
-
|
|
256
|
+
ie,
|
|
254
257
|
{
|
|
255
258
|
onChange: _,
|
|
256
259
|
placeholder: "Search GIF",
|
|
@@ -265,7 +268,7 @@ function he({ selectImage: e, apiKey: t, provider: r, children: c }) {
|
|
|
265
268
|
className: "richtext-cursor-pointer richtext-object-contain richtext-text-center",
|
|
266
269
|
src: h.src,
|
|
267
270
|
onClick: () => {
|
|
268
|
-
e(h.src),
|
|
271
|
+
e(h.src), r(!1);
|
|
269
272
|
}
|
|
270
273
|
},
|
|
271
274
|
h.id
|
|
@@ -275,13 +278,13 @@ function he({ selectImage: e, apiKey: t, provider: r, children: c }) {
|
|
|
275
278
|
)
|
|
276
279
|
] });
|
|
277
280
|
}
|
|
278
|
-
function
|
|
279
|
-
const e =
|
|
280
|
-
return /* @__PURE__ */ u(he, { apiKey: i, provider:
|
|
281
|
+
function xe() {
|
|
282
|
+
const e = ee(ue.name), { action: t, icon: n, tooltip: c, apiKey: i, provider: r } = (e == null ? void 0 : e.componentProps) ?? {}, { editorDisabled: a } = D();
|
|
283
|
+
return /* @__PURE__ */ u(he, { apiKey: i, provider: r, selectImage: (l) => {
|
|
281
284
|
a || t && t(l);
|
|
282
|
-
}, children: /* @__PURE__ */ u(
|
|
285
|
+
}, children: /* @__PURE__ */ u(K, { disabled: a, icon: n, tooltip: c }) });
|
|
283
286
|
}
|
|
284
|
-
const ue = /* @__PURE__ */
|
|
287
|
+
const ue = /* @__PURE__ */ Y.extend({
|
|
285
288
|
name: "imageGif",
|
|
286
289
|
//@ts-expect-error
|
|
287
290
|
addOptions() {
|
|
@@ -297,9 +300,9 @@ const ue = /* @__PURE__ */ J.extend({
|
|
|
297
300
|
draggable: !1,
|
|
298
301
|
selectable: !0,
|
|
299
302
|
atom: !0,
|
|
300
|
-
button: ({ editor: t, extension:
|
|
303
|
+
button: ({ editor: t, extension: n, t: c }) => {
|
|
301
304
|
var a, s;
|
|
302
|
-
const i = ((a =
|
|
305
|
+
const i = ((a = n == null ? void 0 : n.options) == null ? void 0 : a.provider) || "", r = ((s = n == null ? void 0 : n.options) == null ? void 0 : s.API_KEY) || "";
|
|
303
306
|
return {
|
|
304
307
|
componentProps: {
|
|
305
308
|
action: (l) => {
|
|
@@ -309,7 +312,7 @@ const ue = /* @__PURE__ */ J.extend({
|
|
|
309
312
|
disabled: !1,
|
|
310
313
|
icon: "GifIcon",
|
|
311
314
|
tooltip: c("editor.imageGif.tooltip"),
|
|
312
|
-
apiKey:
|
|
315
|
+
apiKey: r,
|
|
313
316
|
provider: i
|
|
314
317
|
}
|
|
315
318
|
};
|
|
@@ -323,8 +326,8 @@ const ue = /* @__PURE__ */ J.extend({
|
|
|
323
326
|
width: {
|
|
324
327
|
default: null,
|
|
325
328
|
parseHTML: (t) => {
|
|
326
|
-
const
|
|
327
|
-
return
|
|
329
|
+
const n = t.style.width || t.getAttribute("width") || "10";
|
|
330
|
+
return n === void 0 ? null : Number.parseInt(`${n}`, 10);
|
|
328
331
|
},
|
|
329
332
|
renderHTML: (t) => ({
|
|
330
333
|
width: t.width
|
|
@@ -346,12 +349,12 @@ const ue = /* @__PURE__ */ J.extend({
|
|
|
346
349
|
var e;
|
|
347
350
|
return {
|
|
348
351
|
...(e = this.parent) == null ? void 0 : e.call(this),
|
|
349
|
-
setImageGif: (t) => ({ commands:
|
|
352
|
+
setImageGif: (t) => ({ commands: n }) => n.insertContent({
|
|
350
353
|
type: this.name,
|
|
351
354
|
attrs: t
|
|
352
355
|
}),
|
|
353
|
-
updateImageGif: (t) => ({ commands:
|
|
354
|
-
setAlignImageGif: (t) => ({ commands:
|
|
356
|
+
updateImageGif: (t) => ({ commands: n }) => n.updateAttributes(this.name, t),
|
|
357
|
+
setAlignImageGif: (t) => ({ commands: n }) => n.updateAttributes(this.name, { align: t })
|
|
355
358
|
};
|
|
356
359
|
},
|
|
357
360
|
renderHTML({ HTMLAttributes: e }) {
|
|
@@ -381,12 +384,12 @@ const ue = /* @__PURE__ */ J.extend({
|
|
|
381
384
|
{
|
|
382
385
|
tag: "div[class=imageGIf]",
|
|
383
386
|
getAttrs: (e) => {
|
|
384
|
-
const t = e.querySelector("img"),
|
|
387
|
+
const t = e.querySelector("img"), n = t == null ? void 0 : t.getAttribute("width");
|
|
385
388
|
return {
|
|
386
389
|
src: t == null ? void 0 : t.getAttribute("src"),
|
|
387
390
|
alt: t == null ? void 0 : t.getAttribute("alt"),
|
|
388
391
|
title: t == null ? void 0 : t.getAttribute("title"),
|
|
389
|
-
width:
|
|
392
|
+
width: n ? Number.parseInt(n, 10) : null,
|
|
390
393
|
align: (t == null ? void 0 : t.getAttribute("align")) || e.style.textAlign || null
|
|
391
394
|
};
|
|
392
395
|
}
|
|
@@ -396,5 +399,5 @@ const ue = /* @__PURE__ */ J.extend({
|
|
|
396
399
|
});
|
|
397
400
|
export {
|
|
398
401
|
ue as ImageGif,
|
|
399
|
-
|
|
402
|
+
xe as RichTextImageGif
|
|
400
403
|
};
|
package/lib/ImportWord.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("./clsx-CXbNJWDD.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("./clsx-CXbNJWDD.cjs"),l=require("react/jsx-runtime"),P=require("mammoth"),A=require("react"),H=require("./toggle-C9tcMm1r.cjs"),N=require("./ImageCropper-CY1ETEjC.cjs"),d=require("./useButtonProps-D9ndBdmA.cjs"),k=require("./index-DgOXAdKt.cjs"),z=require("./use-toast-C6zPo25l.cjs");function D(o,t){const s=atob(o.split(",")[1]),c=Array.from({length:s.length});for(let i=0;i<s.length;i++)c[i]=s.charCodeAt(i);const u=new Uint8Array(c);return new Blob([u],{type:t})}function K(o,t){return new File([o],t,{type:o.type})}function U(){const o=d.useEditorInstance(),t=d.useButtonProps(y.name),{icon:s=void 0,tooltip:c=void 0,tooltipOptions:u={},isActive:i=void 0,mammothOptions:q,limit:w,convert:b}=(t==null?void 0:t.componentProps)??{},{editorDisabled:j}=d.useToggleActive(i),p=d.useExtension(y.name),{toast:W}=z.useToast(),{t:S}=k.useLocale(),[B,v]=A.useState(!1),x=A.useRef(null);function C(){var e;(e=x.current)==null||e.click()}function O(e){const n=e.target.files[0];if(n){if(n.size>w){W({variant:"destructive",title:S("editor.importWord.limitSize")});return}E(n)}}async function R(e){const a=new DOMParser().parseFromString(e,"text/html"),f=a.querySelectorAll("img");if(f.length===0)return a.body.innerHTML;if(d.hasExtension(o,N.Image.name)){const g=p==null?void 0:p.options;if(g&&typeof g.upload=="function"){const T=[];for(const h of f){const m=h.getAttribute("src"),r=D(m,"image/jpeg"),L=K(r,"image.jpeg");T.push(L)}const F=await g.upload(T);for(const[h,m]of f.entries()){m.setAttribute("src",F[h].src);const r=m.parentElement;(r==null?void 0:r.tagName)==="P"&&(r.insertAdjacentElement("beforebegin",m),!r.hasChildNodes()&&r.textContent===""&&r.remove())}return a.body.innerHTML}else return console.warn("Image Upload method found, skip image conversion"),a.body.innerHTML}else return console.error("Image extension not found, unable to convert image"),a.body.innerHTML}async function E(e){v(!0);try{if(b){const n=await b(e);I(n)}else{const n=await e.arrayBuffer(),{value:a}=await P.convertToHtml({arrayBuffer:n},q);I(a)}}finally{v(!1)}}async function I(e){const n=await R(e);o.chain().setContent(n,!0).run()}return t?l.jsxs(l.Fragment,{children:[l.jsx(H.ActionButton,{action:C,disabled:j,icon:s,loading:B,tooltip:c,tooltipOptions:u}),l.jsx("input",{accept:".docx",onChange:O,ref:x,type:"file",style:{display:"none"}})]}):l.jsx(l.Fragment,{})}const y=M.Extension.create({name:"importWord",addOptions(){var o;return{...(o=this.parent)==null?void 0:o.call(this),upload:void 0,convert:void 0,limit:1024*1024*10,button:({extension:t,t:s})=>{const{convert:c,limit:u,mammothOptions:i}=t.options;return{componentProps:{convert:c,limit:u,mammothOptions:i,icon:"Word",shortcutKeys:t.options.shortcutKeys??["alt","mod","S"],tooltip:s("editor.importWord.tooltip")}}}}}});exports.ImportWord=y;exports.RichTextImportWord=U;
|
package/lib/ImportWord.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { E as M } from "./clsx-
|
|
2
|
-
import { jsx as g, Fragment as
|
|
1
|
+
import { E as M } from "./clsx-m_C5j3RU.js";
|
|
2
|
+
import { jsx as g, Fragment as I, jsxs as P } from "react/jsx-runtime";
|
|
3
3
|
import R from "mammoth";
|
|
4
4
|
import { useState as N, useRef as k } from "react";
|
|
5
|
-
import {
|
|
6
|
-
import "./
|
|
7
|
-
import { u as
|
|
5
|
+
import { A as z } from "./toggle-CaSwYCk4.js";
|
|
6
|
+
import { I as D } from "./ImageCropper-DrSdjo9x.js";
|
|
7
|
+
import { f as K, u as U, c as q, i as G, j as J } from "./useButtonProps-D-ruygH7.js";
|
|
8
|
+
import { u as Q } from "./index-BGd2HiwP.js";
|
|
9
|
+
import { u as V } from "./use-toast-CEOqhXfx.js";
|
|
8
10
|
function X(e, t) {
|
|
9
11
|
const s = atob(e.split(",")[1]), c = Array.from({ length: s.length });
|
|
10
12
|
for (let i = 0; i < s.length; i++)
|
|
@@ -15,48 +17,48 @@ function X(e, t) {
|
|
|
15
17
|
function Y(e, t) {
|
|
16
18
|
return new File([e], t, { type: e.type });
|
|
17
19
|
}
|
|
18
|
-
function
|
|
19
|
-
const e =
|
|
20
|
+
function at() {
|
|
21
|
+
const e = K(), t = U(w.name), {
|
|
20
22
|
icon: s = void 0,
|
|
21
23
|
tooltip: c = void 0,
|
|
22
24
|
tooltipOptions: l = {},
|
|
23
25
|
isActive: i = void 0,
|
|
24
|
-
mammothOptions:
|
|
25
|
-
limit:
|
|
26
|
+
mammothOptions: T,
|
|
27
|
+
limit: x,
|
|
26
28
|
convert: h
|
|
27
|
-
} = (t == null ? void 0 : t.componentProps) ?? {}, { editorDisabled: C } =
|
|
28
|
-
function
|
|
29
|
+
} = (t == null ? void 0 : t.componentProps) ?? {}, { editorDisabled: C } = q(i), u = G(w.name), { toast: E } = V(), { t: W } = Q(), [j, y] = N(!1), b = k(null);
|
|
30
|
+
function B() {
|
|
29
31
|
var o;
|
|
30
32
|
(o = b.current) == null || o.click();
|
|
31
33
|
}
|
|
32
|
-
function
|
|
34
|
+
function L(o) {
|
|
33
35
|
const n = o.target.files[0];
|
|
34
36
|
if (n) {
|
|
35
|
-
if (n.size >
|
|
37
|
+
if (n.size > x) {
|
|
36
38
|
E({
|
|
37
39
|
variant: "destructive",
|
|
38
40
|
title: W("editor.importWord.limitSize")
|
|
39
41
|
});
|
|
40
42
|
return;
|
|
41
43
|
}
|
|
42
|
-
|
|
44
|
+
S(n);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
|
-
async function
|
|
47
|
+
async function O(o) {
|
|
46
48
|
const a = new DOMParser().parseFromString(o, "text/html"), p = a.querySelectorAll("img");
|
|
47
49
|
if (p.length === 0)
|
|
48
50
|
return a.body.innerHTML;
|
|
49
|
-
if (J(e,
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
51
|
+
if (J(e, D.name)) {
|
|
52
|
+
const f = u == null ? void 0 : u.options;
|
|
53
|
+
if (f && typeof f.upload == "function") {
|
|
52
54
|
const A = [];
|
|
53
|
-
for (const
|
|
54
|
-
const m =
|
|
55
|
+
for (const d of p) {
|
|
56
|
+
const m = d.getAttribute("src"), r = X(m, "image/jpeg"), H = Y(r, "image.jpeg");
|
|
55
57
|
A.push(H);
|
|
56
58
|
}
|
|
57
|
-
const F = await
|
|
58
|
-
for (const [
|
|
59
|
-
m.setAttribute("src", F[
|
|
59
|
+
const F = await f.upload(A);
|
|
60
|
+
for (const [d, m] of p.entries()) {
|
|
61
|
+
m.setAttribute("src", F[d].src);
|
|
60
62
|
const r = m.parentElement;
|
|
61
63
|
(r == null ? void 0 : r.tagName) === "P" && (r.insertAdjacentElement("beforebegin", m), !r.hasChildNodes() && r.textContent === "" && r.remove());
|
|
62
64
|
}
|
|
@@ -66,14 +68,14 @@ function it() {
|
|
|
66
68
|
} else
|
|
67
69
|
return console.error("Image extension not found, unable to convert image"), a.body.innerHTML;
|
|
68
70
|
}
|
|
69
|
-
async function
|
|
71
|
+
async function S(o) {
|
|
70
72
|
y(!0);
|
|
71
73
|
try {
|
|
72
74
|
if (h) {
|
|
73
75
|
const n = await h(o);
|
|
74
76
|
v(n);
|
|
75
77
|
} else {
|
|
76
|
-
const n = await o.arrayBuffer(), { value: a } = await R.convertToHtml({ arrayBuffer: n },
|
|
78
|
+
const n = await o.arrayBuffer(), { value: a } = await R.convertToHtml({ arrayBuffer: n }, T);
|
|
77
79
|
v(a);
|
|
78
80
|
}
|
|
79
81
|
} finally {
|
|
@@ -81,17 +83,17 @@ function it() {
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
async function v(o) {
|
|
84
|
-
const n = await
|
|
86
|
+
const n = await O(o);
|
|
85
87
|
e.chain().setContent(n, !0).run();
|
|
86
88
|
}
|
|
87
|
-
return t ? /* @__PURE__ */ P(
|
|
89
|
+
return t ? /* @__PURE__ */ P(I, { children: [
|
|
88
90
|
/* @__PURE__ */ g(
|
|
89
|
-
|
|
91
|
+
z,
|
|
90
92
|
{
|
|
91
|
-
action:
|
|
93
|
+
action: B,
|
|
92
94
|
disabled: C,
|
|
93
95
|
icon: s,
|
|
94
|
-
loading:
|
|
96
|
+
loading: j,
|
|
95
97
|
tooltip: c,
|
|
96
98
|
tooltipOptions: l
|
|
97
99
|
}
|
|
@@ -100,7 +102,7 @@ function it() {
|
|
|
100
102
|
"input",
|
|
101
103
|
{
|
|
102
104
|
accept: ".docx",
|
|
103
|
-
onChange:
|
|
105
|
+
onChange: L,
|
|
104
106
|
ref: b,
|
|
105
107
|
type: "file",
|
|
106
108
|
style: {
|
|
@@ -108,9 +110,9 @@ function it() {
|
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
)
|
|
111
|
-
] }) : /* @__PURE__ */ g(
|
|
113
|
+
] }) : /* @__PURE__ */ g(I, {});
|
|
112
114
|
}
|
|
113
|
-
const
|
|
115
|
+
const w = /* @__PURE__ */ M.create({
|
|
114
116
|
name: "importWord",
|
|
115
117
|
//@ts-expect-error
|
|
116
118
|
addOptions() {
|
|
@@ -140,6 +142,6 @@ const I = /* @__PURE__ */ M.create({
|
|
|
140
142
|
}
|
|
141
143
|
});
|
|
142
144
|
export {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
w as ImportWord,
|
|
146
|
+
at as RichTextImportWord
|
|
145
147
|
};
|