@remarkablejames/editor 0.0.1 → 0.0.2

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 (178) hide show
  1. package/lib/{ActionMenuButton-B0EHT9CC.js → ActionMenuButton-Bmn3RME4.js} +10 -9
  2. package/lib/ActionMenuButton-C5P0Kzrb.cjs +1 -0
  3. package/lib/Attachment.cjs +2 -2
  4. package/lib/Attachment.js +33 -31
  5. package/lib/Blockquote.cjs +2 -2
  6. package/lib/Blockquote.js +12 -13
  7. package/lib/Bold.cjs +1 -1
  8. package/lib/Bold.js +10 -11
  9. package/lib/BulletList.cjs +1 -1
  10. package/lib/BulletList.js +8 -9
  11. package/lib/Callout.cjs +1 -1
  12. package/lib/Callout.js +45 -41
  13. package/lib/Clear.cjs +1 -1
  14. package/lib/Clear.js +14 -13
  15. package/lib/Code.cjs +1 -1
  16. package/lib/Code.js +5 -6
  17. package/lib/CodeBlock.cjs +1 -44
  18. package/lib/CodeBlock.js +183 -3858
  19. package/lib/CodeView.cjs +1 -1
  20. package/lib/CodeView.js +8 -9
  21. package/lib/Color.cjs +1 -1
  22. package/lib/Color.js +19 -18
  23. package/lib/Column.cjs +1 -1
  24. package/lib/Column.js +8 -9
  25. package/lib/{Drawer-BCWVN-4l.js → Drawer-DvGh9aXG.js} +52 -46
  26. package/lib/Drawer-gz9U5ArC.cjs +2 -0
  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 +15 -14
  31. package/lib/Excalidraw.cjs +1 -1
  32. package/lib/Excalidraw.js +20 -16
  33. package/lib/ExportPdf.cjs +3 -3
  34. package/lib/ExportPdf.js +13 -14
  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 +6 -7
  39. package/lib/FontSize.cjs +1 -1
  40. package/lib/FontSize.js +14 -15
  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 +23 -22
  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 +9 -10
  49. package/lib/Icon-CKM0tYbW.js +15 -0
  50. package/lib/Icon-CQyFgXeo.cjs +1 -0
  51. package/lib/{Iframe-BdgiWGml.js → Iframe-CnnvV6cK.js} +21 -19
  52. package/lib/Iframe-Ds6gG2YO.cjs +1 -0
  53. package/lib/Iframe.cjs +1 -1
  54. package/lib/Iframe.js +2 -2
  55. package/lib/Image.cjs +1 -1
  56. package/lib/Image.js +5 -4
  57. package/lib/ImageCropper-BKhXlnXN.cjs +1 -0
  58. package/lib/ImageCropper-DUzu_9-6.js +896 -0
  59. package/lib/ImageGif.cjs +1 -1
  60. package/lib/ImageGif.js +94 -91
  61. package/lib/ImportWord.cjs +1 -1
  62. package/lib/ImportWord.js +26 -25
  63. package/lib/{Indent-BpMcZKok.js → Indent-Bsj8gKvT.js} +30 -31
  64. package/lib/Indent-D_7HOYYd.cjs +1 -0
  65. package/lib/Indent.cjs +1 -1
  66. package/lib/Indent.js +2 -2
  67. package/lib/Italic.cjs +1 -1
  68. package/lib/Italic.js +11 -12
  69. package/lib/{Katex-B8_uprkO.js → Katex-CilGTz7u.js} +22 -19
  70. package/lib/Katex-lL3bHXJd.cjs +4 -0
  71. package/lib/Katex.cjs +1 -1
  72. package/lib/Katex.js +2 -2
  73. package/lib/LineHeight.cjs +1 -1
  74. package/lib/LineHeight.js +20 -19
  75. package/lib/Link.cjs +1 -1
  76. package/lib/Link.js +2 -2
  77. package/lib/{LinkEditBlock-BX0fXXpF.js → LinkEditBlock-BD_WvA3r.js} +24 -19
  78. package/lib/LinkEditBlock-D3HSHmsU.cjs +5 -0
  79. package/lib/Mention.js +3 -3
  80. package/lib/Mermaid-BfeLPzoS.cjs +2 -0
  81. package/lib/{Mermaid-D8bbIgAl.js → Mermaid-BrjU75Bs.js} +48 -45
  82. package/lib/Mermaid.cjs +1 -1
  83. package/lib/Mermaid.js +2 -2
  84. package/lib/MoreMark.cjs +1 -1
  85. package/lib/MoreMark.js +28 -26
  86. package/lib/OrderedList.cjs +1 -1
  87. package/lib/OrderedList.js +10 -11
  88. package/lib/SearchAndReplace.cjs +1 -1
  89. package/lib/SearchAndReplace.js +42 -37
  90. package/lib/SlashCommand.cjs +1 -1
  91. package/lib/SlashCommand.js +5 -5
  92. package/lib/{SlashCommandNodeView-BcmtKbEE.js → SlashCommandNodeView-COx5qZ2y.js} +41 -39
  93. package/lib/SlashCommandNodeView-DD-nlhM-.cjs +1 -0
  94. package/lib/Strike.cjs +1 -1
  95. package/lib/Strike.js +11 -12
  96. package/lib/{Table-DbxuP5xh.js → Table-BlM8yMhr.js} +46 -46
  97. package/lib/Table-C21AlUrh.cjs +5 -0
  98. package/lib/Table.cjs +1 -1
  99. package/lib/Table.js +1 -1
  100. package/lib/TaskList.cjs +1 -1
  101. package/lib/TaskList.js +11 -12
  102. package/lib/TextAlign.cjs +1 -1
  103. package/lib/TextAlign.js +27 -26
  104. package/lib/TextDirection.cjs +1 -1
  105. package/lib/TextDirection.js +19 -18
  106. package/lib/TextUnderline.cjs +1 -1
  107. package/lib/TextUnderline.js +8 -9
  108. package/lib/{Twitter-9I6BLNmg.js → Twitter-BP8sYXX7.js} +22 -18
  109. package/lib/Twitter-D46MnvPr.cjs +1 -0
  110. package/lib/Twitter.cjs +1 -1
  111. package/lib/Twitter.js +2 -2
  112. package/lib/Video-Bpd8W8l6.js +231 -0
  113. package/lib/Video-BwrHx6B1.cjs +1 -0
  114. package/lib/Video.cjs +1 -1
  115. package/lib/Video.js +5 -4
  116. package/lib/bubble.cjs +3 -3
  117. package/lib/bubble.js +171 -162
  118. package/lib/button-BmTP96NR.cjs +1 -0
  119. package/lib/button-CDIxPURh.js +35 -0
  120. package/lib/checkbox-7sfSdzy9.js +29 -0
  121. package/lib/checkbox-DyVlLWHv.cjs +1 -0
  122. package/lib/{clsx-CDyrfCnw.js → clsx-m_C5j3RU.js} +24 -24
  123. package/lib/dialog-B-jOQ5i3.cjs +1 -0
  124. package/lib/dialog-QWWUWOGP.js +95 -0
  125. package/lib/{dropdown-menu-Bs69ZBbO.js → dropdown-menu-C1hdPLCZ.js} +1 -1
  126. package/lib/{dropdown-menu-DjWlG2-J.cjs → dropdown-menu-CkHN04Mx.cjs} +1 -1
  127. package/lib/events.constant-Bh2uzJud.js +71 -0
  128. package/lib/events.constant-ELn21EzG.cjs +1 -0
  129. package/lib/extensions/CodeBlock/CodeBlock.d.ts +1 -1
  130. package/lib/file-BLas99n7.js +43 -0
  131. package/lib/file-i7e4nQY2.cjs +1 -0
  132. package/lib/{index-C-tDsIKJ.js → index-B3Ijnbxs.js} +1 -1
  133. package/lib/{index-C1WCZhyA.js → index-C1KQsOcg.js} +1 -1
  134. package/lib/{index-CsSfYR30.js → index-C8FjP66D.js} +1 -1
  135. package/lib/index-CAiZY1nx.js +2741 -0
  136. package/lib/index-DWSAk_9a.cjs +1 -0
  137. package/lib/{index-DjDf4BK8.js → index-s3l5RdyW.js} +1 -1
  138. package/lib/index.cjs +4 -4
  139. package/lib/index.js +392 -147
  140. package/lib/input-qvpuOf-3.js +21 -0
  141. package/lib/input-s0JD5kf2.cjs +1 -0
  142. package/lib/isNumber-BTYSVlKo.cjs +1 -0
  143. package/lib/isNumber-WaBzl_0s.js +15 -0
  144. package/lib/label-CFax-gzo.cjs +1 -0
  145. package/lib/label-DC37f2RQ.js +11 -0
  146. package/lib/{popover-D-hUKDYu.cjs → popover-B05Fd8lC.cjs} +1 -1
  147. package/lib/{popover-CPr9bHYn.js → popover-CsSXh7w6.js} +1 -1
  148. package/lib/{renderNodeView-BJSrgyGj.js → renderNodeView-C_hPIdEs.js} +2 -2
  149. package/lib/{select-C2KF4RNg.cjs → select-7ubC1NF0.cjs} +1 -1
  150. package/lib/{select-CuE_HaQJ.js → select-B3-5wTqn.js} +1 -1
  151. package/lib/{separator-CHzYNMVt.js → separator-CYCA8tSn.js} +13 -12
  152. package/lib/separator-ncbdw4oq.cjs +1 -0
  153. package/lib/style.css +1 -1
  154. package/lib/tabs-BeHxylKH.js +46 -0
  155. package/lib/tabs-DBqNpGAq.cjs +1 -0
  156. package/lib/{textarea-gEoNp9CA.js → textarea-1FhpmBkP.js} +1 -1
  157. package/lib/{textarea-DZj6EY-N.cjs → textarea-Bjhcpp76.cjs} +1 -1
  158. package/lib/throttle-CRNq0z-O.js +249 -0
  159. package/lib/throttle-gTTvqDTW.cjs +1 -0
  160. package/lib/toggle-DoJTBdvy.js +89 -0
  161. package/lib/toggle-oFwBZC4x.cjs +1 -0
  162. package/lib/{updatePosition-e90ZrFWW.js → updatePosition-DvfTZHcH.js} +2 -2
  163. package/lib/useButtonProps-BE10eHkG.js +165 -0
  164. package/lib/useButtonProps-CFu0GHzW.cjs +1 -0
  165. package/package.json +1 -1
  166. package/lib/ActionMenuButton-J1el_e6Z.cjs +0 -1
  167. package/lib/Drawer-BTouEroZ.cjs +0 -2
  168. package/lib/Iframe-BfBLILDA.cjs +0 -1
  169. package/lib/Indent-Dvqz_WEn.cjs +0 -1
  170. package/lib/Katex-BQyeCeQ0.cjs +0 -4
  171. package/lib/LinkEditBlock-CIshn_8F.cjs +0 -5
  172. package/lib/Mermaid-0GiGVxn0.cjs +0 -2
  173. package/lib/SlashCommandNodeView-rDJ7OjRd.cjs +0 -1
  174. package/lib/Table-BEhNBeuA.cjs +0 -5
  175. package/lib/Twitter-BuEBgpi9.cjs +0 -1
  176. package/lib/index-D9oM__YW.cjs +0 -1
  177. package/lib/index-lj3VWExo.js +0 -4883
  178. package/lib/separator-_gvUNba_.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-D9oM__YW.cjs"),l=require("react/jsx-runtime"),u=require("react"),j=require("./index-bVGIXhRg.cjs");require("./theme.cjs");const L=require("./popover-D-hUKDYu.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-bVGIXhRg.cjs"),L=require("./isNumber-BTYSVlKo.cjs"),W=require("./toggle-oFwBZC4x.cjs"),z=require("./useButtonProps-CFu0GHzW.cjs"),P=require("./popover-B05Fd8lC.cjs"),D=require("./input-s0JD5kf2.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-CDyrfCnw.js";
