@remarkablejames/editor 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{ActionMenuButton-Bmn3RME4.js → ActionMenuButton-D5HLfRzv.js} +9 -10
- package/lib/ActionMenuButton-DN6VHLkp.cjs +1 -0
- package/lib/Attachment.cjs +2 -2
- package/lib/Attachment.js +31 -33
- package/lib/Blockquote.cjs +2 -2
- package/lib/Blockquote.js +13 -12
- package/lib/Bold.cjs +1 -1
- package/lib/Bold.js +11 -10
- package/lib/BulletList.cjs +1 -1
- package/lib/BulletList.js +9 -8
- package/lib/Callout.cjs +1 -1
- package/lib/Callout.js +41 -45
- package/lib/Clear.cjs +1 -1
- package/lib/Clear.js +13 -14
- package/lib/Code.cjs +1 -1
- package/lib/Code.js +6 -5
- package/lib/CodeBlock.cjs +1 -1
- package/lib/CodeBlock.js +30 -31
- package/lib/CodeView.cjs +1 -1
- package/lib/CodeView.js +9 -8
- package/lib/Color.cjs +1 -1
- package/lib/Color.js +18 -19
- package/lib/Column.cjs +1 -1
- package/lib/Column.js +9 -8
- package/lib/{Drawer-DvGh9aXG.js → Drawer-B9l1SoRJ.js} +41 -47
- package/lib/Drawer-BN0lYcnJ.cjs +2 -0
- package/lib/Drawer.cjs +1 -1
- package/lib/Drawer.js +3 -3
- package/lib/Emoji.cjs +1 -1
- package/lib/Emoji.js +14 -15
- package/lib/Excalidraw.cjs +1 -1
- package/lib/Excalidraw.js +24 -28
- package/lib/ExportPdf.cjs +3 -3
- package/lib/ExportPdf.js +14 -13
- package/lib/ExportWord.cjs +1 -1
- package/lib/ExportWord.js +6 -6
- package/lib/FontFamily.cjs +1 -1
- package/lib/FontFamily.js +7 -6
- package/lib/FontSize.cjs +1 -1
- package/lib/FontSize.js +15 -14
- package/lib/Heading.cjs +1 -1
- package/lib/Heading.js +26 -26
- package/lib/Highlight.cjs +1 -1
- package/lib/Highlight.js +22 -23
- package/lib/History.cjs +1 -1
- package/lib/History.js +11 -11
- package/lib/HorizontalRule.cjs +1 -1
- package/lib/HorizontalRule.js +10 -9
- package/lib/Iframe-CXFk3GEq.cjs +1 -0
- package/lib/{Iframe-CnnvV6cK.js → Iframe-MjeJ2OOI.js} +11 -13
- package/lib/Iframe.cjs +1 -1
- package/lib/Iframe.js +2 -2
- package/lib/Image.cjs +1 -1
- package/lib/Image.js +4 -5
- package/lib/ImageGif.cjs +1 -1
- package/lib/ImageGif.js +79 -82
- package/lib/ImportWord.cjs +1 -1
- package/lib/ImportWord.js +25 -26
- package/lib/Indent-BPX9XRos.cjs +1 -0
- package/lib/{Indent-Bsj8gKvT.js → Indent-CgwDItIf.js} +31 -30
- package/lib/Indent.cjs +1 -1
- package/lib/Indent.js +2 -2
- package/lib/Italic.cjs +1 -1
- package/lib/Italic.js +12 -11
- package/lib/{Katex-CilGTz7u.js → Katex-CZ4g3vA9.js} +19 -22
- package/lib/Katex-DIgsR_dS.cjs +4 -0
- package/lib/Katex.cjs +1 -1
- package/lib/Katex.js +2 -2
- package/lib/LineHeight.cjs +1 -1
- package/lib/LineHeight.js +19 -20
- package/lib/Link.cjs +1 -1
- package/lib/Link.js +2 -2
- package/lib/LinkEditBlock-B2bU0Mcr.cjs +5 -0
- package/lib/{LinkEditBlock-BD_WvA3r.js → LinkEditBlock-CaDV3Vq5.js} +19 -24
- package/lib/Mention.js +3 -3
- package/lib/Mermaid-B9h7XKFo.cjs +2 -0
- package/lib/{Mermaid-BrjU75Bs.js → Mermaid-EhYj_ICn.js} +45 -48
- package/lib/Mermaid.cjs +1 -1
- package/lib/Mermaid.js +2 -2
- package/lib/MoreMark.cjs +1 -1
- package/lib/MoreMark.js +26 -28
- package/lib/OrderedList.cjs +1 -1
- package/lib/OrderedList.js +11 -10
- package/lib/SearchAndReplace.cjs +1 -1
- package/lib/SearchAndReplace.js +37 -42
- package/lib/SlashCommand.cjs +1 -1
- package/lib/SlashCommand.js +5 -5
- package/lib/SlashCommandNodeView-COlWSlnE.cjs +1 -0
- package/lib/{SlashCommandNodeView-COx5qZ2y.js → SlashCommandNodeView-CY3peX5x.js} +39 -41
- package/lib/Strike.cjs +1 -1
- package/lib/Strike.js +12 -11
- package/lib/{Table-BlM8yMhr.js → Table-Bw7rLue7.js} +46 -46
- package/lib/Table-DLrtX6T7.cjs +5 -0
- package/lib/Table.cjs +1 -1
- package/lib/Table.js +1 -1
- package/lib/TaskList.cjs +1 -1
- package/lib/TaskList.js +12 -11
- package/lib/TextAlign.cjs +1 -1
- package/lib/TextAlign.js +26 -27
- package/lib/TextDirection.cjs +1 -1
- package/lib/TextDirection.js +18 -19
- package/lib/TextUnderline.cjs +1 -1
- package/lib/TextUnderline.js +9 -8
- package/lib/Twitter-Ck6vGefg.cjs +1 -0
- package/lib/{Twitter-BP8sYXX7.js → Twitter-pM0y5Z-L.js} +18 -22
- package/lib/Twitter.cjs +1 -1
- package/lib/Twitter.js +2 -2
- package/lib/Video.cjs +1 -1
- package/lib/Video.js +4 -5
- package/lib/bubble.cjs +3 -3
- package/lib/bubble.js +77 -86
- package/lib/{clsx-m_C5j3RU.js → clsx-CDyrfCnw.js} +24 -24
- package/lib/{dropdown-menu-CkHN04Mx.cjs → dropdown-menu-DwR8tTs9.cjs} +1 -1
- package/lib/{dropdown-menu-C1hdPLCZ.js → dropdown-menu-nX-u8e2w.js} +1 -1
- package/lib/extensions/Image/Image.d.ts +11 -0
- package/lib/extensions/Image/components/ImageCropper.d.ts +1 -1
- package/lib/{index-B3Ijnbxs.js → index-C-tDsIKJ.js} +1 -1
- package/lib/{index-C1KQsOcg.js → index-C1WCZhyA.js} +1 -1
- package/lib/{index-C8FjP66D.js → index-CsSfYR30.js} +1 -1
- package/lib/index-Dib4cXXf.cjs +10 -0
- package/lib/{index-s3l5RdyW.js → index-DjDf4BK8.js} +1 -1
- package/lib/index-_WrFM-Fk.js +5054 -0
- package/lib/index.cjs +4 -4
- package/lib/index.js +147 -392
- package/lib/{popover-B05Fd8lC.cjs → popover-BY7j9SiD.cjs} +1 -1
- package/lib/{popover-CsSXh7w6.js → popover-CSvY4C-l.js} +1 -1
- package/lib/{renderNodeView-C_hPIdEs.js → renderNodeView-BJSrgyGj.js} +2 -2
- package/lib/{select-B3-5wTqn.js → select-BelNLNvT.js} +1 -1
- package/lib/{select-7ubC1NF0.cjs → select-Bu-5iIA9.cjs} +1 -1
- package/lib/{separator-CYCA8tSn.js → separator-Br5kcIJa.js} +12 -13
- package/lib/separator-Cp9Lg3HU.cjs +1 -0
- package/lib/style.css +1 -1
- package/lib/{textarea-1FhpmBkP.js → textarea-Ceev4t42.js} +1 -1
- package/lib/{textarea-Bjhcpp76.cjs → textarea-DfqvYaA6.cjs} +1 -1
- package/lib/theme/theme.d.ts +1 -1
- package/lib/{updatePosition-DvfTZHcH.js → updatePosition-e90ZrFWW.js} +2 -2
- package/package.json +1 -1
- package/lib/ActionMenuButton-C5P0Kzrb.cjs +0 -1
- package/lib/Drawer-gz9U5ArC.cjs +0 -2
- package/lib/Icon-CKM0tYbW.js +0 -15
- package/lib/Icon-CQyFgXeo.cjs +0 -1
- package/lib/Iframe-Ds6gG2YO.cjs +0 -1
- package/lib/ImageCropper-BKhXlnXN.cjs +0 -1
- package/lib/ImageCropper-DUzu_9-6.js +0 -896
- package/lib/Indent-D_7HOYYd.cjs +0 -1
- package/lib/Katex-lL3bHXJd.cjs +0 -4
- package/lib/LinkEditBlock-D3HSHmsU.cjs +0 -5
- package/lib/Mermaid-BfeLPzoS.cjs +0 -2
- package/lib/SlashCommandNodeView-DD-nlhM-.cjs +0 -1
- package/lib/Table-C21AlUrh.cjs +0 -5
- package/lib/Twitter-D46MnvPr.cjs +0 -1
- package/lib/Video-Bpd8W8l6.js +0 -231
- package/lib/Video-BwrHx6B1.cjs +0 -1
- package/lib/button-BmTP96NR.cjs +0 -1
- package/lib/button-CDIxPURh.js +0 -35
- package/lib/checkbox-7sfSdzy9.js +0 -29
- package/lib/checkbox-DyVlLWHv.cjs +0 -1
- package/lib/dialog-B-jOQ5i3.cjs +0 -1
- package/lib/dialog-QWWUWOGP.js +0 -95
- package/lib/events.constant-Bh2uzJud.js +0 -71
- package/lib/events.constant-ELn21EzG.cjs +0 -1
- package/lib/file-BLas99n7.js +0 -43
- package/lib/file-i7e4nQY2.cjs +0 -1
- package/lib/index-CAiZY1nx.js +0 -2741
- package/lib/index-DWSAk_9a.cjs +0 -1
- package/lib/input-qvpuOf-3.js +0 -21
- package/lib/input-s0JD5kf2.cjs +0 -1
- package/lib/isNumber-BTYSVlKo.cjs +0 -1
- package/lib/isNumber-WaBzl_0s.js +0 -15
- package/lib/label-CFax-gzo.cjs +0 -1
- package/lib/label-DC37f2RQ.js +0 -11
- package/lib/separator-ncbdw4oq.cjs +0 -1
- package/lib/tabs-BeHxylKH.js +0 -46
- package/lib/tabs-DBqNpGAq.cjs +0 -1
- package/lib/throttle-CRNq0z-O.js +0 -249
- package/lib/throttle-gTTvqDTW.cjs +0 -1
- package/lib/toggle-DoJTBdvy.js +0 -89
- package/lib/toggle-oFwBZC4x.cjs +0 -1
- package/lib/useButtonProps-BE10eHkG.js +0 -165
- package/lib/useButtonProps-CFu0GHzW.cjs +0 -1
package/lib/Image.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import "./clsx-
|
|
2
|
-
import "./
|
|
3
|
-
import { I as r, R as t } from "./ImageCropper-DUzu_9-6.js";
|
|
1
|
+
import "./clsx-CDyrfCnw.js";
|
|
2
|
+
import { t, $ as o } from "./index-_WrFM-Fk.js";
|
|
4
3
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
t as Image,
|
|
5
|
+
o as RichTextImage
|
|
7
6
|
};
|
package/lib/ImageGif.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./clsx-CXbNJWDD.cjs"),f=require("./index-Dib4cXXf.cjs"),l=require("react/jsx-runtime"),u=require("react"),j=require("./index-bVGIXhRg.cjs");require("./theme.cjs");const L=require("./popover-BY7j9SiD.cjs"),N={TOP_LEFT:"tl",TOP_RIGHT:"tr",BOTTOM_LEFT:"bl",BOTTOM_RIGHT:"br"};function q(e){var k,z;const[t,r]=u.useState({width:j.IMAGE_MAX_SIZE,height:j.IMAGE_MAX_SIZE}),[o,i]=u.useState({width:0,height:0}),[n]=u.useState([N.TOP_LEFT,N.TOP_RIGHT,N.BOTTOM_LEFT,N.BOTTOM_RIGHT]),[s,a]=u.useState(!1),[h,x]=u.useState({x:0,y:0,w:0,h:0,dir:""}),{align:T}=(k=e==null?void 0:e.node)==null?void 0:k.attrs,m=u.useMemo(()=>{var b;const{src:c,alt:w,width:v,height:A}=(b=e==null?void 0:e.node)==null?void 0:b.attrs,G=f.isNumber(v)?`${v}px`:v,d=f.isNumber(A)?`${A}px`:A;return{src:c||void 0,alt:w||void 0,style:{width:G||void 0,height:d||void 0}}},[(z=e==null?void 0:e.node)==null?void 0:z.attrs]),_=u.useMemo(()=>{const{style:{width:c}}=m;return{width:c==="100%"?c:void 0}},[m]);function g(c){i({width:c.target.width,height:c.target.height})}function I(){const{editor:c,getPos:w}=e;c.commands.setNodeSelection(w())}const M=u.useCallback(f.throttle(()=>{const{editor:c}=e,{width:w}=getComputedStyle(c.view.dom);r(v=>({...v,width:Number.parseInt(w,10)}))},j.IMAGE_THROTTLE_WAIT_TIME),[e==null?void 0:e.editor]);function H(c,w){c.preventDefault(),c.stopPropagation();const v=o.width,A=o.height,G=v/A;let d=Number(e.node.attrs.width),b=Number(e.node.attrs.height);const y=t.width;d&&!b?(d=d>y?y:d,b=Math.round(d/G)):b&&!d?(d=Math.round(b*G),d=d>y?y:d):!d&&!b?(d=v>y?y:v,b=Math.round(d/G)):d=d>y?y:d,a(!0),x({x:c.clientX,y:c.clientY,w:d,h:b,dir:w})}const E=u.useCallback(f.throttle(c=>{if(c.preventDefault(),c.stopPropagation(),!s)return;const{x:w,w:v,dir:A}=h,G=(c.clientX-w)*(/l/.test(A)?-1:1),d=f.clamp$1(v+G,j.IMAGE_MIN_SIZE,t.width);e.updateAttributes({width:d,height:null})},j.IMAGE_THROTTLE_WAIT_TIME),[s,h,t,e.updateAttributes]),S=u.useCallback(c=>{c.preventDefault(),c.stopPropagation(),s&&(x({x:0,y:0,w:0,h:0,dir:""}),a(!1),I())},[s,I]),$=u.useCallback(()=>{document==null||document.addEventListener("mousemove",E,!0),document==null||document.addEventListener("mouseup",S,!0)},[E,S]),O=u.useCallback(()=>{document==null||document.removeEventListener("mousemove",E,!0),document==null||document.removeEventListener("mouseup",S,!0)},[E,S]);u.useEffect(()=>(s?$():O(),()=>{O()}),[s,$,O]);const R=u.useMemo(()=>new ResizeObserver(()=>M()),[M]);return u.useEffect(()=>(R.observe(e.editor.view.dom),()=>{R.disconnect()}),[e.editor.view.dom,R]),l.jsx(P.NodeViewWrapper,{className:"image-view",style:{..._,width:"100%",textAlign:T},children:l.jsxs("div",{"data-drag-handle":!0,draggable:"true",style:_,className:`image-view__body ${e!=null&&e.selected?"image-view__body--focused":""} ${s?"image-view__body--resizing":""}`,children:[l.jsx("img",{alt:m.alt,className:"image-view__body__image block",height:"auto",onClick:I,onLoad:g,src:m.src,style:m.style}),(e==null?void 0:e.editor.view.editable)&&((e==null?void 0:e.selected)||s)&&l.jsx("div",{className:"image-resizer",children:n==null?void 0:n.map(c=>l.jsx("span",{className:`image-resizer__handler image-resizer__handler--${c}`,onMouseDown:w=>H(w,c)},`image-dir-${c}`))})]})})}async function W(e){var o;const r=await(await fetch(`https://api.giphy.com/v1/gifs/trending?q=&limit=15&api_key=${e}`)).json();return(o=r==null?void 0:r.data)==null?void 0:o.map(i=>{var n,s,a;return{id:i==null?void 0:i.id,src:(n=i==null?void 0:i.images.original)==null?void 0:n.url,width:+((s=i==null?void 0:i.images.original)==null?void 0:s.width),height:+((a=i==null?void 0:i.images.original)==null?void 0:a.width)}})}async function p(e,t){var i;const o=await(await fetch(`https://api.giphy.com/v1/gifs/search?q=${e}&limit=15&api_key=${t}`)).json();return(i=o==null?void 0:o.data)==null?void 0:i.map(n=>{var s,a,h;return{id:n==null?void 0:n.id,src:(s=n==null?void 0:n.images.original)==null?void 0:s.url,width:+((a=n==null?void 0:n.images.original)==null?void 0:a.width),height:+((h=n==null?void 0:n.images.original)==null?void 0:h.width)}})}async function D(e){var n,s;const t=await fetch(`https://tenor.googleapis.com/v2/trending_terms?key=${e}&limit=10`),r=await(t==null?void 0:t.json()),i=await(await fetch(`https://tenor.googleapis.com/v2/search?key=${e}&q=${(n=r==null?void 0:r.results)==null?void 0:n[0]}&limit=15`)).json();return(s=i==null?void 0:i.results)==null?void 0:s.map(a=>{var h,x,T,m,_,g,I,M;return{id:a==null?void 0:a.id,src:(x=(h=a==null?void 0:a.media_formats)==null?void 0:h.gif)==null?void 0:x.url,width:(_=(m=(T=a==null?void 0:a.media_formats)==null?void 0:T.gif)==null?void 0:m.dims)==null?void 0:_[0],height:(M=(I=(g=a==null?void 0:a.media_formats)==null?void 0:g.gif)==null?void 0:I.dims)==null?void 0:M[1]}})}async function F(e,t){var i;const o=await(await fetch(`https://tenor.googleapis.com/v2/search?key=${t}&q=${e}&limit=15`)).json();return(i=o==null?void 0:o.results)==null?void 0:i.map(n=>{var s,a,h,x,T,m,_,g;return{id:n==null?void 0:n.id,src:(a=(s=n==null?void 0:n.media_formats)==null?void 0:s.gif)==null?void 0:a.url,width:(T=(x=(h=n==null?void 0:n.media_formats)==null?void 0:h.gif)==null?void 0:x.dims)==null?void 0:T[0],height:(g=(_=(m=n==null?void 0:n.media_formats)==null?void 0:m.gif)==null?void 0:_.dims)==null?void 0:g[1]}})}function B(e,t){return{searchTrending:async()=>t?e==="giphy"?W(t):e==="tenor"?D(t):[]:[],searchWord:async i=>t?e==="giphy"?p(i,t):e==="tenor"?F(i,t):[]:[]}}function V({selectImage:e,apiKey:t,provider:r,children:o}){const[i,n]=u.useState(!1),[s,a]=u.useState([]),{editorDisabled:h}=f.useToggleActive(),x=u.useRef(null),{searchTrending:T,searchWord:m}=B(r,t);u.useEffect(()=>{(async()=>{const g=await T();a(g)})()},[]);const _=u.useCallback(f.debounce(async g=>{if(!g.target.value){const M=await T();a(M);return}const I=await m(g.target.value);a(I)},350),[]);return l.jsxs(L.Popover,{modal:!0,onOpenChange:n,open:i,children:[l.jsx(L.PopoverTrigger,{asChild:!0,disabled:h,children:o}),l.jsx(L.PopoverContent,{align:"start",className:"richtext-size-full richtext-p-2",hideWhenDetached:!0,side:"bottom",children:t?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"richtext-mb-[10px] richtext-w-full",children:l.jsx(f.Input,{onChange:_,placeholder:"Search GIF",ref:x,type:"text"})}),l.jsx("div",{className:"richtext-max-h-[280px] !richtext-max-w-[400px] richtext-overflow-y-auto",children:l.jsx("div",{className:"richtext-grid richtext-grid-cols-2 richtext-gap-1",children:s!=null&&s.length?s==null?void 0:s.map(g=>l.jsx("img",{alt:"",className:"richtext-cursor-pointer richtext-object-contain richtext-text-center",src:g.src,onClick:()=>{e(g.src),n(!1)}},g.id)):l.jsx("p",{children:"No GIFs found"})})})]}):l.jsx("div",{children:l.jsx("p",{children:"Missing Giphy API Key"})})})]})}function X(){const e=f.useButtonProps(C.name),{action:t,icon:r,tooltip:o,apiKey:i,provider:n}=(e==null?void 0:e.componentProps)??{},{editorDisabled:s}=f.useToggleActive(),a=h=>{s||t&&t(h)};return l.jsx(V,{apiKey:i,provider:n,selectImage:a,children:l.jsx(f.ActionButton,{disabled:s,icon:r,tooltip:o})})}const C=f.index_default.extend({name:"imageGif",addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),inline:!1,content:"",marks:"",group:"block",API_KEY:"",provider:"giphy",draggable:!1,selectable:!0,atom:!0,button:({editor:t,extension:r,t:o})=>{var s,a;const i=((s=r==null?void 0:r.options)==null?void 0:s.provider)||"",n=((a=r==null?void 0:r.options)==null?void 0:a.API_KEY)||"";return{componentProps:{action:h=>{t.chain().focus().setImageGif({src:h}).run()},isActive:()=>!1,disabled:!1,icon:"GifIcon",tooltip:o("editor.imageGif.tooltip"),apiKey:n,provider:i}}}}},addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),width:{default:null,parseHTML:t=>{const r=t.style.width||t.getAttribute("width")||"10";return r===void 0?null:Number.parseInt(`${r}`,10)},renderHTML:t=>({width:t.width})},align:{default:"center",parseHTML:t=>t.getAttribute("align"),renderHTML:t=>({align:t.align})}}},addNodeView(){return P.ReactNodeViewRenderer(q)},addCommands(){var e;return{...(e=this.parent)==null?void 0:e.call(this),setImageGif:t=>({commands:r})=>r.insertContent({type:this.name,attrs:t}),updateImageGif:t=>({commands:r})=>r.updateAttributes(this.name,t),setAlignImageGif:t=>({commands:r})=>r.updateAttributes(this.name,{align:t})}},renderHTML({HTMLAttributes:e}){const{align:t}=e;return["div",{style:t?`text-align: ${t};`:"",class:"imageGIf"},["img",P.mergeAttributes({height:"auto"},this.options.HTMLAttributes,e)]]},parseHTML(){return[{tag:"div[class=imageGIf]",getAttrs:e=>{const t=e.querySelector("img"),r=t==null?void 0:t.getAttribute("width");return{src:t==null?void 0:t.getAttribute("src"),alt:t==null?void 0:t.getAttribute("alt"),title:t==null?void 0:t.getAttribute("title"),width:r?Number.parseInt(r,10):null,align:(t==null?void 0:t.getAttribute("align"))||e.style.textAlign||null}}}]}});exports.ImageGif=C;exports.RichTextImageGif=X;
|
package/lib/ImageGif.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { h as B, m as q, k as V } from "./clsx-
|
|
2
|
-
import {
|
|
3
|
-
import { jsx as u, jsxs as
|
|
4
|
-
import { useState as G, useMemo as
|
|
5
|
-
import { I as
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
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";
|
|
1
|
+
import { h as B, m as q, k as V } from "./clsx-CDyrfCnw.js";
|
|
2
|
+
import { z as k, F as C, G as X, u as Y, d as D, A as Z, H as J, j as U, J as Q } from "./index-_WrFM-Fk.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-CSvY4C-l.js";
|
|
11
8
|
const O = {
|
|
12
9
|
TOP_LEFT: "tl",
|
|
13
10
|
TOP_RIGHT: "tr",
|
|
@@ -15,14 +12,14 @@ const O = {
|
|
|
15
12
|
BOTTOM_RIGHT: "br"
|
|
16
13
|
};
|
|
17
14
|
function ae(e) {
|
|
18
|
-
var
|
|
19
|
-
const [t,
|
|
20
|
-
width:
|
|
21
|
-
height:
|
|
15
|
+
var p, H;
|
|
16
|
+
const [t, r] = G({
|
|
17
|
+
width: j,
|
|
18
|
+
height: j
|
|
22
19
|
}), [c, i] = G({
|
|
23
20
|
width: 0,
|
|
24
21
|
height: 0
|
|
25
|
-
}), [
|
|
22
|
+
}), [n] = G([
|
|
26
23
|
O.TOP_LEFT,
|
|
27
24
|
O.TOP_RIGHT,
|
|
28
25
|
O.BOTTOM_LEFT,
|
|
@@ -33,9 +30,9 @@ function ae(e) {
|
|
|
33
30
|
w: 0,
|
|
34
31
|
h: 0,
|
|
35
32
|
dir: ""
|
|
36
|
-
}), { align: b } = (
|
|
33
|
+
}), { align: b } = (p = e == null ? void 0 : e.node) == null ? void 0 : p.attrs, g = L(() => {
|
|
37
34
|
var w;
|
|
38
|
-
const { src: o, alt: m, width: f, height: x } = (w = e == null ? void 0 : e.node) == null ? void 0 : w.attrs, A =
|
|
35
|
+
const { src: o, alt: m, width: f, height: x } = (w = e == null ? void 0 : e.node) == null ? void 0 : w.attrs, A = k(f) ? `${f}px` : f, d = k(x) ? `${x}px` : x;
|
|
39
36
|
return {
|
|
40
37
|
src: o || void 0,
|
|
41
38
|
alt: m || void 0,
|
|
@@ -44,7 +41,7 @@ function ae(e) {
|
|
|
44
41
|
height: d || void 0
|
|
45
42
|
}
|
|
46
43
|
};
|
|
47
|
-
}, [(
|
|
44
|
+
}, [(H = e == null ? void 0 : e.node) == null ? void 0 : H.attrs]), _ = L(() => {
|
|
48
45
|
const {
|
|
49
46
|
style: { width: o }
|
|
50
47
|
} = g;
|
|
@@ -60,22 +57,22 @@ function ae(e) {
|
|
|
60
57
|
const { editor: o, getPos: m } = e;
|
|
61
58
|
o.commands.setNodeSelection(m());
|
|
62
59
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
60
|
+
const I = M(
|
|
61
|
+
C(() => {
|
|
65
62
|
const { editor: o } = e, { width: m } = getComputedStyle(o.view.dom);
|
|
66
|
-
|
|
63
|
+
r((f) => ({
|
|
67
64
|
...f,
|
|
68
65
|
width: Number.parseInt(m, 10)
|
|
69
66
|
}));
|
|
70
|
-
},
|
|
67
|
+
}, W),
|
|
71
68
|
[e == null ? void 0 : e.editor]
|
|
72
69
|
);
|
|
73
70
|
function F(o, m) {
|
|
74
71
|
o.preventDefault(), o.stopPropagation();
|
|
75
72
|
const f = c.width, x = c.height, A = f / x;
|
|
76
73
|
let d = Number(e.node.attrs.width), w = Number(e.node.attrs.height);
|
|
77
|
-
const
|
|
78
|
-
d && !w ? (d = d >
|
|
74
|
+
const T = t.width;
|
|
75
|
+
d && !w ? (d = d > T ? T : d, w = Math.round(d / A)) : w && !d ? (d = Math.round(w * A), d = d > T ? T : d) : !d && !w ? (d = f > T ? T : f, w = Math.round(d / A)) : d = d > T ? T : d, s(!0), v({
|
|
79
76
|
x: o.clientX,
|
|
80
77
|
y: o.clientY,
|
|
81
78
|
w: d,
|
|
@@ -84,15 +81,15 @@ function ae(e) {
|
|
|
84
81
|
});
|
|
85
82
|
}
|
|
86
83
|
const N = M(
|
|
87
|
-
|
|
84
|
+
C((o) => {
|
|
88
85
|
if (o.preventDefault(), o.stopPropagation(), !a)
|
|
89
86
|
return;
|
|
90
|
-
const { x: m, w: f, dir: x } = l, A = (o.clientX - m) * (/l/.test(x) ? -1 : 1), d =
|
|
87
|
+
const { x: m, w: f, dir: x } = l, A = (o.clientX - m) * (/l/.test(x) ? -1 : 1), d = X(f + A, te, t.width);
|
|
91
88
|
e.updateAttributes({
|
|
92
89
|
width: d,
|
|
93
90
|
height: null
|
|
94
91
|
});
|
|
95
|
-
},
|
|
92
|
+
}, W),
|
|
96
93
|
[a, l, t, e.updateAttributes]
|
|
97
94
|
), E = M(
|
|
98
95
|
(o) => {
|
|
@@ -105,23 +102,23 @@ function ae(e) {
|
|
|
105
102
|
}), s(!1), y());
|
|
106
103
|
},
|
|
107
104
|
[a, y]
|
|
108
|
-
),
|
|
105
|
+
), R = M(() => {
|
|
109
106
|
document == null || document.addEventListener("mousemove", N, !0), document == null || document.addEventListener("mouseup", E, !0);
|
|
110
107
|
}, [N, E]), S = M(() => {
|
|
111
108
|
document == null || document.removeEventListener("mousemove", N, !0), document == null || document.removeEventListener("mouseup", E, !0);
|
|
112
109
|
}, [N, E]);
|
|
113
|
-
|
|
110
|
+
$(() => (a ? R() : S(), () => {
|
|
114
111
|
S();
|
|
115
|
-
}), [a,
|
|
116
|
-
const
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
}), [e.editor.view.dom,
|
|
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(
|
|
120
117
|
B,
|
|
121
118
|
{
|
|
122
119
|
className: "image-view",
|
|
123
120
|
style: { ..._, width: "100%", textAlign: b },
|
|
124
|
-
children: /* @__PURE__ */
|
|
121
|
+
children: /* @__PURE__ */ P(
|
|
125
122
|
"div",
|
|
126
123
|
{
|
|
127
124
|
"data-drag-handle": !0,
|
|
@@ -141,7 +138,7 @@ function ae(e) {
|
|
|
141
138
|
style: g.style
|
|
142
139
|
}
|
|
143
140
|
),
|
|
144
|
-
(e == null ? void 0 : e.editor.view.editable) && ((e == null ? void 0 : e.selected) || a) && /* @__PURE__ */ u("div", { className: "image-resizer", children:
|
|
141
|
+
(e == null ? void 0 : e.editor.view.editable) && ((e == null ? void 0 : e.selected) || a) && /* @__PURE__ */ u("div", { className: "image-resizer", children: n == null ? void 0 : n.map((o) => /* @__PURE__ */ u(
|
|
145
142
|
"span",
|
|
146
143
|
{
|
|
147
144
|
className: `image-resizer__handler image-resizer__handler--${o}`,
|
|
@@ -157,12 +154,12 @@ function ae(e) {
|
|
|
157
154
|
}
|
|
158
155
|
async function se(e) {
|
|
159
156
|
var c;
|
|
160
|
-
const
|
|
161
|
-
return (c =
|
|
162
|
-
var
|
|
157
|
+
const r = await (await fetch(`https://api.giphy.com/v1/gifs/trending?q=&limit=15&api_key=${e}`)).json();
|
|
158
|
+
return (c = r == null ? void 0 : r.data) == null ? void 0 : c.map((i) => {
|
|
159
|
+
var n, a, s;
|
|
163
160
|
return {
|
|
164
161
|
id: i == null ? void 0 : i.id,
|
|
165
|
-
src: (
|
|
162
|
+
src: (n = i == null ? void 0 : i.images.original) == null ? void 0 : n.url,
|
|
166
163
|
width: +((a = i == null ? void 0 : i.images.original) == null ? void 0 : a.width),
|
|
167
164
|
height: +((s = i == null ? void 0 : i.images.original) == null ? void 0 : s.width)
|
|
168
165
|
};
|
|
@@ -173,30 +170,30 @@ async function oe(e, t) {
|
|
|
173
170
|
const c = await (await fetch(
|
|
174
171
|
`https://api.giphy.com/v1/gifs/search?q=${e}&limit=15&api_key=${t}`
|
|
175
172
|
)).json();
|
|
176
|
-
return (i = c == null ? void 0 : c.data) == null ? void 0 : i.map((
|
|
173
|
+
return (i = c == null ? void 0 : c.data) == null ? void 0 : i.map((n) => {
|
|
177
174
|
var a, s, l;
|
|
178
175
|
return {
|
|
179
|
-
id:
|
|
180
|
-
src: (a =
|
|
181
|
-
width: +((s =
|
|
182
|
-
height: +((l =
|
|
176
|
+
id: n == null ? void 0 : n.id,
|
|
177
|
+
src: (a = n == null ? void 0 : n.images.original) == null ? void 0 : a.url,
|
|
178
|
+
width: +((s = n == null ? void 0 : n.images.original) == null ? void 0 : s.width),
|
|
179
|
+
height: +((l = n == null ? void 0 : n.images.original) == null ? void 0 : l.width)
|
|
183
180
|
};
|
|
184
181
|
});
|
|
185
182
|
}
|
|
186
183
|
async function ce(e) {
|
|
187
|
-
var
|
|
184
|
+
var n, a;
|
|
188
185
|
const t = await fetch(
|
|
189
186
|
`https://tenor.googleapis.com/v2/trending_terms?key=${e}&limit=10`
|
|
190
|
-
),
|
|
191
|
-
`https://tenor.googleapis.com/v2/search?key=${e}&q=${(
|
|
187
|
+
), r = await (t == null ? void 0 : t.json()), i = await (await fetch(
|
|
188
|
+
`https://tenor.googleapis.com/v2/search?key=${e}&q=${(n = r == null ? void 0 : r.results) == null ? void 0 : n[0]}&limit=15`
|
|
192
189
|
)).json();
|
|
193
190
|
return (a = i == null ? void 0 : i.results) == null ? void 0 : a.map((s) => {
|
|
194
|
-
var l, v, b, g, _, h, y,
|
|
191
|
+
var l, v, b, g, _, h, y, I;
|
|
195
192
|
return {
|
|
196
193
|
id: s == null ? void 0 : s.id,
|
|
197
194
|
src: (v = (l = s == null ? void 0 : s.media_formats) == null ? void 0 : l.gif) == null ? void 0 : v.url,
|
|
198
195
|
width: (_ = (g = (b = s == null ? void 0 : s.media_formats) == null ? void 0 : b.gif) == null ? void 0 : g.dims) == null ? void 0 : _[0],
|
|
199
|
-
height: (
|
|
196
|
+
height: (I = (y = (h = s == null ? void 0 : s.media_formats) == null ? void 0 : h.gif) == null ? void 0 : y.dims) == null ? void 0 : I[1]
|
|
200
197
|
};
|
|
201
198
|
});
|
|
202
199
|
}
|
|
@@ -205,13 +202,13 @@ async function de(e, t) {
|
|
|
205
202
|
const c = await (await fetch(
|
|
206
203
|
`https://tenor.googleapis.com/v2/search?key=${t}&q=${e}&limit=15`
|
|
207
204
|
)).json();
|
|
208
|
-
return (i = c == null ? void 0 : c.results) == null ? void 0 : i.map((
|
|
205
|
+
return (i = c == null ? void 0 : c.results) == null ? void 0 : i.map((n) => {
|
|
209
206
|
var a, s, l, v, b, g, _, h;
|
|
210
207
|
return {
|
|
211
|
-
id:
|
|
212
|
-
src: (s = (a =
|
|
213
|
-
width: (b = (v = (l =
|
|
214
|
-
height: (h = (_ = (g =
|
|
208
|
+
id: n == null ? void 0 : n.id,
|
|
209
|
+
src: (s = (a = n == null ? void 0 : n.media_formats) == null ? void 0 : a.gif) == null ? void 0 : s.url,
|
|
210
|
+
width: (b = (v = (l = n == null ? void 0 : n.media_formats) == null ? void 0 : l.gif) == null ? void 0 : v.dims) == null ? void 0 : b[0],
|
|
211
|
+
height: (h = (_ = (g = n == null ? void 0 : n.media_formats) == null ? void 0 : g.gif) == null ? void 0 : _.dims) == null ? void 0 : h[1]
|
|
215
212
|
};
|
|
216
213
|
});
|
|
217
214
|
}
|
|
@@ -221,19 +218,19 @@ function le(e, t) {
|
|
|
221
218
|
searchWord: async (i) => t ? e === "giphy" ? oe(i, t) : e === "tenor" ? de(i, t) : [] : []
|
|
222
219
|
};
|
|
223
220
|
}
|
|
224
|
-
function he({ selectImage: e, apiKey: t, provider:
|
|
225
|
-
const [i,
|
|
226
|
-
|
|
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
|
+
$(() => {
|
|
227
224
|
(async () => {
|
|
228
225
|
const h = await b();
|
|
229
226
|
s(h);
|
|
230
227
|
})();
|
|
231
228
|
}, []);
|
|
232
229
|
const _ = M(
|
|
233
|
-
|
|
230
|
+
J(async (h) => {
|
|
234
231
|
if (!h.target.value) {
|
|
235
|
-
const
|
|
236
|
-
s(
|
|
232
|
+
const I = await b();
|
|
233
|
+
s(I);
|
|
237
234
|
return;
|
|
238
235
|
}
|
|
239
236
|
const y = await g(h.target.value);
|
|
@@ -242,18 +239,18 @@ function he({ selectImage: e, apiKey: t, provider: n, children: c }) {
|
|
|
242
239
|
// Adjust the debounce delay as needed
|
|
243
240
|
[]
|
|
244
241
|
);
|
|
245
|
-
return /* @__PURE__ */
|
|
242
|
+
return /* @__PURE__ */ P(ne, { modal: !0, onOpenChange: n, open: i, children: [
|
|
246
243
|
/* @__PURE__ */ u(re, { asChild: !0, disabled: l, children: c }),
|
|
247
244
|
/* @__PURE__ */ u(
|
|
248
|
-
|
|
245
|
+
ie,
|
|
249
246
|
{
|
|
250
247
|
align: "start",
|
|
251
248
|
className: "richtext-size-full richtext-p-2",
|
|
252
249
|
hideWhenDetached: !0,
|
|
253
250
|
side: "bottom",
|
|
254
|
-
children: t ? /* @__PURE__ */
|
|
251
|
+
children: t ? /* @__PURE__ */ P(K, { children: [
|
|
255
252
|
/* @__PURE__ */ u("div", { className: "richtext-mb-[10px] richtext-w-full", children: /* @__PURE__ */ u(
|
|
256
|
-
|
|
253
|
+
U,
|
|
257
254
|
{
|
|
258
255
|
onChange: _,
|
|
259
256
|
placeholder: "Search GIF",
|
|
@@ -268,7 +265,7 @@ function he({ selectImage: e, apiKey: t, provider: n, children: c }) {
|
|
|
268
265
|
className: "richtext-cursor-pointer richtext-object-contain richtext-text-center",
|
|
269
266
|
src: h.src,
|
|
270
267
|
onClick: () => {
|
|
271
|
-
e(h.src),
|
|
268
|
+
e(h.src), n(!1);
|
|
272
269
|
}
|
|
273
270
|
},
|
|
274
271
|
h.id
|
|
@@ -278,13 +275,13 @@ function he({ selectImage: e, apiKey: t, provider: n, children: c }) {
|
|
|
278
275
|
)
|
|
279
276
|
] });
|
|
280
277
|
}
|
|
281
|
-
function
|
|
282
|
-
const e =
|
|
283
|
-
return /* @__PURE__ */ u(he, { apiKey: i, provider:
|
|
278
|
+
function ye() {
|
|
279
|
+
const e = Y(ue.name), { action: t, icon: r, tooltip: c, apiKey: i, provider: n } = (e == null ? void 0 : e.componentProps) ?? {}, { editorDisabled: a } = D();
|
|
280
|
+
return /* @__PURE__ */ u(he, { apiKey: i, provider: n, selectImage: (l) => {
|
|
284
281
|
a || t && t(l);
|
|
285
|
-
}, children: /* @__PURE__ */ u(
|
|
282
|
+
}, children: /* @__PURE__ */ u(Z, { disabled: a, icon: r, tooltip: c }) });
|
|
286
283
|
}
|
|
287
|
-
const ue = /* @__PURE__ */
|
|
284
|
+
const ue = /* @__PURE__ */ Q.extend({
|
|
288
285
|
name: "imageGif",
|
|
289
286
|
//@ts-expect-error
|
|
290
287
|
addOptions() {
|
|
@@ -300,9 +297,9 @@ const ue = /* @__PURE__ */ Y.extend({
|
|
|
300
297
|
draggable: !1,
|
|
301
298
|
selectable: !0,
|
|
302
299
|
atom: !0,
|
|
303
|
-
button: ({ editor: t, extension:
|
|
300
|
+
button: ({ editor: t, extension: r, t: c }) => {
|
|
304
301
|
var a, s;
|
|
305
|
-
const i = ((a =
|
|
302
|
+
const i = ((a = r == null ? void 0 : r.options) == null ? void 0 : a.provider) || "", n = ((s = r == null ? void 0 : r.options) == null ? void 0 : s.API_KEY) || "";
|
|
306
303
|
return {
|
|
307
304
|
componentProps: {
|
|
308
305
|
action: (l) => {
|
|
@@ -312,7 +309,7 @@ const ue = /* @__PURE__ */ Y.extend({
|
|
|
312
309
|
disabled: !1,
|
|
313
310
|
icon: "GifIcon",
|
|
314
311
|
tooltip: c("editor.imageGif.tooltip"),
|
|
315
|
-
apiKey:
|
|
312
|
+
apiKey: n,
|
|
316
313
|
provider: i
|
|
317
314
|
}
|
|
318
315
|
};
|
|
@@ -326,8 +323,8 @@ const ue = /* @__PURE__ */ Y.extend({
|
|
|
326
323
|
width: {
|
|
327
324
|
default: null,
|
|
328
325
|
parseHTML: (t) => {
|
|
329
|
-
const
|
|
330
|
-
return
|
|
326
|
+
const r = t.style.width || t.getAttribute("width") || "10";
|
|
327
|
+
return r === void 0 ? null : Number.parseInt(`${r}`, 10);
|
|
331
328
|
},
|
|
332
329
|
renderHTML: (t) => ({
|
|
333
330
|
width: t.width
|
|
@@ -349,12 +346,12 @@ const ue = /* @__PURE__ */ Y.extend({
|
|
|
349
346
|
var e;
|
|
350
347
|
return {
|
|
351
348
|
...(e = this.parent) == null ? void 0 : e.call(this),
|
|
352
|
-
setImageGif: (t) => ({ commands:
|
|
349
|
+
setImageGif: (t) => ({ commands: r }) => r.insertContent({
|
|
353
350
|
type: this.name,
|
|
354
351
|
attrs: t
|
|
355
352
|
}),
|
|
356
|
-
updateImageGif: (t) => ({ commands:
|
|
357
|
-
setAlignImageGif: (t) => ({ commands:
|
|
353
|
+
updateImageGif: (t) => ({ commands: r }) => r.updateAttributes(this.name, t),
|
|
354
|
+
setAlignImageGif: (t) => ({ commands: r }) => r.updateAttributes(this.name, { align: t })
|
|
358
355
|
};
|
|
359
356
|
},
|
|
360
357
|
renderHTML({ HTMLAttributes: e }) {
|
|
@@ -384,12 +381,12 @@ const ue = /* @__PURE__ */ Y.extend({
|
|
|
384
381
|
{
|
|
385
382
|
tag: "div[class=imageGIf]",
|
|
386
383
|
getAttrs: (e) => {
|
|
387
|
-
const t = e.querySelector("img"),
|
|
384
|
+
const t = e.querySelector("img"), r = t == null ? void 0 : t.getAttribute("width");
|
|
388
385
|
return {
|
|
389
386
|
src: t == null ? void 0 : t.getAttribute("src"),
|
|
390
387
|
alt: t == null ? void 0 : t.getAttribute("alt"),
|
|
391
388
|
title: t == null ? void 0 : t.getAttribute("title"),
|
|
392
|
-
width:
|
|
389
|
+
width: r ? Number.parseInt(r, 10) : null,
|
|
393
390
|
align: (t == null ? void 0 : t.getAttribute("align")) || e.style.textAlign || null
|
|
394
391
|
};
|
|
395
392
|
}
|
|
@@ -399,5 +396,5 @@ const ue = /* @__PURE__ */ Y.extend({
|
|
|
399
396
|
});
|
|
400
397
|
export {
|
|
401
398
|
ue as ImageGif,
|
|
402
|
-
|
|
399
|
+
ye as RichTextImageGif
|
|
403
400
|
};
|
package/lib/ImportWord.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("./clsx-CXbNJWDD.cjs"),u=require("react/jsx-runtime"),H=require("mammoth"),A=require("react"),s=require("./index-Dib4cXXf.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;
|
package/lib/ImportWord.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { E as M } from "./clsx-
|
|
1
|
+
import { E as M } from "./clsx-CDyrfCnw.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 {
|
|
6
|
-
import
|
|
7
|
-
import { f as U, u as q, c as G, i as J, j as Q } from "./useButtonProps-BE10eHkG.js";
|
|
5
|
+
import { h as q, u as z, d as D, q as K, r as U, A as G, s as J, t as Q } from "./index-_WrFM-Fk.js";
|
|
6
|
+
import "./theme.js";
|
|
8
7
|
import { u as V } from "./index-4Q5IhypJ.js";
|
|
9
8
|
function X(e, t) {
|
|
10
9
|
const s = atob(e.split(",")[1]), c = Array.from({ length: s.length });
|
|
@@ -16,8 +15,8 @@ function X(e, t) {
|
|
|
16
15
|
function Y(e, t) {
|
|
17
16
|
return new File([e], t, { type: e.type });
|
|
18
17
|
}
|
|
19
|
-
function
|
|
20
|
-
const e =
|
|
18
|
+
function it() {
|
|
19
|
+
const e = q(), t = z(w.name), {
|
|
21
20
|
icon: s = void 0,
|
|
22
21
|
tooltip: c = void 0,
|
|
23
22
|
tooltipOptions: l = {},
|
|
@@ -25,12 +24,12 @@ function st() {
|
|
|
25
24
|
mammothOptions: T,
|
|
26
25
|
limit: x,
|
|
27
26
|
convert: h
|
|
28
|
-
} = (t == null ? void 0 : t.componentProps) ?? {}, { editorDisabled: C } =
|
|
29
|
-
function
|
|
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() {
|
|
30
29
|
var o;
|
|
31
30
|
(o = b.current) == null || o.click();
|
|
32
31
|
}
|
|
33
|
-
function
|
|
32
|
+
function O(o) {
|
|
34
33
|
const n = o.target.files[0];
|
|
35
34
|
if (n) {
|
|
36
35
|
if (n.size > x) {
|
|
@@ -40,24 +39,24 @@ function st() {
|
|
|
40
39
|
});
|
|
41
40
|
return;
|
|
42
41
|
}
|
|
43
|
-
|
|
42
|
+
j(n);
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
async function
|
|
45
|
+
async function S(o) {
|
|
47
46
|
const a = new DOMParser().parseFromString(o, "text/html"), p = a.querySelectorAll("img");
|
|
48
47
|
if (p.length === 0)
|
|
49
48
|
return a.body.innerHTML;
|
|
50
|
-
if (
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
49
|
+
if (J(e, Q.name)) {
|
|
50
|
+
const d = u == null ? void 0 : u.options;
|
|
51
|
+
if (d && typeof d.upload == "function") {
|
|
53
52
|
const A = [];
|
|
54
|
-
for (const
|
|
55
|
-
const m =
|
|
53
|
+
for (const f of p) {
|
|
54
|
+
const m = f.getAttribute("src"), r = X(m, "image/jpeg"), H = Y(r, "image.jpeg");
|
|
56
55
|
A.push(H);
|
|
57
56
|
}
|
|
58
|
-
const F = await
|
|
59
|
-
for (const [
|
|
60
|
-
m.setAttribute("src", F[
|
|
57
|
+
const F = await d.upload(A);
|
|
58
|
+
for (const [f, m] of p.entries()) {
|
|
59
|
+
m.setAttribute("src", F[f].src);
|
|
61
60
|
const r = m.parentElement;
|
|
62
61
|
(r == null ? void 0 : r.tagName) === "P" && (r.insertAdjacentElement("beforebegin", m), !r.hasChildNodes() && r.textContent === "" && r.remove());
|
|
63
62
|
}
|
|
@@ -67,7 +66,7 @@ function st() {
|
|
|
67
66
|
} else
|
|
68
67
|
return console.error("Image extension not found, unable to convert image"), a.body.innerHTML;
|
|
69
68
|
}
|
|
70
|
-
async function
|
|
69
|
+
async function j(o) {
|
|
71
70
|
y(!0);
|
|
72
71
|
try {
|
|
73
72
|
if (h) {
|
|
@@ -82,17 +81,17 @@ function st() {
|
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
async function v(o) {
|
|
85
|
-
const n = await
|
|
84
|
+
const n = await S(o);
|
|
86
85
|
e.chain().setContent(n, !0).run();
|
|
87
86
|
}
|
|
88
87
|
return t ? /* @__PURE__ */ P(I, { children: [
|
|
89
88
|
/* @__PURE__ */ g(
|
|
90
|
-
|
|
89
|
+
G,
|
|
91
90
|
{
|
|
92
|
-
action:
|
|
91
|
+
action: L,
|
|
93
92
|
disabled: C,
|
|
94
93
|
icon: s,
|
|
95
|
-
loading:
|
|
94
|
+
loading: B,
|
|
96
95
|
tooltip: c,
|
|
97
96
|
tooltipOptions: l
|
|
98
97
|
}
|
|
@@ -101,7 +100,7 @@ function st() {
|
|
|
101
100
|
"input",
|
|
102
101
|
{
|
|
103
102
|
accept: ".docx",
|
|
104
|
-
onChange:
|
|
103
|
+
onChange: O,
|
|
105
104
|
ref: b,
|
|
106
105
|
type: "file",
|
|
107
106
|
style: {
|
|
@@ -142,5 +141,5 @@ const w = /* @__PURE__ */ M.create({
|
|
|
142
141
|
});
|
|
143
142
|
export {
|
|
144
143
|
w as ImportWord,
|
|
145
|
-
|
|
144
|
+
it as RichTextImportWord
|
|
146
145
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const p=require("./clsx-CXbNJWDD.cjs"),l=require("@tiptap/pm/state"),c=require("react/jsx-runtime"),u=require("./index-Dib4cXXf.cjs");require("react");require("./theme.cjs");var a=(t=>(t[t.max=7]="max",t[t.min=0]="min",t[t.more=1]="more",t[t.less=-1]="less",t))(a||{});function b(t,e,n){return t<e?e:t>n?n:t}function T(t,e,n,o){const{doc:s,selection:r}=t;if(!s||!r||!(r instanceof l.TextSelection||r instanceof l.AllSelection))return t;const{from:i,to:d}=r;return s.nodesBetween(i,d,(m,x)=>{const I=m.type;return n.includes(I.name)?(t=h(t,x,e),!1):!p.isList(m.type.name,o.extensionManager.extensions)}),t}function h(t,e,n){if(!t.doc)return t;const o=t.doc.nodeAt(e);if(!o)return t;const i=b((o.attrs.indent||0)+n,0,7);if(i===o.attrs.indent)return t;const d={...o.attrs,indent:i};return t.setNodeMarkup(e,o.type,d,o.marks)}function f({delta:t,types:e}){return({state:n,dispatch:o,editor:s})=>{const{selection:r}=n;let{tr:i}=n;return i=i.setSelection(r),i=T(i,t,e,s),i.docChanged?(o&&o(i),!0):!1}}function A(){const t=u.useButtonProps(y.name),{indent:e,outdent:n}=(t==null?void 0:t.componentProps)??{},{editorDisabled:o}=u.useToggleActive(),s=()=>{o||e!=null&&e.action&&(e==null||e.action())},r=()=>{o||n!=null&&n.action&&(n==null||n.action())};return t?c.jsxs(c.Fragment,{children:[c.jsx(u.ActionButton,{action:s,disabled:o,icon:e==null?void 0:e.icon,shortcutKeys:e==null?void 0:e.shortcutKeys,tooltip:e==null?void 0:e.tooltip}),c.jsx(u.ActionButton,{action:r,disabled:o,icon:n==null?void 0:n.icon,shortcutKeys:n==null?void 0:n.shortcutKeys,tooltip:n==null?void 0:n.tooltip})]}):c.jsx(c.Fragment,{})}const y=p.Extension.create({name:"richtextIndentOutdent",addOptions(){var t;return{...(t=this.parent)==null?void 0:t.call(this),types:["paragraph","heading","blockquote"],minIndent:a.min,maxIndent:a.max,button({editor:e,t:n,extension:o}){var s,r;return{componentProps:{indent:{action:()=>{e.commands.indent()},shortcutKeys:((s=o.options.shortcutKeys)==null?void 0:s[0])??["Tab"],icon:"IndentIncrease",tooltip:n("editor.indent.tooltip")},outdent:{action:()=>{e.commands.outdent()},shortcutKeys:((r=o.options.shortcutKeys)==null?void 0:r[1])??["Shift","Tab"],icon:"IndentDecrease",tooltip:n("editor.outdent.tooltip")}}}}}},addGlobalAttributes(){return[{types:this.options.types,attributes:{indent:{default:0,parseHTML:t=>{const e=t.dataset.indent;return(e?Number.parseInt(e,10):0)||0},renderHTML:t=>t.indent?{"data-indent":t.indent}:{}}}}]},addCommands(){return{indent:()=>f({delta:a.more,types:this.options.types}),outdent:()=>f({delta:a.less,types:this.options.types})}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.indent(),"Shift-Tab":()=>this.editor.commands.outdent()}}});exports.Indent=y;exports.IndentProps=a;exports.RichTextIndent=A;exports.setNodeIndentMarkup=h;
|