@remarkablejames/editor 0.0.5 → 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.
Files changed (194) hide show
  1. package/README.md +1 -1
  2. package/lib/ActionMenuButton-D9o3Kwmv.cjs +1 -0
  3. package/lib/{ActionMenuButton-DBZjUu-F.js → ActionMenuButton-nxV91Fqo.js} +10 -9
  4. package/lib/Attachment.cjs +19 -1
  5. package/lib/Attachment.js +270 -7
  6. package/lib/Blockquote.cjs +2 -2
  7. package/lib/Blockquote.js +12 -13
  8. package/lib/Bold.cjs +1 -1
  9. package/lib/Bold.js +10 -11
  10. package/lib/BulletList.cjs +1 -1
  11. package/lib/BulletList.js +8 -9
  12. package/lib/Callout.cjs +1 -1
  13. package/lib/Callout.js +45 -41
  14. package/lib/Clear.cjs +1 -1
  15. package/lib/Clear.js +14 -13
  16. package/lib/Code.cjs +1 -1
  17. package/lib/Code.js +5 -6
  18. package/lib/CodeBlock.cjs +1 -1
  19. package/lib/CodeBlock.js +31 -30
  20. package/lib/CodeView.cjs +1 -1
  21. package/lib/CodeView.js +8 -9
  22. package/lib/Color.cjs +1 -1
  23. package/lib/Color.js +19 -18
  24. package/lib/Column.cjs +1 -1
  25. package/lib/Column.js +8 -9
  26. package/lib/Drawer-Bh-y5bs8.cjs +2 -0
  27. package/lib/{Drawer-DTCwtJEs.js → Drawer-CF6Z_IA2.js} +24 -18
  28. package/lib/Drawer.cjs +1 -1
  29. package/lib/Drawer.js +3 -3
  30. package/lib/Emoji.cjs +1 -1
  31. package/lib/Emoji.js +15 -14
  32. package/lib/Excalidraw.cjs +1 -1
  33. package/lib/Excalidraw.js +33 -28
  34. package/lib/ExportPdf.cjs +3 -3
  35. package/lib/ExportPdf.js +13 -14
  36. package/lib/ExportWord.cjs +1 -1
  37. package/lib/ExportWord.js +6 -6
  38. package/lib/FontFamily.cjs +1 -1
  39. package/lib/FontFamily.js +6 -7
  40. package/lib/FontSize.cjs +1 -1
  41. package/lib/FontSize.js +14 -15
  42. package/lib/Heading.cjs +1 -1
  43. package/lib/Heading.js +26 -26
  44. package/lib/Highlight.cjs +1 -1
  45. package/lib/Highlight.js +23 -22
  46. package/lib/History.cjs +1 -1
  47. package/lib/History.js +11 -11
  48. package/lib/HorizontalRule.cjs +1 -1
  49. package/lib/HorizontalRule.js +9 -10
  50. package/lib/Icon-BvGyfX2j.js +15 -0
  51. package/lib/Icon-wjwoRc9F.cjs +1 -0
  52. package/lib/Iframe-BbfZKbPY.cjs +1 -0
  53. package/lib/{Iframe-D-UYBxiv.js → Iframe-Dfd3LI7b.js} +18 -15
  54. package/lib/Iframe.cjs +1 -1
  55. package/lib/Iframe.js +3 -3
  56. package/lib/Image.cjs +1 -1
  57. package/lib/Image.js +5 -4
  58. package/lib/ImageCropper-CY1ETEjC.cjs +10 -0
  59. package/lib/ImageCropper-DrSdjo9x.js +979 -0
  60. package/lib/ImageGif.cjs +1 -1
  61. package/lib/ImageGif.js +80 -77
  62. package/lib/ImportWord.cjs +1 -1
  63. package/lib/ImportWord.js +28 -26
  64. package/lib/{Indent-Bvt-Qwar.js → Indent-CDVF9DWN.js} +30 -31
  65. package/lib/Indent-Q1VuhSM2.cjs +1 -0
  66. package/lib/Indent.cjs +1 -1
  67. package/lib/Indent.js +2 -2
  68. package/lib/Italic.cjs +1 -1
  69. package/lib/Italic.js +11 -12
  70. package/lib/{Katex-CJDtvu-v.js → Katex-DqhWWAA-.js} +22 -19
  71. package/lib/Katex-K1QU2SB2.cjs +4 -0
  72. package/lib/Katex.cjs +1 -1
  73. package/lib/Katex.js +2 -2
  74. package/lib/LineHeight.cjs +1 -1
  75. package/lib/LineHeight.js +20 -19
  76. package/lib/Link.cjs +1 -1
  77. package/lib/Link.js +2 -2
  78. package/lib/LinkEditBlock-CBYGLs3J.cjs +5 -0
  79. package/lib/{LinkEditBlock-Cdqwj_NU.js → LinkEditBlock-xP0pGVhB.js} +24 -19
  80. package/lib/Mention.js +3 -3
  81. package/lib/{Mermaid-CnMYVX1P.js → Mermaid-BJ6ryVdY.js} +48 -45
  82. package/lib/Mermaid-D3_nLeOW.cjs +2 -0
  83. package/lib/Mermaid.cjs +1 -1
  84. package/lib/Mermaid.js +2 -2
  85. package/lib/MoreMark.cjs +1 -1
  86. package/lib/MoreMark.js +28 -26
  87. package/lib/OrderedList.cjs +1 -1
  88. package/lib/OrderedList.js +10 -11
  89. package/lib/PaywallSeparator.cjs +1 -0
  90. package/lib/PaywallSeparator.js +140 -0
  91. package/lib/SearchAndReplace.cjs +1 -1
  92. package/lib/SearchAndReplace.js +42 -37
  93. package/lib/SlashCommand.cjs +1 -1
  94. package/lib/SlashCommand.js +5 -5
  95. package/lib/SlashCommandNodeView-CUJrDQS7.cjs +1 -0
  96. package/lib/{SlashCommandNodeView-DcoLvt_6.js → SlashCommandNodeView-DS9FqMiY.js} +80 -62
  97. package/lib/Strike.cjs +1 -1
  98. package/lib/Strike.js +11 -12
  99. package/lib/Table-CV6pUoVf.cjs +5 -0
  100. package/lib/{Table-Cu12PvQ_.js → Table-CcG-JNtV.js} +46 -46
  101. package/lib/Table.cjs +1 -1
  102. package/lib/Table.js +1 -1
  103. package/lib/TaskList.cjs +1 -1
  104. package/lib/TaskList.js +11 -12
  105. package/lib/TextAlign.cjs +1 -1
  106. package/lib/TextAlign.js +27 -26
  107. package/lib/TextDirection.cjs +1 -1
  108. package/lib/TextDirection.js +19 -18
  109. package/lib/TextUnderline.cjs +1 -1
  110. package/lib/TextUnderline.js +8 -9
  111. package/lib/{Twitter-CrX4XY1j.js → Twitter-BIL3o833.js} +22 -18
  112. package/lib/Twitter-BfSTqPDh.cjs +1 -0
  113. package/lib/Twitter.cjs +1 -1
  114. package/lib/Twitter.js +2 -2
  115. package/lib/Video-DAKr90QL.js +231 -0
  116. package/lib/Video-HAinT0w6.cjs +1 -0
  117. package/lib/Video.cjs +1 -1
  118. package/lib/Video.js +5 -4
  119. package/lib/bubble.cjs +3 -3
  120. package/lib/bubble.js +86 -77
  121. package/lib/button-090-I3tp.js +35 -0
  122. package/lib/button-B4Sz2ZhW.cjs +1 -0
  123. package/lib/checkbox-BCPsu7yR.cjs +1 -0
  124. package/lib/checkbox-DiXWHAI0.js +29 -0
  125. package/lib/{clsx-BUPZHhq3.js → clsx-m_C5j3RU.js} +24 -24
  126. package/lib/components/RichTextProvider.d.ts +1 -1
  127. package/lib/dialog-C8J59d2J.cjs +1 -0
  128. package/lib/dialog-bDkDW-C_.js +95 -0
  129. package/lib/dom-dataset-BqoJhJXt.cjs +1 -0
  130. package/lib/dom-dataset-CIEeltF6.js +47 -0
  131. package/lib/{dropdown-menu-CVwXaR3Z.js → dropdown-menu-DWt_xj4h.js} +1 -1
  132. package/lib/{dropdown-menu-XIrQk3jr.cjs → dropdown-menu-tUP872Zv.cjs} +1 -1
  133. package/lib/events.constant-Bke62qxm.cjs +1 -0
  134. package/lib/events.constant-CSWD3-ho.js +72 -0
  135. package/lib/extensions/PaywallSeparator/PaywallSeparator.d.ts +35 -0
  136. package/lib/extensions/PaywallSeparator/components/PaywallIcon.d.ts +2 -0
  137. package/lib/extensions/PaywallSeparator/components/PaywallSeparatorView.d.ts +17 -0
  138. package/lib/extensions/PaywallSeparator/components/RichTextPaywallSeparator.d.ts +1 -0
  139. package/lib/extensions/PaywallSeparator/components/index.d.ts +2 -0
  140. package/lib/extensions/PaywallSeparator/index.d.ts +1 -0
  141. package/lib/file-i7e4nQY2.cjs +1 -0
  142. package/lib/file-jDdkhyj7.js +43 -0
  143. package/lib/{index-RkKGy5oa.js → index-B3Ijnbxs.js} +1 -1
  144. package/lib/index-BXh8X1ch.cjs +1 -0
  145. package/lib/{index-Dl3OjzmR.js → index-C1KQsOcg.js} +1 -1
  146. package/lib/{index-D4M4hrH4.js → index-C8FjP66D.js} +1 -1
  147. package/lib/index-jMN4V2hr.js +2763 -0
  148. package/lib/{index-DZj2z9_1.js → index-s3l5RdyW.js} +1 -1
  149. package/lib/index.cjs +4 -4
  150. package/lib/index.js +464 -149
  151. package/lib/input-C_J-pfTx.js +21 -0
  152. package/lib/input-DwLo4r7V.cjs +1 -0
  153. package/lib/isNumber-BTYSVlKo.cjs +1 -0
  154. package/lib/isNumber-WaBzl_0s.js +15 -0
  155. package/lib/label-BgIVynq3.cjs +1 -0
  156. package/lib/label-ClsOg9Hr.js +11 -0
  157. package/lib/{popover-DDT8YRht.js → popover-BC7FRr8B.js} +1 -1
  158. package/lib/{popover-0syCfWYi.cjs → popover-C3A6zzNV.cjs} +1 -1
  159. package/lib/{renderNodeView-dj6AaFSX.js → renderNodeView-C_hPIdEs.js} +2 -2
  160. package/lib/{select-DTNz0ZeE.cjs → select-B8HIWDXf.cjs} +1 -1
  161. package/lib/{select-D9wQw2qB.js → select-DSKqhVGR.js} +1 -1
  162. package/lib/{separator-DRGTEiX4.js → separator-BJWSNjvr.js} +13 -12
  163. package/lib/separator-D6ruF682.cjs +1 -0
  164. package/lib/style.css +1 -1
  165. package/lib/tabs-D1J1iB7B.js +46 -0
  166. package/lib/tabs-IEbMQmNX.cjs +1 -0
  167. package/lib/{textarea-DfVzbMr5.js → textarea-Ch5w3PiI.js} +1 -1
  168. package/lib/{textarea-DpkwluT0.cjs → textarea-CtVdqwSM.cjs} +1 -1
  169. package/lib/theme.cjs +1 -1
  170. package/lib/theme.js +18 -18
  171. package/lib/throttle-CRNq0z-O.js +249 -0
  172. package/lib/throttle-gTTvqDTW.cjs +1 -0
  173. package/lib/toggle-C9tcMm1r.cjs +1 -0
  174. package/lib/toggle-CaSwYCk4.js +89 -0
  175. package/lib/types.d.ts +5 -5
  176. package/lib/{updatePosition-C294Pixi.js → updatePosition-DvfTZHcH.js} +2 -2
  177. package/lib/use-toast-C6zPo25l.cjs +1 -0
  178. package/lib/use-toast-CEOqhXfx.js +97 -0
  179. package/lib/useButtonProps-D-ruygH7.js +165 -0
  180. package/lib/useButtonProps-D9ndBdmA.cjs +1 -0
  181. package/package.json +34 -32
  182. package/lib/ActionMenuButton-C6jGtl3k.cjs +0 -1
  183. package/lib/Drawer-B031ezmA.cjs +0 -2
  184. package/lib/Iframe-BUK2pkOL.cjs +0 -1
  185. package/lib/Indent-_y6N8MIQ.cjs +0 -1
  186. package/lib/Katex-bJXkt-VP.cjs +0 -4
  187. package/lib/LinkEditBlock-ewTApx0K.cjs +0 -5
  188. package/lib/Mermaid-Dwz9o-yM.cjs +0 -2
  189. package/lib/SlashCommandNodeView-BMgQJ4xT.cjs +0 -1
  190. package/lib/Table-B8CHl8jK.cjs +0 -5
  191. package/lib/Twitter-6HYP_upt.cjs +0 -1
  192. package/lib/index-B0d-u29p.js +0 -5425
  193. package/lib/index-De9MZVWQ.cjs +0 -28
  194. package/lib/separator-D8lOAf8f.cjs +0 -1