2
- import { y as k, z as C, F as X, u as Y, d as D, A as Z, G as U, j as J, H as Q } from "./index-lj3VWExo.js";
3
- import { jsx as u, jsxs as P, Fragment as K } from "react/jsx-runtime";
4
- import { useState as G, useMemo as L, useCallback as M, useEffect as $, useRef as ee } from "react";
5
- import { I as j, i as W, j as te } from "./index-4Q5IhypJ.js";
6
- import "./theme.js";
7
- import { P as ne, a as re, b as ie } from "./popover-CPr9bHYn.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-4Q5IhypJ.js";
6
+ import { i as W, c as Q } from "./isNumber-WaBzl_0s.js";
7
+ import { A as K } from "./toggle-DoJTBdvy.js";
8
+ import { u as ee, c as D } from "./useButtonProps-BE10eHkG.js";
9
+ import { P as te, a as re, b as ne } from "./popover-CsSXh7w6.js";
10
+ import { I as ie } from "./input-qvpuOf-3.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 = L(() => {
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]), y = L(() => {
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;
@@ -53,26 +56,26 @@ function ae(e) {
53
56
  height: o.target.height
54
57
  });
55
58
  }
56
- function _() {
59
+ function y() {
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) => {
@@ -99,31 +102,31 @@ function ae(e) {
99
102
  w: 0,
100
103
  h: 0,
101
104
  dir: ""
102
- }), s(!1), _());
105
+ }), s(!1), y());
103
106
  },
