wysimark-lite 0.25.19 → 0.25.20
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/dist/index.js +5 -3
- package/dist/index.mjs +10 -3
- package/dist/index.mjs.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
`;case"horizontal-rule":return`---
|
|
18
18
|
|
|
19
|
-
`;case"paragraph":
|
|
19
|
+
`;case"paragraph":{let o=G(e.children);return o===""?`\xA0
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
`:`${o}
|
|
22
|
+
|
|
23
|
+
`}case"table":return Vn(e);case"table-row":case"table-cell":case"table-content":throw new Error(`Table elements should only be present as children of table which should be handled by serializeTable. Got ${e.type} may indicate an error in normalization.`);case"unordered-list-item":return`${" ".repeat(e.depth*Ro)}- ${G(e.children)}
|
|
22
24
|
`;case"ordered-list-item":return`${" ".repeat(e.depth*Ro)}${t[e.depth]}. ${G(e.children)}
|
|
23
25
|
`;case"task-list-item":{let o=" ".repeat(e.depth*Ro),r=G(e.children);return r.trim()===""&&(r=" "),`${o}- [${e.checked?"x":" "}] ${r}
|
|
24
26
|
`}case"image-block":return Tn(e);case"image-inline":return``;case"code-block":return xn(e);case"code-block-line":throw new Error("Code block line elements should only be present as children of code-block which should be handled by serializeCodeBlock. Got code-block-line may indicate an error in normalization.");case"html-block":return`${e.html}
|
|
@@ -1472,4 +1474,4 @@
|
|
|
1472
1474
|
margin-top: 0.5em;
|
|
1473
1475
|
color: var(--shade-500);
|
|
1474
1476
|
line-height: 1.375;
|
|
1475
|
-
`;import{Fragment as zb,jsx as te,jsxs as vt}from"react/jsx-runtime";var Lb=wb("enter");function Yc({dest:e,close:t}){let o=Rb(),r=Mb(null),[n,i]=kt({x:0,y:0}),a=bo((E,k)=>{i(P=>({x:P.x+E,y:P.y+k}))},[]),l=j({src:r,dest:e},({src:E,dest:k},P)=>!E||!k?{left:0,top:0}:ke(E,P,{left:k.left-12,top:k.top+k.height},{margin:16})),m={...l,left:l.left+n.x,top:l.top+n.y},s=Ib(()=>{let{selection:E}=o;return E&&!Cb.isCollapsed(E)?Pb.string(o,E):""},[]),[c,d]=kt(""),[p,u]=kt(s),[g,T]=kt(s),[S,L]=kt(!1),M=()=>{let E=p.trim()||c,k=g.trim()||void 0;o.anchor.insertLink(c,E,{select:!0,title:k}),Sb.focus(o),t()},N=bo(E=>{d(E.currentTarget.value)},[d]),w=bo(E=>{let k=E.currentTarget.value;u(k),S||T(k)},[u,T,S]),z=bo(E=>{T(E.currentTarget.value),L(!0)},[T]),I=E=>{Lb(E)&&(E.preventDefault(),E.stopPropagation(),M())};return vt(zb,{children:[te(ye,{close:t}),vt(Oi,{ref:r,style:m,children:[te(Te,{onDrag:a}),vt("div",{style:{padding:"0.75em"},children:[te(At,{children:te(Ot,{type:"text",value:c,autoFocus:!0,placeholder:h("linkUrl"),onChange:N,onKeyDown:I})}),te(At,{style:{marginTop:"0.5em"},children:te(Ot,{type:"text",value:p,placeholder:h("linkText"),onChange:w,onKeyDown:I})}),vt(At,{style:{marginTop:"0.5em"},children:[te(Ot,{type:"text",value:g,placeholder:h("tooltipText"),onChange:z,onKeyDown:I}),vt(Cr,{onClick:M,children:[te(go,{}),te(Tc,{})]}),te(Cr,{onClick:t,style:{marginLeft:"0.25em",background:"var(--shade-400)"},children:te(Fc,{})})]}),te(jc,{children:h("tooltipHint")})]})]})]})}var Sr=[{icon:go,title:h("insertLink"),more:!0,hotkey:"mod+k",Component:Yc},{icon:Dc,title:h("insertImageFromUrl"),more:!0,Component:Qc},{icon:Lc,title:h("insertTable"),more:!0,Component:yc},{icon:Kc,title:h("horizontalRule"),hotkey:"super+-",action:e=>e.horizontalRule.insertHorizontalRule()}],Jc=Sr,Zc=Sr,ep=[{icon:Nc,title:h("insert"),more:!0,children:Sr}];import{Editor as Bb}from"slate";function tt(e){let t=Bb.marks(e);return{bold:t?.bold||!1,italic:t?.italic||!1,strike:t?.strike||!1,code:t?.code||!1,underline:t?.underline||!1,highlight:t?.highlight||!1}}var tp=[{icon:vr,title:h("bold"),hotkey:"mod+b",action:e=>e.marksPlugin.toggleBold(),active:e=>tt(e).bold},{icon:Cc,title:h("italic"),hotkey:"mod+i",action:e=>e.marksPlugin.toggleItalic(),active:e=>tt(e).italic},{icon:$c,title:h("strike"),hotkey:"super+k",action:e=>e.marksPlugin.toggleStrike(),active:e=>tt(e).strike},{icon:zc,title:h("inlineCode"),hotkey:"mod+j",action:e=>e.inlineCode.toggleInlineCode(),active:e=>tt(e).code},{icon:Hc,title:h("underline"),hotkey:"mod+u",action:e=>e.marksPlugin.toggleUnderline(),active:e=>tt(e).underline},{icon:Vc,title:h("highlight"),hotkey:"mod+h",action:e=>e.marksPlugin.toggleHighlight(),active:e=>tt(e).highlight,show:e=>!e.wysimark.disableHighlight}],Rr=tp,op=[{icon:vr,title:h("format"),more:!0,children:tp}];var rp=[{icon:Rc,title:h("bulletList"),hotkey:"super+8",action:e=>e.list.convertUnorderedList(!0)},{icon:wr,title:h("numberedList"),hotkey:"super+7",action:e=>e.list.convertOrderedList(!0)},{icon:Ac,title:h("checkList"),hotkey:"super+9",action:e=>e.list.convertTaskList(!0),show:e=>!e.wysimark.disableTaskList}],Lr=[...rp,"divider",...Ir],np=[{icon:wr,title:h("list"),more:!0,children:[...rp,"divider",...Ir]}];import{Editor as ip,Path as Db,Transforms as Eo}from"slate";var ap=[{icon:Tr,title:h("quote"),hotkey:"super+.",action:e=>{e.blockQuotePlugin.isActive()?e.blockQuotePlugin.outdent():e.blockQuotePlugin.indent()},active:e=>e.blockQuotePlugin.isActive()},{icon:Sc,title:h("increaseQuoteDepth"),action:e=>e.blockQuotePlugin.increaseDepth(),active:e=>e.blockQuotePlugin.canIncreaseDepth()},{icon:Bc,title:h("codeBlock"),action:e=>{let{selection:t}=e,o=x(e,"code-block");if(o){let[,r]=o,n=ip.string(e,r);Eo.removeNodes(e,{at:r}),Eo.insertNodes(e,{type:"paragraph",children:[{text:n}]},{at:r});return}if(t&&!Db.equals(t.anchor.path,t.focus.path)){e.codeBlock.createCodeBlock({language:"text"});return}if(t&&t.anchor.offset!==t.focus.offset){let r=ip.string(e,t);Eo.delete(e),Eo.insertNodes(e,{type:"code-block",language:"text",children:[{type:"code-block-line",children:[{text:r}]}]});return}e.codeBlock.createCodeBlock({language:"text"})},active:e=>!!x(e,"code-block"),show:e=>!e.wysimark.disableCodeBlock}],zr=ap,lp=[{icon:Tr,title:h("quote"),more:!0,children:ap}];var Nb=[...Wc,"divider",...Lr,"divider",...Rr,"divider",...Jc,"divider",...zr],$b=[...Mr,"divider",...Lr,"divider",...Rr,"divider",...Zc,"divider",...zr],sp=[...Mr,"divider",...np,"divider",...op,"divider",...ep,"divider",...lp],mp=sp;var ot=[Nb,$b,sp];import{clsx as Hb}from"clsx";import{useCallback as Br,useRef as Ab}from"react";import{ReactEditor as Ob,useSlate as Ub,useSlateStatic as Fb}from"slate-react";import{jsx as xo,jsxs as Vb}from"react/jsx-runtime";function cp({item:e}){let t=Fb(),o=Ub(),r=e.active?e.active(o):!1,n=Ab(null),i=J({title:e.title,hotkey:()=>e.hotkey?$t(e.hotkey):void 0}),a=O("menu"),l=Br(()=>{let c=n.current,d=e.children,p=e.Component;c&&(d?a.open(()=>xo(Ue,{dest:c,items:d,close:a.close})):p&&a.open(()=>xo(p,{dest:c,close:a.close})))},[e]),m=Br(()=>{if(e.action){e.action(t),Ob.focus(t);return}a.layer?a.close():l()},[a.layer,e]),s=Br(c=>{i.onMouseEnter(c),a.layer&&l()},[a.layer,l,i.onMouseEnter]);return Vb(Yi,{"data-item-type":"button",ref:n,onMouseEnter:s,onMouseLeave:i.onMouseLeave,onClick:m,className:Hb({"--active":r&&!zo(e?.title)?.includes("Depth"),"--more":e.more,"--disabled":!r&&zo(e?.title)?.includes("Depth")}),children:[xo(e.icon,{}),e.more?xo(vc,{}):null]})}import{jsx as rt}from"react/jsx-runtime";function qb({item:e}){let t=Gb();return e==="divider"?rt(Xi,{"data-item-type":"divider",children:rt(ji,{})}):(e.show===void 0?!0:e.show(t))?rt(cp,{item:e}):null}function Qb(e){let t=e.querySelector("[data-item-type=button]"),o=e.querySelector("[data-item-type=divider]");return!t||!o?null:{toolbar:e.offsetWidth,button:t.offsetWidth,divider:o.offsetWidth}}function Xb(e,t,o){let r=0;for(let n of e)r+=n==="divider"?o:t;return r}var jb=4;function pp(){let e=_b(null),[t,o]=Wb(mp);return Kb(()=>{let r=e.current;if(!r)return;let n=()=>{let a=Qb(r);if(a){for(let l=0;l<ot.length-1;l++)if(Xb(ot[l],a.button,a.divider)<a.toolbar-jb){o(ot[l]);return}o(ot[ot.length-1])}},i=new ResizeObserver(n);return i.observe(r),()=>{i.disconnect()}},[]),rt(qi,{ref:e,children:rt(Qi,{children:t.map((r,n)=>rt(qb,{item:r},typeof r=="string"?n:r.title))})})}import{jsx as Dr,jsxs as iE}from"react/jsx-runtime";function dp({attributes:e,Editable:t}){let o=Zb(null),r=nE(),n=rE(),i=Jb(a=>{a.target===a.currentTarget&&(tE.select(r,eE.end(r,[])),oE.focus(r))},[r]);return Dr(zi,{children:iE(Ki,{ref:o,className:Yb({"--focused":n}),style:{height:r.toolbar.height,minHeight:r.toolbar.minHeight,maxHeight:r.toolbar.maxHeight},onClick:i,children:[Dr(pp,{}),Dr(t,{as:Vi,...e,style:{overflowY:"auto"}})]})})}var up=v((e,t)=>(e.toolbar={height:t.toolbar?.height,minHeight:t.toolbar?.minHeight,maxHeight:t.toolbar?.maxHeight,showUploadButtons:t.toolbar?.showUploadButtons??!0},{name:"toolbar",editor:{},renderEditable:dp,editableProps:{}}));import{Editor as Nr,Node as aE,Path as lE,Transforms as sE}from"slate";var fp=v(e=>(e.allowTrailingBlock=!0,{name:"trailing-block",editor:{normalizeNode:t=>{if(!Nr.isEditor(t[0]))return!1;let o=[e.children.length-1],r=aE.child(e,e.children.length-1);return(Nr.hasBlocks(e,r)||Nr.isVoid(e,r))&&sE.insertNodes(e,{type:"paragraph",children:[{text:""}]},{at:lE.next(o)}),!0}}}));import{Transforms as mE}from"slate";function cE(e,t){let o=ge(t),r=Ee(o);mE.insertNodes(e,r)}function hp(e){return{pasteMarkdown:f(cE,e)}}var gp=v(e=>(e.pasteMarkdown=hp(e),{name:"paste-markdown",editor:{},editableProps:{onPaste(t){let{types:o}=t.clipboardData;if(o.length!==1||o[0]!=="text/plain")return!1;let r=t.clipboardData.getData("text/plain");return e.pasteMarkdown.pasteMarkdown(r),Me(t),!0}}}));import{jsx as dE}from"react/jsx-runtime";function pE(e){let t={...e.attributes,style:{...e.attributes.style,width:void 0,maxWidth:void 0}};return dE("span",{...t,children:e.children})}var bp=v((e,t,{createPolicy:o})=>(e.placeholder={},o({name:"placeholder",editableProps:{renderPlaceholder:pE}})));var Ep=[gp,ps,Ea,ks,sm,Ls,El,Kl,Xl,pc,Ps,fp,rm,va,pm,ns,fc,up,hl,bp];var uE=ri(Ep),{withSink:xp,SinkEditable:yp}=uE;import{useState as fE}from"react";import{createEditor as hE,Editor as gE,Transforms as bE}from"slate";import{withHistory as EE}from"slate-history";import{withReact as xE}from"slate-react";function $r({authToken:e,height:t,minHeight:o,maxHeight:r,disableRawMode:n,disableTaskList:i,disableCodeBlock:a,disableHighlight:l}={}){let[m]=fE(()=>{let s=hE(),c=xp(xE(EE(s)),{toolbar:{height:t,minHeight:o,maxHeight:r,showUploadButtons:!!e},image:{}});return c.convertElement.addConvertElementType("paragraph"),s.wysimark={disableRawMode:n??!0,disableTaskList:i,disableCodeBlock:a,disableHighlight:l??!0},s.getMarkdown=()=>st(s.children),s.setMarkdown=d=>{let p=ge(d),u=Ee(p);s.children=u,s.selection=null,bE.select(s,gE.start(s,[0]))},c});return m}import{jsx as oe,jsxs as vp}from"react/jsx-runtime";function IE({children:e,attributes:t}){return oe("span",{...t,children:e})}function Tp({editor:e,value:t,onChange:o,throttleInMs:r=1e3,placeholder:n,className:i,style:a,onImageChange:l,onFileSelect:m}){let[s,c]=kp(!1),[d,p]=kp(t),u=wt(!1),g=wt(void 0),T=wt(void 0),S=wt(null),L=wt(o);L.current=o;let M=Tt(yE(()=>{let C=st(e.children);e.wysimark.prevValue={markdown:C,children:e.children},L.current(C)},r,{leading:!1,trailing:!0}),[e,r]),N=Tt(()=>{T.current!==e.children&&(T.current=e.children,M())},[M]);if(!s){let C=S.current??t;if(S.current!==null&&(S.current=null),e.wysimark.prevValue==null||g.current==null){u.current=!0;let se=ge(C),fe=Ee(se);e.children=fe,T.current=g.current=fe,e.wysimark.prevValue={markdown:C,children:fe}}else if(C!==e.wysimark.prevValue.markdown){u.current=!0;let se=ge(C),fe=Ee(se);e.children=fe,e.selection=null,vE.select(e,kE.start(e,[0]))}}let w=Tt(()=>{navigator.userAgent.toLowerCase().includes("firefox")&&TE.focus(e)},[e]),z=Tt(()=>{M.flush()},[M]),I=C=>{let se=C.target.value;p(se),o(se)},E=Tt(()=>{let C=e.getMarkdown();p(C)},[e]),k=()=>{s?(S.current=d,e.wysimark.prevValue=void 0,g.current=void 0,T.current=void 0):E(),c(!s)};e.wysimark.onImageChange=l,e.wysimark.onFileSelect=m,e.wysimark.onChange=o;let P=e.wysimark.disableRawMode;return vp("div",{style:{position:"relative"},children:[!P&&oe("div",{style:{position:"absolute",top:"5px",right:"25px",zIndex:10},children:oe("div",{onClick:k,style:{background:"none",border:s?"1px solid #4a90e2":"1px solid transparent",cursor:"pointer",padding:"6px",borderRadius:"4px",backgroundColor:s?"rgba(74, 144, 226, 0.1)":"transparent",boxShadow:s?"0 1px 3px rgba(0, 0, 0, 0.1)":"none",transition:"all 0.2s ease-in-out",display:"flex",alignItems:"center",justifyContent:"center"},title:s?h("switchToVisualEditor"):h("switchToRawMarkdown"),role:"button",tabIndex:0,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(k(),C.preventDefault())},children:vp("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[oe("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:s?"#4a90e2":"currentColor",strokeWidth:"1.5",fill:s?"rgba(74, 144, 226, 0.05)":"transparent"}),oe("path",{d:"M7 15V9L10 12L13 9V15",stroke:s?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),oe("path",{d:"M16 9H18V15",stroke:s?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),oe("path",{d:"M16 12H18",stroke:s?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})})}),oe("div",{style:{display:s?"block":"none",textAlign:"center"},children:oe("textarea",{value:nt(d).replace(/ /g,""),onChange:I,placeholder:n,className:i,style:{width:"calc(100% - 60px)",margin:"0 auto",minHeight:"200px",padding:"20px",fontFamily:"monospace",fontSize:"1rem",color:"#333",lineHeight:"1.5",backgroundColor:"#fff",border:"1px solid #ddd",borderRadius:"4px",...a}})}),oe("div",{style:{display:s?"none":"block"},children:oe(wE,{editor:e,initialValue:g.current,onChange:N,children:oe(yp,{renderLeaf:IE,onMouseDown:w,onBlur:z,placeholder:n,className:i,style:a})})})]})}import{jsx as wp}from"react/jsx-runtime";function zE({standaloneOptions:{onChange:e,placeholder:t,className:o,...r},standaloneMethodsRef:n}){let[i,a]=RE(r.initialMarkdown||""),l=SE(i),m=$r(r);l.current=i,CE(n,()=>({getMarkdown(){return l.current},setMarkdown(c){l.current=c,a(c)}}),[l,a]);let s=PE(c=>{l.current=c,a(c),e?.(c)},[m]);return wp(Tp,{editor:m,value:i,className:o||"",onChange:s,placeholder:t})}function BA(e,t){let o=ME(),r=LE(e);return r.render(wp(zE,{standaloneMethodsRef:o,standaloneOptions:t})),{unmount(){try{r.unmount()}catch{}},getMarkdown(){return o.current?.getMarkdown()||""},setMarkdown(n){o.current?.setMarkdown(n)}}}export{Tp as Editable,BA as createWysimark,$r as useEditor};
|
|
1477
|
+
`;import{Fragment as zb,jsx as te,jsxs as vt}from"react/jsx-runtime";var Lb=wb("enter");function Yc({dest:e,close:t}){let o=Rb(),r=Mb(null),[n,i]=kt({x:0,y:0}),a=bo((E,k)=>{i(P=>({x:P.x+E,y:P.y+k}))},[]),l=j({src:r,dest:e},({src:E,dest:k},P)=>!E||!k?{left:0,top:0}:ke(E,P,{left:k.left-12,top:k.top+k.height},{margin:16})),m={...l,left:l.left+n.x,top:l.top+n.y},s=Ib(()=>{let{selection:E}=o;return E&&!Cb.isCollapsed(E)?Pb.string(o,E):""},[]),[c,d]=kt(""),[p,u]=kt(s),[g,T]=kt(s),[S,L]=kt(!1),M=()=>{let E=p.trim()||c,k=g.trim()||void 0;o.anchor.insertLink(c,E,{select:!0,title:k}),Sb.focus(o),t()},N=bo(E=>{d(E.currentTarget.value)},[d]),w=bo(E=>{let k=E.currentTarget.value;u(k),S||T(k)},[u,T,S]),z=bo(E=>{T(E.currentTarget.value),L(!0)},[T]),I=E=>{Lb(E)&&(E.preventDefault(),E.stopPropagation(),M())};return vt(zb,{children:[te(ye,{close:t}),vt(Oi,{ref:r,style:m,children:[te(Te,{onDrag:a}),vt("div",{style:{padding:"0.75em"},children:[te(At,{children:te(Ot,{type:"text",value:c,autoFocus:!0,placeholder:h("linkUrl"),onChange:N,onKeyDown:I})}),te(At,{style:{marginTop:"0.5em"},children:te(Ot,{type:"text",value:p,placeholder:h("linkText"),onChange:w,onKeyDown:I})}),vt(At,{style:{marginTop:"0.5em"},children:[te(Ot,{type:"text",value:g,placeholder:h("tooltipText"),onChange:z,onKeyDown:I}),vt(Cr,{onClick:M,children:[te(go,{}),te(Tc,{})]}),te(Cr,{onClick:t,style:{marginLeft:"0.25em",background:"var(--shade-400)"},children:te(Fc,{})})]}),te(jc,{children:h("tooltipHint")})]})]})]})}var Sr=[{icon:go,title:h("insertLink"),more:!0,hotkey:"mod+k",Component:Yc},{icon:Dc,title:h("insertImageFromUrl"),more:!0,Component:Qc},{icon:Lc,title:h("insertTable"),more:!0,Component:yc},{icon:Kc,title:h("horizontalRule"),hotkey:"super+-",action:e=>e.horizontalRule.insertHorizontalRule()}],Jc=Sr,Zc=Sr,ep=[{icon:Nc,title:h("insert"),more:!0,children:Sr}];import{Editor as Bb}from"slate";function tt(e){let t=Bb.marks(e);return{bold:t?.bold||!1,italic:t?.italic||!1,strike:t?.strike||!1,code:t?.code||!1,underline:t?.underline||!1,highlight:t?.highlight||!1}}var tp=[{icon:vr,title:h("bold"),hotkey:"mod+b",action:e=>e.marksPlugin.toggleBold(),active:e=>tt(e).bold},{icon:Cc,title:h("italic"),hotkey:"mod+i",action:e=>e.marksPlugin.toggleItalic(),active:e=>tt(e).italic},{icon:$c,title:h("strike"),hotkey:"super+k",action:e=>e.marksPlugin.toggleStrike(),active:e=>tt(e).strike},{icon:zc,title:h("inlineCode"),hotkey:"mod+j",action:e=>e.inlineCode.toggleInlineCode(),active:e=>tt(e).code},{icon:Hc,title:h("underline"),hotkey:"mod+u",action:e=>e.marksPlugin.toggleUnderline(),active:e=>tt(e).underline},{icon:Vc,title:h("highlight"),hotkey:"mod+h",action:e=>e.marksPlugin.toggleHighlight(),active:e=>tt(e).highlight,show:e=>!e.wysimark.disableHighlight}],Rr=tp,op=[{icon:vr,title:h("format"),more:!0,children:tp}];var rp=[{icon:Rc,title:h("bulletList"),hotkey:"super+8",action:e=>e.list.convertUnorderedList(!0)},{icon:wr,title:h("numberedList"),hotkey:"super+7",action:e=>e.list.convertOrderedList(!0)},{icon:Ac,title:h("checkList"),hotkey:"super+9",action:e=>e.list.convertTaskList(!0),show:e=>!e.wysimark.disableTaskList}],Lr=[...rp,"divider",...Ir],np=[{icon:wr,title:h("list"),more:!0,children:[...rp,"divider",...Ir]}];import{Editor as ip,Path as Db,Transforms as Eo}from"slate";var ap=[{icon:Tr,title:h("quote"),hotkey:"super+.",action:e=>{e.blockQuotePlugin.isActive()?e.blockQuotePlugin.outdent():e.blockQuotePlugin.indent()},active:e=>e.blockQuotePlugin.isActive()},{icon:Sc,title:h("increaseQuoteDepth"),action:e=>e.blockQuotePlugin.increaseDepth(),active:e=>e.blockQuotePlugin.canIncreaseDepth()},{icon:Bc,title:h("codeBlock"),action:e=>{let{selection:t}=e,o=x(e,"code-block");if(o){let[,r]=o,n=ip.string(e,r);Eo.removeNodes(e,{at:r}),Eo.insertNodes(e,{type:"paragraph",children:[{text:n}]},{at:r});return}if(t&&!Db.equals(t.anchor.path,t.focus.path)){e.codeBlock.createCodeBlock({language:"text"});return}if(t&&t.anchor.offset!==t.focus.offset){let r=ip.string(e,t);Eo.delete(e),Eo.insertNodes(e,{type:"code-block",language:"text",children:[{type:"code-block-line",children:[{text:r}]}]});return}e.codeBlock.createCodeBlock({language:"text"})},active:e=>!!x(e,"code-block"),show:e=>!e.wysimark.disableCodeBlock}],zr=ap,lp=[{icon:Tr,title:h("quote"),more:!0,children:ap}];var Nb=[...Wc,"divider",...Lr,"divider",...Rr,"divider",...Jc,"divider",...zr],$b=[...Mr,"divider",...Lr,"divider",...Rr,"divider",...Zc,"divider",...zr],sp=[...Mr,"divider",...np,"divider",...op,"divider",...ep,"divider",...lp],mp=sp;var ot=[Nb,$b,sp];import{clsx as Hb}from"clsx";import{useCallback as Br,useRef as Ab}from"react";import{ReactEditor as Ob,useSlate as Ub,useSlateStatic as Fb}from"slate-react";import{jsx as xo,jsxs as Vb}from"react/jsx-runtime";function cp({item:e}){let t=Fb(),o=Ub(),r=e.active?e.active(o):!1,n=Ab(null),i=J({title:e.title,hotkey:()=>e.hotkey?$t(e.hotkey):void 0}),a=O("menu"),l=Br(()=>{let c=n.current,d=e.children,p=e.Component;c&&(d?a.open(()=>xo(Ue,{dest:c,items:d,close:a.close})):p&&a.open(()=>xo(p,{dest:c,close:a.close})))},[e]),m=Br(()=>{if(e.action){e.action(t),Ob.focus(t);return}a.layer?a.close():l()},[a.layer,e]),s=Br(c=>{i.onMouseEnter(c),a.layer&&l()},[a.layer,l,i.onMouseEnter]);return Vb(Yi,{"data-item-type":"button",ref:n,onMouseEnter:s,onMouseLeave:i.onMouseLeave,onClick:m,className:Hb({"--active":r&&!zo(e?.title)?.includes("Depth"),"--more":e.more,"--disabled":!r&&zo(e?.title)?.includes("Depth")}),children:[xo(e.icon,{}),e.more?xo(vc,{}):null]})}import{jsx as rt}from"react/jsx-runtime";function qb({item:e}){let t=Gb();return e==="divider"?rt(Xi,{"data-item-type":"divider",children:rt(ji,{})}):(e.show===void 0?!0:e.show(t))?rt(cp,{item:e}):null}function Qb(e){let t=e.querySelector("[data-item-type=button]"),o=e.querySelector("[data-item-type=divider]");return!t||!o?null:{toolbar:e.offsetWidth,button:t.offsetWidth,divider:o.offsetWidth}}function Xb(e,t,o){let r=0;for(let n of e)r+=n==="divider"?o:t;return r}var jb=4;function pp(){let e=_b(null),[t,o]=Wb(mp);return Kb(()=>{let r=e.current;if(!r)return;let n=()=>{let a=Qb(r);if(a){for(let l=0;l<ot.length-1;l++)if(Xb(ot[l],a.button,a.divider)<a.toolbar-jb){o(ot[l]);return}o(ot[ot.length-1])}},i=new ResizeObserver(n);return i.observe(r),()=>{i.disconnect()}},[]),rt(qi,{ref:e,children:rt(Qi,{children:t.map((r,n)=>rt(qb,{item:r},typeof r=="string"?n:r.title))})})}import{jsx as Dr,jsxs as iE}from"react/jsx-runtime";function dp({attributes:e,Editable:t}){let o=Zb(null),r=nE(),n=rE(),i=Jb(a=>{a.target===a.currentTarget&&(tE.select(r,eE.end(r,[])),oE.focus(r))},[r]);return Dr(zi,{children:iE(Ki,{ref:o,className:Yb({"--focused":n}),style:{height:r.toolbar.height,minHeight:r.toolbar.minHeight,maxHeight:r.toolbar.maxHeight},onClick:i,children:[Dr(pp,{}),Dr(t,{as:Vi,...e,style:{overflowY:"auto"}})]})})}var up=v((e,t)=>(e.toolbar={height:t.toolbar?.height,minHeight:t.toolbar?.minHeight,maxHeight:t.toolbar?.maxHeight,showUploadButtons:t.toolbar?.showUploadButtons??!0},{name:"toolbar",editor:{},renderEditable:dp,editableProps:{}}));import{Editor as Nr,Node as aE,Path as lE,Transforms as sE}from"slate";var fp=v(e=>(e.allowTrailingBlock=!0,{name:"trailing-block",editor:{normalizeNode:t=>{if(!Nr.isEditor(t[0]))return!1;let o=[e.children.length-1],r=aE.child(e,e.children.length-1);return(Nr.hasBlocks(e,r)||Nr.isVoid(e,r))&&sE.insertNodes(e,{type:"paragraph",children:[{text:""}]},{at:lE.next(o)}),!0}}}));import{Transforms as mE}from"slate";function cE(e,t){let o=ge(t),r=Ee(o);mE.insertNodes(e,r)}function hp(e){return{pasteMarkdown:f(cE,e)}}var gp=v(e=>(e.pasteMarkdown=hp(e),{name:"paste-markdown",editor:{},editableProps:{onPaste(t){let{types:o}=t.clipboardData;if(o.length!==1||o[0]!=="text/plain")return!1;let r=t.clipboardData.getData("text/plain");return e.pasteMarkdown.pasteMarkdown(r),Me(t),!0}}}));import{jsx as dE}from"react/jsx-runtime";function pE(e){let t={...e.attributes,style:{...e.attributes.style,width:void 0,maxWidth:void 0}};return dE("span",{...t,children:e.children})}var bp=v((e,t,{createPolicy:o})=>(e.placeholder={},o({name:"placeholder",editableProps:{renderPlaceholder:pE}})));var Ep=[gp,ps,Ea,ks,sm,Ls,El,Kl,Xl,pc,Ps,fp,rm,va,pm,ns,fc,up,hl,bp];var uE=ri(Ep),{withSink:xp,SinkEditable:yp}=uE;import{useState as fE}from"react";import{createEditor as hE,Editor as gE,Transforms as bE}from"slate";import{withHistory as EE}from"slate-history";import{withReact as xE}from"slate-react";function $r({authToken:e,height:t,minHeight:o,maxHeight:r,disableRawMode:n,disableTaskList:i,disableCodeBlock:a,disableHighlight:l}={}){let[m]=fE(()=>{let s=hE(),c=xp(xE(EE(s)),{toolbar:{height:t,minHeight:o,maxHeight:r,showUploadButtons:!!e},image:{}});return c.convertElement.addConvertElementType("paragraph"),s.wysimark={disableRawMode:n??!0,disableTaskList:i,disableCodeBlock:a,disableHighlight:l??!0},s.getMarkdown=()=>st(s.children),s.setMarkdown=d=>{let p=ge(d),u=Ee(p);s.children=u,s.selection=null,bE.select(s,gE.start(s,[0]))},c});return m}import{jsx as oe,jsxs as vp}from"react/jsx-runtime";function IE({children:e,attributes:t}){return oe("span",{...t,children:e})}function Tp({editor:e,value:t,onChange:o,throttleInMs:r=1e3,placeholder:n,className:i,style:a,onImageChange:l,onFileSelect:m}){let[s,c]=kp(!1),[d,p]=kp(t),u=wt(!1),g=wt(void 0),T=wt(void 0),S=wt(null),L=wt(o);L.current=o;let M=Tt(yE(()=>{let C=st(e.children);e.wysimark.prevValue={markdown:C,children:e.children},L.current(C)},r,{leading:!1,trailing:!0}),[e,r]),N=Tt(()=>{T.current!==e.children&&(T.current=e.children,M())},[M]);if(!s){let C=S.current??t;if(S.current!==null&&(S.current=null),e.wysimark.prevValue==null||g.current==null){u.current=!0;let se=ge(C),fe=Ee(se);e.children=fe,T.current=g.current=fe,e.wysimark.prevValue={markdown:C,children:fe}}else if(C!==e.wysimark.prevValue.markdown){u.current=!0;let se=ge(C),fe=Ee(se);e.children=fe,e.selection=null,vE.select(e,kE.start(e,[0]))}}let w=Tt(()=>{navigator.userAgent.toLowerCase().includes("firefox")&&TE.focus(e)},[e]),z=Tt(()=>{M.flush()},[M]),I=C=>{let se=C.target.value;p(se),o(se)},E=Tt(()=>{let C=e.getMarkdown();p(C)},[e]),k=()=>{s?(S.current=d,e.wysimark.prevValue=void 0,g.current=void 0,T.current=void 0):E(),c(!s)};e.wysimark.onImageChange=l,e.wysimark.onFileSelect=m,e.wysimark.onChange=o;let P=e.wysimark.disableRawMode;return vp("div",{style:{position:"relative"},children:[!P&&oe("div",{style:{position:"absolute",top:"5px",right:"25px",zIndex:10},children:oe("div",{onClick:k,style:{background:"none",border:s?"1px solid #4a90e2":"1px solid transparent",cursor:"pointer",padding:"6px",borderRadius:"4px",backgroundColor:s?"rgba(74, 144, 226, 0.1)":"transparent",boxShadow:s?"0 1px 3px rgba(0, 0, 0, 0.1)":"none",transition:"all 0.2s ease-in-out",display:"flex",alignItems:"center",justifyContent:"center"},title:s?h("switchToVisualEditor"):h("switchToRawMarkdown"),role:"button",tabIndex:0,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(k(),C.preventDefault())},children:vp("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[oe("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:s?"#4a90e2":"currentColor",strokeWidth:"1.5",fill:s?"rgba(74, 144, 226, 0.05)":"transparent"}),oe("path",{d:"M7 15V9L10 12L13 9V15",stroke:s?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),oe("path",{d:"M16 9H18V15",stroke:s?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),oe("path",{d:"M16 12H18",stroke:s?"#4a90e2":"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})})}),oe("div",{style:{display:s?"block":"none",textAlign:"center"},children:oe("textarea",{value:nt(d).replace(/ |\u00A0/g,""),onChange:I,placeholder:n,className:i,style:{width:"calc(100% - 60px)",margin:"0 auto",minHeight:"200px",padding:"20px",fontFamily:"monospace",fontSize:"1rem",color:"#333",lineHeight:"1.5",backgroundColor:"#fff",border:"1px solid #ddd",borderRadius:"4px",...a}})}),oe("div",{style:{display:s?"none":"block"},children:oe(wE,{editor:e,initialValue:g.current,onChange:N,children:oe(yp,{renderLeaf:IE,onMouseDown:w,onBlur:z,placeholder:n,className:i,style:a})})})]})}import{jsx as wp}from"react/jsx-runtime";function zE({standaloneOptions:{onChange:e,placeholder:t,className:o,...r},standaloneMethodsRef:n}){let[i,a]=RE(r.initialMarkdown||""),l=SE(i),m=$r(r);l.current=i,CE(n,()=>({getMarkdown(){return l.current},setMarkdown(c){l.current=c,a(c)}}),[l,a]);let s=PE(c=>{l.current=c,a(c),e?.(c)},[m]);return wp(Tp,{editor:m,value:i,className:o||"",onChange:s,placeholder:t})}function BA(e,t){let o=ME(),r=LE(e);return r.render(wp(zE,{standaloneMethodsRef:o,standaloneOptions:t})),{unmount(){try{r.unmount()}catch{}},getMarkdown(){return o.current?.getMarkdown()||""},setMarkdown(n){o.current?.setMarkdown(n)}}}export{Tp as Editable,BA as createWysimark,$r as useEditor};
|
package/dist/index.mjs
CHANGED
|
@@ -1556,10 +1556,17 @@ function serializeElement(element, orders) {
|
|
|
1556
1556
|
`;
|
|
1557
1557
|
case "horizontal-rule":
|
|
1558
1558
|
return "---\n\n";
|
|
1559
|
-
case "paragraph":
|
|
1560
|
-
|
|
1559
|
+
case "paragraph": {
|
|
1560
|
+
const content = serializeLine(element.children);
|
|
1561
|
+
if (content === "") {
|
|
1562
|
+
return `\xA0
|
|
1561
1563
|
|
|
1562
1564
|
`;
|
|
1565
|
+
}
|
|
1566
|
+
return `${content}
|
|
1567
|
+
|
|
1568
|
+
`;
|
|
1569
|
+
}
|
|
1563
1570
|
/**
|
|
1564
1571
|
* Table
|
|
1565
1572
|
*/
|
|
@@ -9716,7 +9723,7 @@ function Editable2({
|
|
|
9716
9723
|
/* @__PURE__ */ jsx67("div", { style: { display: isRawMode ? "block" : "none", textAlign: "center" }, children: /* @__PURE__ */ jsx67(
|
|
9717
9724
|
"textarea",
|
|
9718
9725
|
{
|
|
9719
|
-
value: unescapeUrlSlashes(rawText).replace(/ 
|
|
9726
|
+
value: unescapeUrlSlashes(rawText).replace(/ |\u00A0/g, ""),
|
|
9720
9727
|
onChange: handleRawTextChange,
|
|
9721
9728
|
placeholder,
|
|
9722
9729
|
className,
|