package/lib/ImageGif.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./clsx-CXbNJWDD.cjs"),f=require("./index-De9MZVWQ.cjs"),l=require("react/jsx-runtime"),u=require("react"),j=require("./index-DgOXAdKt.cjs");require("./theme.cjs");const L=require("./popover-0syCfWYi.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;
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-BUPZHhq3.js";
2
- import { G as k, H as C, J as X, u as Y, d as D, A as Z, K as J, j as U, M as Q } from "./index-B0d-u29p.js";
3
- import { jsx as u, jsxs as z, Fragment as K } from "react/jsx-runtime";
4
- import { useState as G, useMemo as P, useCallback as M, 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-DDT8YRht.js";
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 p, H;
16
- const [t, r] = G({
17
- width: j,
18
- height: j
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
- }), [n] = G([
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 } = (p = e == null ? void 0 : e.node) == null ? void 0 : p.attrs, g = P(() => {
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 = k(f) ? `${f}px` : f, d = k(x) ? `${x}px` : x;
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
- }, [(H = e == null ? void 0 : e.node) == null ? void 0 : H.attrs]), _ = P(() => {
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 I = M(
61
- C(() => {
63
+ const T = M(
64
+ H(() => {
62
65
  const { editor: o } = e, { width: m } = getComputedStyle(o.view.dom);
63
- r((f) => ({
66
+ n((f) => ({
64
67
  ...f,
65
68
  width: Number.parseInt(m, 10)
66
69
  }));
67
- }, W),
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 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({
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
- C((o) => {
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 = X(f + A, te, t.width);
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
- }, W),
95
+ }, j),
93
96
  [a, l, t, e.updateAttributes]
94
97
  ), E = M(
95
98
  (o) => {
@@ -102,23 +105,23 @@ function ae(e) {
102
105
  }), s(!1), y());
103
106
  },
104
107
  [a, y]
105
- ), R = M(() => {
108
+ ), $ = M(() => {
106
109
  document == null || document.addEventListener("mousemove", N, !0), document == null || document.addEventListener("mouseup", E, !0);
107
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
- $(() => (a ? R() : S(), () => {
113
+ z(() => (a ? $() : S(), () => {
111
114
  S();
112
- }), [a, R, S]);
113
- const L = P(() => new ResizeObserver(() => I()), [I]);
114
- return $(() => (L.observe(e.editor.view.dom), () => {
115
+ }), [a, $, S]);
116
+ const L = P(() => new ResizeObserver(() => T()), [T]);
117
+ return z(() => (L.observe(e.editor.view.dom), () => {
115
118
  L.disconnect();
116
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__ */ z(
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: n == null ? void 0 : n.map((o) => /* @__PURE__ */ u(
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 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;
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: (n = i == null ? void 0 : i.images.original) == null ? void 0 : n.url,
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((n) => {
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: 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)
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 n, a;
187
+ var r, a;
185
188
  const t = await fetch(
186
189
  `https://tenor.googleapis.com/v2/trending_terms?key=${e}&limit=10`
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`
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, I;
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: (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]
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((n) => {
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: 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]
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: r, children: c }) {
222
- const [i, n] = G(!1), [a, s] = G([]), { editorDisabled: l } = D(), v = ee(null), { searchTrending: b, searchWord: g } = le(r, t);
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
- J(async (h) => {
233
+ X(async (h) => {
231
234
  if (!h.target.value) {
232
- const I = await b();
233
- s(I);
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__ */ z(ne, { modal: !0, onOpenChange: n, open: i, children: [
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
- ie,
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__ */ z(K, { children: [
254
+ children: t ? /* @__PURE__ */ p(Z, { children: [
252
255
  /* @__PURE__ */ u("div", { className: "richtext-mb-[10px] richtext-w-full", children: /* @__PURE__ */ u(
253
- U,
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), n(!1);
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 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) => {
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(Z, { disabled: a, icon: r, tooltip: c }) });
285
+ }, children: /* @__PURE__ */ u(K, { disabled: a, icon: n, tooltip: c }) });
283
286
  }
284
- const ue = /* @__PURE__ */ Q.extend({
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__ */ Q.extend({
297
300
  draggable: !1,
298
301
  selectable: !0,
299
302
  atom: !0,
300
- button: ({ editor: t, extension: r, t: c }) => {
303
+ button: ({ editor: t, extension: n, t: c }) => {
301
304
  var a, s;
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) || "";
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__ */ Q.extend({
309
312
  disabled: !1,
310
313
  icon: "GifIcon",
311
314
  tooltip: c("editor.imageGif.tooltip"),
312
- apiKey: n,
315
+ apiKey: r,
313
316
  provider: i
314
317
  }
315
318
  };
@@ -323,8 +326,8 @@ const ue = /* @__PURE__ */ Q.extend({
323
326
  width: {
324
327
  default: null,
325
328
  parseHTML: (t) => {
326
- const r = t.style.width || t.getAttribute("width") || "10";
327
- return r === void 0 ? null : Number.parseInt(`${r}`, 10);
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__ */ Q.extend({
346
349
  var e;
347
350
  return {
348
351
  ...(e = this.parent) == null ? void 0 : e.call(this),
349
- setImageGif: (t) => ({ commands: r }) => r.insertContent({
352
+ setImageGif: (t) => ({ commands: n }) => n.insertContent({
350
353
  type: this.name,
351
354
  attrs: t
352
355
  }),
353
- updateImageGif: (t) => ({ commands: r }) => r.updateAttributes(this.name, t),
354
- setAlignImageGif: (t) => ({ commands: r }) => r.updateAttributes(this.name, { align: t })
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__ */ Q.extend({
381
384
  {
382
385
  tag: "div[class=imageGIf]",
383
386
  getAttrs: (e) => {
384
- const t = e.querySelector("img"), r = t == null ? void 0 : t.getAttribute("width");
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: r ? Number.parseInt(r, 10) : null,
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__ */ Q.extend({
396
399
  });
397
400
  export {
398
401
  ue as ImageGif,
399
- ye as RichTextImageGif
402
+ xe as RichTextImageGif
400
403
  };
@@ -1 +1 @@
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-De9MZVWQ.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;
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-BUPZHhq3.js";
1
+ import { E as M } from "./clsx-m_C5j3RU.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 { 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-B0d-u29p.js";
6
- import "./theme.js";
7
- import { u as V } from "./index-BGd2HiwP.js";
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,8 +17,8 @@ function X(e, t) {
15
17
  function Y(e, t) {
16
18
  return new File([e], t, { type: e.type });
17
19
  }
18
- function it() {
19
- const e = q(), t = z(w.name), {
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 = {},
@@ -24,12 +26,12 @@ function it() {
24
26
  mammothOptions: T,
25
27
  limit: x,
26
28
  convert: h
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() {
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 O(o) {
34
+ function L(o) {
33
35
  const n = o.target.files[0];
34
36
  if (n) {
35
37
  if (n.size > x) {
@@ -39,24 +41,24 @@ function it() {
39
41
  });
40
42
  return;
41
43
  }
42
- j(n);
44
+ S(n);
43
45
  }
44
46
  }
45
- async function S(o) {
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, Q.name)) {
50
- const d = u == null ? void 0 : u.options;
51
- if (d && typeof d.upload == "function") {
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 f of p) {
54
- const m = f.getAttribute("src"), r = X(m, "image/jpeg"), H = Y(r, "image.jpeg");
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 d.upload(A);
58
- for (const [f, m] of p.entries()) {
59
- m.setAttribute("src", F[f].src);
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,7 +68,7 @@ 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 j(o) {
71
+ async function S(o) {
70
72
  y(!0);
71
73
  try {
72
74
  if (h) {
@@ -81,17 +83,17 @@ function it() {
81
83
  }
82
84
  }
83
85
  async function v(o) {
84
- const n = await S(o);
86
+ const n = await O(o);
85
87
  e.chain().setContent(n, !0).run();
86
88
  }
87
89
  return t ? /* @__PURE__ */ P(I, { children: [
88
90
  /* @__PURE__ */ g(
89
- G,
91
+ z,
90
92
  {
91
- action: L,
93
+ action: B,
92
94
  disabled: C,
93
95
  icon: s,
94
- loading: B,
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: O,
105
+ onChange: L,
104
106
  ref: b,
105
107
  type: "file",
106
108
  style: {
@@ -141,5 +143,5 @@ const w = /* @__PURE__ */ M.create({
141
143
  });
142
144
  export {
143
145
  w as ImportWord,
144
- it as RichTextImportWord
146
+ at as RichTextImportWord
145
147
  };