104
- [a, _]
105
- ), R = M(() => {
107
+ [a, y]
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 z = L(() => new ResizeObserver(() => I()), [I]);
114
- return $(() => (z.observe(e.editor.view.dom), () => {
115
- z.disconnect();
116
- }), [e.editor.view.dom, z]), /* @__PURE__ */ u(
115
+ }), [a, $, S]);
116
+ const L = P(() => new ResizeObserver(() => T()), [T]);
117
+ return z(() => (L.observe(e.editor.view.dom), () => {
118
+ L.disconnect();
119
+ }), [e.editor.view.dom, L]), /* @__PURE__ */ u(
117
120
  B,
118
121
  {
119
122
  className: "image-view",
120
- style: { ...y, width: "100%", textAlign: b },
121
- children: /* @__PURE__ */ P(
123
+ style: { ..._, width: "100%", textAlign: b },
124
+ children: /* @__PURE__ */ p(
122
125
  "div",
123
126
  {
124
127
  "data-drag-handle": !0,
125
128
  draggable: "true",
126
- style: y,
129
+ style: _,
127
130
  className: `image-view__body ${e != null && e.selected ? "image-view__body--focused" : ""} ${a ? "image-view__body--resizing" : ""}`,
128
131
  children: [
129
132
  /* @__PURE__ */ u(
@@ -132,13 +135,13 @@ function ae(e) {
132
135
  alt: g.alt,
133
136
  className: "image-view__body__image block",
134
137
  height: "auto",
135
- onClick: _,
138
+ onClick: y,
136
139
  onLoad: h,
137
140
  src: g.src,
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, y, h, _, 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
- width: (y = (g = (b = s == null ? void 0 : s.media_formats) == null ? void 0 : b.gif) == null ? void 0 : g.dims) == null ? void 0 : y[0],
196
- height: (I = (_ = (h = s == null ? void 0 : s.media_formats) == null ? void 0 : h.gif) == null ? void 0 : _.dims) == null ? void 0 : I[1]
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],
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) => {
206
- var a, s, l, v, b, g, y, h;
208
+ return (i = c == null ? void 0 : c.results) == null ? void 0 : i.map((r) => {
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 = (y = (g = n == null ? void 0 : n.media_formats) == null ? void 0 : g.gif) == null ? void 0 : y.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,41 +221,41 @@ 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
- const y = M(
230
- U(async (h) => {
232
+ const _ = M(
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
- const _ = await g(h.target.value);
237
- s(_);
239
+ const y = await g(h.target.value);
240
+ s(y);
238
241
  }, 350),
239
242
  // Adjust the debounce delay as needed
240
243
  []
241
244
  );
242
- return /* @__PURE__ */ P(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__ */ P(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
- J,
256
+ ie,
254
257
  {
255
- onChange: y,
258
+ onChange: _,
256
259
  placeholder: "Search GIF",
257
260
  ref: v,
258
261
  type: "text"
@@ -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 _e() {
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
- _e 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"),A=require("react"),s=require("./index-D9oM__YW.cjs");require("./theme.cjs");const P=require("./index-bVGIXhRg.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]=A.useState(!1),x=A.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 T=[];for(const h of f){const d=h.getAttribute("src"),r=N(d,"image/jpeg"),L=k(r,"image.jpeg");T.push(L)}const F=await g.upload(T);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 P=require("./clsx-CXbNJWDD.cjs"),l=require("react/jsx-runtime"),H=require("mammoth"),A=require("react"),N=require("./toggle-oFwBZC4x.cjs"),w=require("./ImageCropper-BKhXlnXN.cjs"),d=require("./useButtonProps-CFu0GHzW.cjs"),k=require("./index-bVGIXhRg.cjs");function z(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 D(o,t){return new File([o],t,{type:o.type})}function K(){const o=d.useEditorInstance(),t=d.useButtonProps(y.name),{icon:s=void 0,tooltip:c=void 0,tooltipOptions:u={},isActive:i=void 0,mammothOptions:j,limit:q,convert:b}=(t==null?void 0:t.componentProps)??{},{editorDisabled:W}=d.useToggleActive(i),p=d.useExtension(y.name),{toast:S}=w.useToast(),{t:B}=k.useLocale(),[C,v]=A.useState(!1),x=A.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>q){S({variant:"destructive",title:B("editor.importWord.limitSize")});return}F(n)}}async function E(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,w.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=z(m,"image/jpeg"),M=D(r,"image.jpeg");T.push(M)}const L=await g.upload(T);for(const[h,m]of f.entries()){m.setAttribute("src",L[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 F(e){v(!0);try{if(b){const n=await b(e);I(n)}else{const n=await e.arrayBuffer(),{value:a}=await H.convertToHtml({arrayBuffer:n},j);I(a)}}finally{v(!1)}}async function I(e){const n=await E(e);o.chain().setContent(n,!0).run()}return t?l.jsxs(l.Fragment,{children:[l.jsx(N.ActionButton,{action:O,disabled:W,icon:s,loading:C,tooltip:c,tooltipOptions:u}),l.jsx("input",{accept:".docx",onChange:R,ref:x,type:"file",style:{display:"none"}})]}):l.jsx(l.Fragment,{})}const y=P.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=K;
package/lib/ImportWord.js CHANGED
@@ -1,9 +1,10 @@
1
- import { E as M } from "./clsx-CDyrfCnw.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-lj3VWExo.js";
6
- import "./theme.js";
5
+ import { A as z } from "./toggle-DoJTBdvy.js";
6
+ import { u as D, I as K } from "./ImageCropper-DUzu_9-6.js";
7
+ import { f as U, u as q, c as G, i as J, j as Q } from "./useButtonProps-BE10eHkG.js";
7
8
  import { u as V } from "./index-4Q5IhypJ.js";
8
9
  function X(e, t) {
9
10
  const s = atob(e.split(",")[1]), c = Array.from({ length: s.length });
@@ -15,8 +16,8 @@ function X(e, t) {
15
16
  function Y(e, t) {
16
17
  return new File([e], t, { type: e.type });
17
18
  }
18
- function it() {
19
- const e = q(), t = z(w.name), {
19
+ function st() {
20
+ const e = U(), t = q(w.name), {
20
21
  icon: s = void 0,
21
22
  tooltip: c = void 0,
22
23
  tooltipOptions: l = {},
@@ -24,12 +25,12 @@ function it() {
24
25
  mammothOptions: T,
25
26
  limit: x,
26
27
  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() {
28
+ } = (t == null ? void 0 : t.componentProps) ?? {}, { editorDisabled: C } = G(i), u = J(w.name), { toast: E } = D(), { t: W } = V(), [j, y] = N(!1), b = k(null);
29
+ function B() {
29
30
  var o;
30
31
  (o = b.current) == null || o.click();
31
32
  }
32
- function O(o) {
33
+ function L(o) {
33
34
  const n = o.target.files[0];
34
35
  if (n) {
35
36
  if (n.size > x) {
@@ -39,24 +40,24 @@ function it() {
39
40
  });
40
41
  return;
41
42
  }
42
- j(n);
43
+ S(n);
43
44
  }
44
45
  }
45
- async function S(o) {
46
+ async function O(o) {
46
47
  const a = new DOMParser().parseFromString(o, "text/html"), p = a.querySelectorAll("img");
47
48
  if (p.length === 0)
48
49
  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") {
50
+ if (Q(e, K.name)) {
51
+ const f = u == null ? void 0 : u.options;
52
+ if (f && typeof f.upload == "function") {
52
53
  const A = [];
53
- for (const f of p) {
54
- const m = f.getAttribute("src"), r = X(m, "image/jpeg"), H = Y(r, "image.jpeg");
54
+ for (const d of p) {
55
+ const m = d.getAttribute("src"), r = X(m, "image/jpeg"), H = Y(r, "image.jpeg");
55
56
  A.push(H);
56
57
  }
57
- const F = await d.upload(A);
58
- for (const [f, m] of p.entries()) {
59
- m.setAttribute("src", F[f].src);
58
+ const F = await f.upload(A);
59
+ for (const [d, m] of p.entries()) {
60
+ m.setAttribute("src", F[d].src);
60
61
  const r = m.parentElement;
61
62
  (r == null ? void 0 : r.tagName) === "P" && (r.insertAdjacentElement("beforebegin", m), !r.hasChildNodes() && r.textContent === "" && r.remove());
62
63
  }
@@ -66,7 +67,7 @@ function it() {
66
67
  } else
67
68
  return console.error("Image extension not found, unable to convert image"), a.body.innerHTML;
68
69
  }
69
- async function j(o) {
70
+ async function S(o) {
70
71
  y(!0);
71
72
  try {
72
73
  if (h) {
@@ -81,17 +82,17 @@ function it() {
81
82
  }
82
83
  }
83
84
  async function v(o) {
84
- const n = await S(o);
85
+ const n = await O(o);
85
86
  e.chain().setContent(n, !0).run();
86
87
  }
87
88
  return t ? /* @__PURE__ */ P(I, { children: [
88
89
  /* @__PURE__ */ g(
89
- G,
90
+ z,
90
91
  {
91
- action: L,
92
+ action: B,
92
93
  disabled: C,
93
94
  icon: s,
94
- loading: B,
95
+ loading: j,
95
96
  tooltip: c,
96
97
  tooltipOptions: l
97
98
  }
@@ -100,7 +101,7 @@ function it() {
100
101
  "input",
101
102
  {
102
103
  accept: ".docx",
103
- onChange: O,
104
+ onChange: L,
104
105
  ref: b,
105
106
  type: "file",
106
107
  style: {
@@ -141,5 +142,5 @@ const w = /* @__PURE__ */ M.create({
141
142
  });
142
143
  export {
143
144
  w as ImportWord,
144
- it as RichTextImportWord
145
+ st as RichTextImportWord
145
146
  };