@remarkablejames/editor 0.0.7 → 0.0.9

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