wysimark-lite 0.25.9 → 0.25.11
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 +7 -7
- package/dist/index.mjs +280 -498
- package/dist/index.mjs.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -968,7 +968,7 @@
|
|
|
968
968
|
`;import{jsx as Wl,jsxs as fh}from"react/jsx-runtime";function Gl({attributes:e,children:t,element:o}){return fh(Kl,{...e,contentEditable:!1,children:[Wl(_l,{children:"HTML"}),Wl("div",{children:ot(o.html)}),t]})}import{jsx as gh}from"react/jsx-runtime";var ql=k((e,t,{createPolicy:o})=>{function r(){let{selection:n}=e;if(!me(n))return!1;let i=E(e,"html-block");return i==null?!1:(hh.removeNodes(e,{at:i[1]}),!0)}return o({name:"html-block",editor:{deleteBackward:r,deleteForward:r,isInline(n){if(n.type==="html-block")return!1},isVoid(n){if(n.type==="html-block")return!0},isMaster(n){if(n.type==="html-block")return!0}},editableProps:{renderElement:({element:n,attributes:i,children:a})=>{if(n.type==="html-block")return gh(Gl,{element:n,attributes:i,children:a})}}})});import{Editor as ts}from"slate";import{Element as kh}from"slate";import{Element as bh,Transforms as Eh}from"slate";function Ql(e){return bh.isElement(e)&&e.type==="paragraph"}function Xl(e,t){return be(e,t,(o,r)=>!Ql(o[0])||!Ql(r[0])?!1:o[0].__collapsible&&r[0].__collapsible?(Eh.removeNodes(e,{at:o[1]}),!0):!1)}import{Element as xh,Transforms as yh}from"slate";function tr(e,t){return xh.isElement(t)?e.isVoid(t)||e.isMaster(t):!1}function jl(e,t){return tr(e,t[0])?be(e,t,(o,r)=>!tr(e,o[0])||!tr(e,r[0])?!1:(yh.insertNodes(e,{type:"paragraph",__collapsible:!0,children:[{text:""}]},{at:r[1]}),!0)):!1}function Yl(e,t){let[o,r]=t;return kh.isElement(o)?!!(jl(e,[o,r])||Xl(e,[o,r])):!1}import{clsx as wh}from"clsx";import{useSelected as Ih}from"slate-react";import vh from"@emotion/styled";var Jl=vh("p")`
|
|
969
969
|
padding: 0;
|
|
970
970
|
margin: 0;
|
|
971
|
-
&:first-
|
|
971
|
+
&:first-of-type {
|
|
972
972
|
margin-top: 0;
|
|
973
973
|
}
|
|
974
974
|
|
|
@@ -997,7 +997,7 @@
|
|
|
997
997
|
}
|
|
998
998
|
`;import{Node as Th}from"slate";function Zl(e){return e.children.length===1&&Th.string(e.children[0]).length===0}import{jsx as Mh}from"react/jsx-runtime";function es({element:e,attributes:t,children:o}){let r=Ih(),n=Zl(e);return Mh(Jl,{...t,className:wh({"--selected":r,"--empty":n,"--collapsible":!!e.__collapsible}),children:o})}import{jsx as Ph}from"react/jsx-runtime";var os=k(e=>{let{insertBreak:t}=e;if(e.insertBreak=()=>{let{selection:o}=e;if(o&&o.anchor.path[0]===o.focus.path[0]){let r=[o.anchor.path[0]],n=ts.start(e,r);ts.string(e,{anchor:n,focus:o.anchor}).endsWith(`
|
|
999
999
|
`)?t():e.insertText(`
|
|
1000
|
-
`)}else t()},e.convertElement.addConvertElementType("paragraph"),e.collapsibleParagraph={convertParagraph:()=>{e.convertElement.convertElements(()=>!1,{type:"paragraph"},!1)}},!e.normalizeAfterDelete)throw new Error("The collapsible-paragraph-plugin has a dependency on the normalize-after-delete plugin. Please add that plugin before this one.");return{name:"collapsible-paragraph",editor:{normalizeNode:f(Yl,e)},editableProps:{renderElement:({element:o,attributes:r,children:n})=>{
|
|
1000
|
+
`)}else t()},e.convertElement.addConvertElementType("paragraph"),e.collapsibleParagraph={convertParagraph:()=>{e.convertElement.convertElements(()=>!1,{type:"paragraph"},!1)}},!e.normalizeAfterDelete)throw new Error("The collapsible-paragraph-plugin has a dependency on the normalize-after-delete plugin. Please add that plugin before this one.");return{name:"collapsible-paragraph",editor:{normalizeNode:f(Yl,e)},editableProps:{renderElement:({element:o,attributes:r,children:n})=>{if(o.type==="paragraph")return Ph(es,{element:o,attributes:r,children:n})},onKeyDown:N({"super+0":e.collapsibleParagraph.convertParagraph})}}});function rs(e,t){Array.isArray(t)?e.convertElement.convertElementTypes.push(...t):e.convertElement.convertElementTypes.push(t)}import{Editor as _,Element as to,Node as ne,Point as _e,Range as Ch,Transforms as Ce}from"slate";function ns(e,t,o){try{let r=_.start(e,o),n=_.end(e,o);if(_e.isBefore(t,r)||_e.isAfter(t,n))return-1;let i={anchor:r,focus:t};return _.string(e,i).length}catch{return-1}}function is(e,t,o){try{let r=ne.get(e,t);if(!to.isElement(r))return;let n=ne.string(r),i=Math.min(o,n.length),a=_.start(e,t),l=0,s=a.path,m=0;for(let[d,p]of ne.texts(r)){let u=d.text.length;if(l+u>=i){s=[...t,...p],m=i-l;break}l+=u}let c={path:s,offset:m};Ce.select(e,{anchor:c,focus:c})}catch{}}function Sh(e){return ne.string(e).includes(`
|
|
1001
1001
|
`)}function Rh(e,t,o,r){let n=ne.string(t),i=n.split(`
|
|
1002
1002
|
`),a=_.start(e,o),l=_.end(e,o),s=_e.isBefore(r.anchor,a)?a:_e.isAfter(r.anchor,l)?l:r.anchor,m=_e.isBefore(r.focus,a)?a:_e.isAfter(r.focus,l)?l:r.focus,c=Math.min(_.string(e,{anchor:a,focus:s}).length,n.length),d=Math.min(_.string(e,{anchor:a,focus:m}).length,n.length),p=Math.min(c,d),u=Math.max(c,d),h=0,v=0,S=i.length-1;for(let P=0;P<i.length;P++){let M=h+i[P].length;if(h<=p&&p<=M&&(v=P),h<=u&&u<=M){S=P;break}h=M+1}return{startLineIndex:v,endLineIndex:S}}function Lh(e,t,o,r){let n=ne.string(t);if(!n.includes(`
|
|
1003
1003
|
`))return o;let i=n.split(`
|
|
@@ -1007,7 +1007,7 @@
|
|
|
1007
1007
|
`)}]};Ce.insertNodes(e,v,{at:[...d,p+1]})}else Ce.insertNodes(e,{text:m.join(`
|
|
1008
1008
|
`)},{at:[...o,0]})}),s.length>0?[...o.slice(0,-1),o[o.length-1]+1]:o)}function as(e,t,o,r){let{selection:n}=e;if(!n)return!1;let i=-1,a=-1,l=Ch.isCollapsed(n),s=Array.from(_.nodes(e,{match:p=>to.isElement(p)&&e.convertElement.isConvertibleElement(p)}));if(s.length>0){let[,p]=s[0];i=ns(e,n.anchor,p),a=ns(e,n.focus,p)}if(s.length===0)return!1;let m=[];_.withoutNormalizing(e,()=>{for(let p=s.length-1;p>=0;p--){let[u,h]=s[p];if(Sh(u)){let v=Lh(e,u,h,n);m.unshift(v)}else m.unshift(h)}});let c=m.map(p=>{try{let u=ne.get(e,p);return to.isElement(u)?[u,p]:null}catch{return null}}).filter(p=>p!==null);if(c.length===0)return!1;if(r&&c.every(p=>t(p[0]))?_.withoutNormalizing(e,()=>{for(let p of c)ct(e,{type:"paragraph"},p[1])}):_.withoutNormalizing(e,()=>{for(let p of c)ct(e,o,p[1])}),c.length>0&&i>=0){let[,p]=c[0];if(l)is(e,p,i);else if(a>=0)try{let u=ne.get(e,p);if(to.isElement(u)){let h=ne.string(u),v=Math.min(i,h.length),S=Math.min(a,h.length),P=_.start(e,p),M=P.path,B=v,C=0;for(let[x,I]of ne.texts(u)){let w=x.text.length;if(C+w>=v){M=[...p,...I],B=v-C;break}C+=w}let D=P.path,T=S;C=0;for(let[x,I]of ne.texts(u)){let w=x.text.length;if(C+w>=S){D=[...p,...I],T=S-C;break}C+=w}Ce.select(e,{anchor:{path:M,offset:B},focus:{path:D,offset:T}})}}catch{is(e,p,i)}}return!0}function ls(e,t){return e.convertElement.convertElementTypes.includes(t.type)}function ss(e){return{convertElementTypes:[],addConvertElementType:f(rs,e),isConvertibleElement:f(ls,e),convertElements:f(as,e)}}var ms=k(e=>(e.convertElement=ss(e),{name:"convert-element"}));import{Editor as or,Path as zh,Range as Bh,Transforms as cs}from"slate";function ps(e){let t=E(e,"heading");if(!t||!e.selection||Bh.isExpanded(e.selection)||!or.isEnd(e,e.selection.anchor,t[1]))return!1;let o=zh.next(t[1]);return cs.insertNodes(e,{type:"paragraph",children:[{text:""}]},{at:o}),cs.select(e,{anchor:or.start(e,o),focus:or.start(e,o)}),!0}import{Editor as Dh}from"slate";function Nh(e,t,o){e.convertElement.convertElements(r=>r.type==="heading"&&r.level==t,{type:"heading",level:t},o)}function $h(e,t){let[o]=Dh.nodes(e,{match:r=>"type"in r&&"level"in r&&r.type==="heading"&&r.level===t});return!!o}function ds(e){return{convertHeading:f(Nh,e),isHeadingActive:f($h,e)}}import{css as Hh}from"@emotion/react";import We from"@emotion/styled";var Ge=Hh`
|
|
1009
1009
|
margin-top: 1em;
|
|
1010
|
-
&:first-
|
|
1010
|
+
&:first-of-type {
|
|
1011
1011
|
margin-top: 0;
|
|
1012
1012
|
}
|
|
1013
1013
|
font-weight: bold;
|
|
@@ -1111,7 +1111,7 @@
|
|
|
1111
1111
|
* if isDebug is true, then show a highlight on list items that are marked
|
|
1112
1112
|
* as the first at a given depth.
|
|
1113
1113
|
*/
|
|
1114
|
-
background: ${
|
|
1114
|
+
background: ${"inherit"};
|
|
1115
1115
|
}
|
|
1116
1116
|
|
|
1117
1117
|
&:before {
|
|
@@ -1435,11 +1435,11 @@
|
|
|
1435
1435
|
&.--selected {
|
|
1436
1436
|
background: var(--blue-100);
|
|
1437
1437
|
}
|
|
1438
|
-
`;import{Fragment as ub,jsx as fo,jsxs as fb}from"react/jsx-runtime";function xc(e){return[...Array(e).keys()]}function yc({dest:e,close:t}){let[o,r]=cb({x:0,y:0}),n=db(),i=mb(null),a=j({src:i,dest:e},({dest:d})=>d?{left:d.left-8,top:d.top+d.height}:{left:0,top:0}),l=xc(5).map(d=>d+1),s=xc(5).map(d=>d+1),m=Ec((d,p)=>{r({x:d,y:p})},[r]),c=Ec((d,p)=>{n.tablePlugin.insertTable(d,p),pb.focus(n),t()},[n]);return fb(ub,{children:[fo(Ee,{close:t}),fo(hc,{ref:i,style:a,children:fo(gc,{onMouseLeave:()=>m(0,0),children:l.map(d=>s.map(p=>{let u=p<=o.x&&d<=o.y;return fo(bc,{className:sb({"--selected":u}),onMouseEnter:()=>m(p,d),onClick:()=>c(p,d)},`${p},${d}`)}))})})]})}import Hb from"lodash.
|
|
1438
|
+
`;import{Fragment as ub,jsx as fo,jsxs as fb}from"react/jsx-runtime";function xc(e){return[...Array(e).keys()]}function yc({dest:e,close:t}){let[o,r]=cb({x:0,y:0}),n=db(),i=mb(null),a=j({src:i,dest:e},({dest:d})=>d?{left:d.left-8,top:d.top+d.height}:{left:0,top:0}),l=xc(5).map(d=>d+1),s=xc(5).map(d=>d+1),m=Ec((d,p)=>{r({x:d,y:p})},[r]),c=Ec((d,p)=>{n.tablePlugin.insertTable(d,p),pb.focus(n),t()},[n]);return fb(ub,{children:[fo(Ee,{close:t}),fo(hc,{ref:i,style:a,children:fo(gc,{onMouseLeave:()=>m(0,0),children:l.map(d=>s.map(p=>{let u=p<=o.x&&d<=o.y;return fo(bc,{className:sb({"--selected":u}),onMouseEnter:()=>m(p,d),onClick:()=>c(p,d)},`${p},${d}`)}))})})]})}import Hb from"lodash.debounce";import{useEffect as Ab,useRef as Ob,useState as Ub}from"react";import{useSlateStatic as Fb}from"slate-react";import{jsx as b,jsxs as Je}from"react/jsx-runtime";var kc=()=>b(y,{children:b("path",{d:"M7 12h10M7 5v14M17 5v14M15 19h4M15 5h4M5 19h4M5 5h4"})}),vc=()=>b(y,{className:"--more-icon",width:"0.5em",viewBox:"0 0 12 24",children:b("path",{d:"m2 12 4 4 4-4"})}),Tc=()=>b(y,{width:"0.5em",viewBox:"6 0 12 24",children:b("path",{d:"M9 12h6M12 9v6"})}),wc=()=>b(y,{children:b("path",{d:"M19 18v-8l-2 2M4 6v12M12 6v12M11 18h2M3 18h2M4 12h8M3 6h2M11 6h2"})}),Ic=()=>b(y,{children:b("path",{d:"M17 12a2 2 0 1 1 4 0c0 .591-.417 1.318-.816 1.858L17 18.001h4M4 6v12M12 6v12M11 18h2M3 18h2M4 12h8M3 6h2M11 6h2"})}),Mc=()=>b(y,{children:b("path",{d:"M19 14a2 2 0 1 0-2-2M17 16a2 2 0 1 0 2-2M4 6v12M12 6v12M11 18h2M3 18h2M4 12h8M3 6h2M11 6h2"})});var Pc=()=>b(y,{children:b("path",{d:"M8 18V6h2l6 9V6h2v12h-2l-6-9v9H8z"})}),kr=()=>b(y,{children:b("path",{d:"M7 5h6a3.5 3.5 0 0 1 0 7H7zM13 12h1a3.5 3.5 0 0 1 0 7H7v-7"})}),Cc=()=>b(y,{children:b("path",{d:"M11 5h6M7 19h6M14 5l-4 14"})});var ho=()=>Je(y,{children:[b("path",{d:"M10 14a3.5 3.5 0 0 0 5 0l4-4a3.5 3.5 0 0 0-5-5l-.5.5"}),b("path",{d:"M14 10a3.5 3.5 0 0 0-5 0l-4 4a3.5 3.5 0 0 0 5 5l.5-.5"})]});var vr=()=>b(y,{children:b("path",{d:"M10 11H6a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v6c0 2.667-1.333 4.333-4 5M19 11h-4a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v6c0 2.667-1.333 4.333-4 5"})}),Sc=()=>Je(y,{children:[b("path",{d:"M10 9l4 3-4 3"}),b("path",{d:"M16 9l4 3-4 3"})]});var Rc=()=>b(y,{children:b("path",{d:"M9 6h11M9 12h11M9 18h11M5 6v.01M5 12v.01M5 18v.01"})}),Lc=()=>Je(y,{children:[b("rect",{x:4,y:4,width:16,height:16,rx:2}),b("path",{d:"M4 10h16M10 4v16"})]}),zc=()=>b(y,{children:b("path",{d:"m7 8-4 4 4 4M17 8l4 4-4 4M14 4l-4 16"})}),Bc=()=>b(y,{children:b("path",{d:"M9 8L5 12L9 16M15 8L19 12L15 16"})}),Dc=()=>Je(y,{children:[b("path",{d:"M15 8h.01"}),b("rect",{x:4,y:4,width:16,height:16,rx:3}),b("path",{d:"m4 15 4-4a3 5 0 0 1 3 0l5 5"}),b("path",{d:"m14 14 1-1a3 5 0 0 1 3 0l2 2"})]});var Nc=()=>b(y,{children:b("path",{d:"M12 5v14M5 12h14"})}),$c=()=>b(y,{children:b("path",{d:"M5 12h14M16 6.5A4 2 0 0 0 12 5h-1a3.5 3.5 0 0 0 0 7h2a3.5 3.5 0 0 1 0 7h-1.5a4 2 0 0 1-4-1.5"})}),Hc=()=>b(y,{children:b("path",{d:"M7 5v5a5 5 0 0 0 10 0V5M5 19h14"})});var Ac=()=>Je(y,{children:[b("path",{d:"m9 11 3 3 8-8"}),b("path",{d:"M20 12v6a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h9"})]}),Tr=()=>b(y,{children:b("path",{d:"M11 6h9M11 12h9M12 18h8M4 16a2 2 0 1 1 4 0c0 .591-.5 1-1 1.5L4 20h4M6 10V4L4 6"})}),Oc=()=>b(y,{children:b("path",{d:"M4 6h16M8 12h12M12 18h8M7 12l-3-3M7 12l-3 3"})}),Uc=()=>b(y,{children:b("path",{d:"M4 6h16M8 12h12M12 18h8M4 12l3-3M4 12l3 3"})});var Fc=()=>b(y,{children:b("path",{d:"M18 6L6 18M6 6l12 12"})}),Vc=()=>Je(y,{children:[b("path",{d:"M4 20h4l10.5-10.5a2.828 2.828 0 1 0-4-4L4 16v4"}),b("path",{d:"M13.5 6.5l4 4"}),b("path",{d:"m14 19 6-6M18 15l2 2M5 21h4"})]}),Kc=()=>b(y,{children:b("path",{d:"M5 12h14"})});var wr=[{icon:Oc,title:g("increaseDepth"),hotkey:"tab",action:e=>e.list.increaseDepth(),active:e=>e.list.canIncreaseDepth()},{icon:Uc,title:g("decreaseDepth"),hotkey:"shift+tab",action:e=>e.list.decreaseDepth(),active:e=>e.list.canDecreaseDepth()}],_c=[{icon:Pc,title:g("normal"),hotkey:"super+0",action:e=>{e.collapsibleParagraph.convertParagraph()}},{icon:wc,title:g("heading1"),hotkey:"super+1",action:e=>e.heading.convertHeading(1,!0),active:e=>e.heading.isHeadingActive(1)},{icon:Ic,title:g("heading2"),hotkey:"super+2",action:e=>e.heading.convertHeading(2,!0),active:e=>e.heading.isHeadingActive(2)},{icon:Mc,title:g("heading3"),hotkey:"super+3",action:e=>e.heading.convertHeading(3,!0),active:e=>e.heading.isHeadingActive(3)}],Wc=[..._c],Ir=[{icon:kc,title:g("paragraphStyle"),more:!0,children:_c}];import{useState as de,useRef as qc,useEffect as gb,useCallback as Mr}from"react";import{useSlateStatic as bb}from"slate-react";import hb from"@emotion/styled";var Gc=hb(Y)`
|
|
1439
1439
|
width: 18em;
|
|
1440
1440
|
padding: 0;
|
|
1441
1441
|
overflow: hidden;
|
|
1442
|
-
`;import{Fragment as Eb,jsx as F,jsxs as X}from"react/jsx-runtime";function Qc({dest:e,close:t}){let o=bb(),r=qc(null),n=qc(null),[i,a]=de({x:0,y:0}),l=Mr(($,U)=>{a(ue=>({x:ue.x+$,y:ue.y+U}))},[]),s=o.wysimark?.imageDialogState,m=!!o.wysimark?.onImageChange,[c,d]=de(s?.url??""),[p,u]=de(s?.alt??""),[h,v]=de(s?.title??""),[S,P]=de(!1),[M,B]=de(s?.imageSource??(m?"file":"url")),[C,D]=de(!1),[T,x]=de(s?.uploadedUrl??""),[I,w]=de(""),O=Mr($=>{let U=$.target.value;u(U),S||v(U)},[S]),Te=Mr($=>{v($.target.value),P(!0)},[]);gb(()=>{o.wysimark&&(o.wysimark.imageDialogState={url:c,alt:p,title:h,imageSource:M,uploadedUrl:T})},[c,p,h,M,T]);let $r=()=>{o.wysimark&&(o.wysimark.imageDialogState=void 0)},xo=j({src:r,dest:e},({src:$,dest:U},ue)=>$t($,ue,{left:U.left-16,top:U.top+U.height},{margin:16})),Ip={...xo,left:xo.left+i.x,top:xo.top+i.y};function Mp($){$.preventDefault();let U=M==="file"?T:c;U.trim()!==""&&(o.image.insertImageFromUrl(U,p,h),$r(),t())}function Pp(){$r(),t()}async function Cp($){let U=$.target.files?.[0];if(!(!U||!o.wysimark?.onImageChange)){w(U.name),D(!0);try{let ue=await o.wysimark.onImageChange(U);x(ue)}catch(ue){}finally{D(!1)}}}function Sp(){n.current?.click()}let yo=M==="file"?T.trim()===""||C:c.trim()==="";return X(Eb,{children:[F(Ee,{close:t}),X(Gc,{ref:r,style:Ip,children:[F(ye,{onDrag:l}),X("form",{onSubmit:$=>
|
|
1442
|
+
`;import{Fragment as Eb,jsx as F,jsxs as X}from"react/jsx-runtime";function Qc({dest:e,close:t}){let o=bb(),r=qc(null),n=qc(null),[i,a]=de({x:0,y:0}),l=Mr(($,U)=>{a(ue=>({x:ue.x+$,y:ue.y+U}))},[]),s=o.wysimark?.imageDialogState,m=!!o.wysimark?.onImageChange,[c,d]=de(s?.url??""),[p,u]=de(s?.alt??""),[h,v]=de(s?.title??""),[S,P]=de(!1),[M,B]=de(s?.imageSource??(m?"file":"url")),[C,D]=de(!1),[T,x]=de(s?.uploadedUrl??""),[I,w]=de(""),O=Mr($=>{let U=$.target.value;u(U),S||v(U)},[S]),Te=Mr($=>{v($.target.value),P(!0)},[]);gb(()=>{o.wysimark&&(o.wysimark.imageDialogState={url:c,alt:p,title:h,imageSource:M,uploadedUrl:T})},[c,p,h,M,T]);let $r=()=>{o.wysimark&&(o.wysimark.imageDialogState=void 0)},xo=j({src:r,dest:e},({src:$,dest:U},ue)=>$t($,ue,{left:U.left-16,top:U.top+U.height},{margin:16})),Ip={...xo,left:xo.left+i.x,top:xo.top+i.y};function Mp($){$.preventDefault();let U=M==="file"?T:c;U.trim()!==""&&(o.image.insertImageFromUrl(U,p,h),$r(),t())}function Pp(){$r(),t()}async function Cp($){let U=$.target.files?.[0];if(!(!U||!o.wysimark?.onImageChange)){w(U.name),D(!0);try{let ue=await o.wysimark.onImageChange(U);x(ue)}catch(ue){}finally{D(!1)}}}function Sp(){n.current?.click()}let yo=M==="file"?T.trim()===""||C:c.trim()==="";return X(Eb,{children:[F(Ee,{close:t}),X(Gc,{ref:r,style:Ip,children:[F(ye,{onDrag:l}),X("form",{onSubmit:$=>{Mp($)},style:{padding:"8px"},children:[m&&X("div",{style:{marginBottom:"12px"},children:[X("label",{style:{display:"inline-flex",alignItems:"center",marginRight:"16px",cursor:"pointer"},children:[F("input",{type:"radio",name:"imageSource",value:"file",checked:M==="file",onChange:()=>B("file"),style:{marginRight:"4px"}}),g("imageSourceFile")]}),X("label",{style:{display:"inline-flex",alignItems:"center",cursor:"pointer"},children:[F("input",{type:"radio",name:"imageSource",value:"url",checked:M==="url",onChange:()=>B("url"),style:{marginRight:"4px"}}),g("imageSourceUrl")]})]}),M==="url"?X("div",{style:{marginBottom:"8px"},children:[F("label",{style:{display:"block",marginBottom:"4px"},children:g("imageUrlRequired")}),F("input",{type:"text",value:c,onChange:$=>d($.target.value),style:{width:"100%",padding:"6px",boxSizing:"border-box",border:"1px solid var(--shade-300)",borderRadius:"4px",backgroundColor:"var(--shade-50)",color:"var(--shade-700)"},placeholder:"https://example.com/image.jpg"})]}):X("div",{style:{marginBottom:"8px"},children:[F("input",{ref:n,type:"file",accept:"image/*",onChange:$=>{Cp($)},style:{display:"none"}}),F("button",{type:"button",onClick:Sp,disabled:C,style:{padding:"8px 16px",backgroundColor:C?"#ccc":"#0078d4",color:C?"#666":"white",border:"none",borderRadius:"4px",cursor:C?"not-allowed":"pointer",marginBottom:"8px",fontWeight:"bold"},children:C?g("uploading"):g("selectFile")}),T&&X("div",{style:{marginTop:"8px",padding:"8px",backgroundColor:"var(--shade-100)",borderRadius:"4px"},children:[X("div",{style:{color:"green",marginBottom:"4px"},children:["\u2713 ",g("uploadComplete")]}),I&&F("div",{style:{fontSize:"12px",color:"var(--shade-500)"},children:I})]})]}),X("div",{style:{marginBottom:"8px"},children:[F("label",{style:{display:"block",marginBottom:"4px"},children:g("altText")}),F("input",{type:"text",value:p,onChange:O,style:{width:"100%",padding:"6px",boxSizing:"border-box",border:"1px solid var(--shade-300)",borderRadius:"4px",backgroundColor:"var(--shade-50)",color:"var(--shade-700)"},placeholder:g("imageDescription")})]}),X("div",{style:{marginBottom:"8px"},children:[F("label",{style:{display:"block",marginBottom:"4px"},children:g("title")}),F("input",{type:"text",value:h,onChange:Te,style:{width:"100%",padding:"6px",boxSizing:"border-box",border:"1px solid var(--shade-300)",borderRadius:"4px",backgroundColor:"var(--shade-50)",color:"var(--shade-700)"},placeholder:g("imageTitle")})]}),X("div",{style:{display:"flex",gap:"8px"},children:[F("button",{type:"submit",disabled:yo,style:{display:"flex",alignItems:"center",padding:"8px 16px",backgroundColor:yo?"#ccc":"#0078d4",color:"white",border:"none",borderRadius:"4px",cursor:yo?"not-allowed":"pointer",fontWeight:"bold"},children:g("register")}),F("button",{type:"button",onClick:Pp,style:{padding:"8px 16px",backgroundColor:"var(--shade-100)",color:"var(--shade-700)",border:"1px solid var(--shade-300)",borderRadius:"4px",cursor:"pointer"},children:g("cancel")})]})]})]})]})}import{isHotkey as xb}from"is-hotkey";import{useCallback as go,useMemo as yb,useRef as kb,useState as xt}from"react";import{Editor as vb,Range as Tb}from"slate";import{ReactEditor as wb,useSlateStatic as Ib}from"slate-react";import Xc from"@emotion/styled";var Pr=Xc("div")`
|
|
1443
1443
|
/* Center vertically and horizontally */
|
|
1444
1444
|
display: flex;
|
|
1445
1445
|
align-items: center;
|
|
@@ -1468,4 +1468,4 @@
|
|
|
1468
1468
|
margin-top: 0.5em;
|
|
1469
1469
|
color: var(--shade-500);
|
|
1470
1470
|
line-height: 1.375;
|
|
1471
|
-
`;import{Fragment as Pb,jsx as te,jsxs as yt}from"react/jsx-runtime";var Mb=xb("enter");function Yc({dest:e,close:t}){let o=Ib(),r=kb(null),[n,i]=xt({x:0,y:0}),a=go((x,I)=>{i(w=>({x:w.x+x,y:w.y+I}))},[]),l=j({src:r,dest:e},({src:x,dest:I},w)=>!x||!I?{left:0,top:0}:$t(x,w,{left:I.left-12,top:I.top+I.height},{margin:16})),s={...l,left:l.left+n.x,top:l.top+n.y},m=yb(()=>{let{selection:x}=o;return x&&!Tb.isCollapsed(x)?vb.string(o,x):""},[]),[c,d]=xt(""),[p,u]=xt(m),[h,v]=xt(m),[S,P]=xt(!1),M=()=>{let x=p.trim()||c,I=h.trim()||void 0;o.anchor.insertLink(c,x,{select:!0,title:I}),wb.focus(o),t()},B=go(x=>{d(x.currentTarget.value)},[d]),C=go(x=>{let I=x.currentTarget.value;u(I),S||v(I)},[u,v,S]),D=go(x=>{v(x.currentTarget.value),P(!0)},[v]),T=x=>{Mb(x)&&(x.preventDefault(),x.stopPropagation(),M())};return yt(Pb,{children:[te(Ee,{close:t}),yt(Ai,{ref:r,style:s,children:[te(ye,{onDrag:a}),yt("div",{style:{padding:"0.75em"},children:[te(Ht,{children:te(At,{type:"text",value:c,autoFocus:!0,placeholder:g("linkUrl"),onChange:B,onKeyDown:T})}),te(Ht,{style:{marginTop:"0.5em"},children:te(At,{type:"text",value:p,placeholder:g("linkText"),onChange:C,onKeyDown:T})}),yt(Ht,{style:{marginTop:"0.5em"},children:[te(At,{type:"text",value:h,placeholder:g("tooltipText"),onChange:D,onKeyDown:T}),yt(Pr,{onClick:M,children:[te(ho,{}),te(Tc,{})]}),te(Pr,{onClick:t,style:{marginLeft:"0.25em",background:"var(--shade-400)"},children:te(Fc,{})})]}),te(jc,{children:g("tooltipHint")})]})]})]})}var Cr=[{icon:ho,title:g("insertLink"),more:!0,hotkey:"mod+k",Component:Yc},{icon:Dc,title:g("insertImageFromUrl"),more:!0,Component:Qc},{icon:Lc,title:g("insertTable"),more:!0,Component:yc},{icon:Kc,title:g("horizontalRule"),hotkey:"super+-",action:e=>e.horizontalRule.insertHorizontalRule()}],Jc=Cr,Zc=Cr,ep=[{icon:Nc,title:g("insert"),more:!0,children:Cr}];import{Editor as Cb}from"slate";function Ze(e){let t=Cb.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:kr,title:g("bold"),hotkey:"mod+b",action:e=>e.marksPlugin.toggleBold(),active:e=>Ze(e).bold},{icon:Cc,title:g("italic"),hotkey:"mod+i",action:e=>e.marksPlugin.toggleItalic(),active:e=>Ze(e).italic},{icon:$c,title:g("strike"),hotkey:"super+k",action:e=>e.marksPlugin.toggleStrike(),active:e=>Ze(e).strike},{icon:zc,title:g("inlineCode"),hotkey:"mod+j",action:e=>e.inlineCode.toggleInlineCode(),active:e=>Ze(e).code},{icon:Hc,title:g("underline"),hotkey:"mod+u",action:e=>e.marksPlugin.toggleUnderline(),active:e=>Ze(e).underline},{icon:Vc,title:g("highlight"),hotkey:"mod+h",action:e=>e.marksPlugin.toggleHighlight(),active:e=>Ze(e).highlight,show:e=>!e.wysimark.disableHighlight}],Sr=tp,op=[{icon:kr,title:g("format"),more:!0,children:tp}];var rp=[{icon:Rc,title:g("bulletList"),hotkey:"super+8",action:e=>e.list.convertUnorderedList(!0)},{icon:Tr,title:g("numberedList"),hotkey:"super+7",action:e=>e.list.convertOrderedList(!0)},{icon:Ac,title:g("checkList"),hotkey:"super+9",action:e=>e.list.convertTaskList(!0),show:e=>!e.wysimark.disableTaskList}],Rr=[...rp,"divider",...wr],np=[{icon:Tr,title:g("list"),more:!0,children:[...rp,"divider",...wr]}];import{Editor as ip,Transforms as bo}from"slate";var ap=[{icon:vr,title:g("quote"),hotkey:"super+.",action:e=>{e.blockQuotePlugin.isActive()?e.blockQuotePlugin.outdent():e.blockQuotePlugin.indent()},active:e=>e.blockQuotePlugin.isActive()},{icon:Sc,title:g("increaseQuoteDepth"),action:e=>e.blockQuotePlugin.increaseDepth(),active:e=>e.blockQuotePlugin.canIncreaseDepth()},{icon:Bc,title:g("codeBlock"),action:e=>{let{selection:t}=e,o=E(e,"code-block");if(o){let[,r]=o,n=ip.string(e,r);bo.removeNodes(e,{at:r}),bo.insertNodes(e,{type:"paragraph",children:[{text:n}]},{at:r});return}if(t&&JSON.stringify(t.anchor.path)!==JSON.stringify(t.focus.path)){e.codeBlock.createCodeBlock({language:"text"});return}if(t&&(t.anchor.offset!==t.focus.offset||JSON.stringify(t.anchor.path)!==JSON.stringify(t.focus.path))){let r=ip.string(e,t);bo.delete(e),bo.insertNodes(e,{type:"code-block",language:"text",children:[{type:"code-block-line",children:[{text:r}]}]});return}e.codeBlock.createCodeBlock({language:"text"})},active:e=>!!E(e,"code-block"),show:e=>!e.wysimark.disableCodeBlock}],Lr=ap,lp=[{icon:vr,title:g("quote"),more:!0,children:ap}];var Sb=[...Wc,"divider",...Rr,"divider",...Sr,"divider",...Jc,"divider",...Lr],Rb=[...Ir,"divider",...Rr,"divider",...Sr,"divider",...Zc,"divider",...Lr],sp=[...Ir,"divider",...np,"divider",...op,"divider",...ep,"divider",...lp],mp=sp;var et=[Sb,Rb,sp];import{clsx as Lb}from"clsx";import{useCallback as zr,useRef as zb}from"react";import{ReactEditor as Bb,useSlate as Db,useSlateStatic as Nb}from"slate-react";import{jsx as Eo,jsxs as $b}from"react/jsx-runtime";function cp({item:e}){let t=Nb(),o=Db(),r=e.active?e.active(o):!1,n=zb(null),i=J({title:e.title,hotkey:()=>e.hotkey?Dt(e.hotkey):void 0}),a=H("menu"),l=zr(()=>{let c=n.current,d=e.children,p=e.Component;c&&(d?a.open(()=>Eo(Ae,{dest:c,items:d,close:a.close})):p&&a.open(()=>Eo(p,{dest:c,close:a.close})))},[e]),s=zr(()=>{if(e.action){e.action(t),Bb.focus(t);return}a.layer?a.close():l()},[a.layer,e]),m=zr(c=>{i.onMouseEnter(c),a.layer&&l()},[a.layer]);return $b(ji,{"data-item-type":"button",ref:n,onMouseEnter:m,onMouseLeave:i.onMouseLeave,onClick:s,className:Lb({"--active":r&&!Lo(e?.title)?.includes("Depth"),"--more":e.more,"--disabled":!r&&Lo(e?.title)?.includes("Depth")}),children:[Eo(e.icon,{}),e.more?Eo(vc,{}):null]})}import{jsx as tt}from"react/jsx-runtime";function Vb({item:e}){let t=Fb();return e==="divider"?tt(Qi,{"data-item-type":"divider",children:tt(Xi,{})}):(e.show===void 0?!0:e.show(t))?tt(cp,{item:e}):null}function Kb(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 _b(e,t,o){let r=0;for(let n of e)r+=n==="divider"?o:t;return r}var Wb=48;function pp(){let e=Ob(null),[t,o]=Ub(mp);return Ab(()=>{let r=Hb(()=>{let i=e.current;if(!i)throw new Error("Toolbar not found");let a=Kb(i);if(a){for(let l=0;l<et.length-1;l++)if(_b(et[l],a.button,a.divider)<a.toolbar-Wb){o(et[l]);return}o(et[et.length-1])}},100,{trailing:!0}),n=setTimeout(r,0);return window.addEventListener("resize",r),()=>{clearTimeout(n),window.removeEventListener("resize",r)}},[]),tt(Gi,{ref:e,children:tt(qi,{children:t.map((r,n)=>tt(Vb,{item:r},typeof r=="string"?n:r.title))})})}import{jsx as Br,jsxs as eE}from"react/jsx-runtime";function dp({attributes:e,Editable:t}){let o=Qb(null),r=Zb(),n=Jb(),i=qb(a=>{a.target===a.currentTarget&&(jb.select(r,Xb.end(r,[])),Yb.focus(r))},[r]);return Br(Li,{children:eE(Vi,{ref:o,className:Gb({"--focused":n}),style:{height:r.toolbar.height,minHeight:r.toolbar.minHeight,maxHeight:r.toolbar.maxHeight},onClick:i,children:[Br(pp,{}),Br(t,{as:Fi,...e,style:{overflowY:"auto"}})]})})}var up=k((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 Dr,Node as tE,Path as oE,Transforms as rE}from"slate";var fp=k(e=>(e.allowTrailingBlock=!0,{name:"trailing-block",editor:{normalizeNode:t=>{if(!Dr.isEditor(t[0]))return!1;let o=[e.children.length-1],r=tE.child(e,e.children.length-1);return(Dr.hasBlocks(e,r)||Dr.isVoid(e,r))&&rE.insertNodes(e,{type:"paragraph",children:[{text:""}]},{at:oE.next(o)}),!0}}}));import{Transforms as nE}from"slate";function iE(e,t){let o=fe(t),r=ge(o);nE.insertNodes(e,r)}function hp(e){return{pasteMarkdown:f(iE,e)}}var gp=k(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),we(t),!0}}}));import{jsx as lE}from"react/jsx-runtime";function aE(e){let t={...e.attributes,style:{...e.attributes.style,width:void 0,maxWidth:void 0}};return lE("span",{...t,children:e.children})}var bp=k((e,t,{createPolicy:o})=>(e.placeholder={},o({name:"placeholder",editableProps:{renderPlaceholder:aE}})));var Ep=[gp,ms,ga,xs,sm,Ss,gl,Fl,ql,pc,Is,fp,rm,ya,pm,os,fc,up,ul,bp];var sE=oi(Ep),{withSink:xp,SinkEditable:yp}=sE;import{useState as mE}from"react";import{createEditor as cE,Editor as pE,Transforms as dE}from"slate";import{withHistory as uE}from"slate-history";import{withReact as fE}from"slate-react";function Nr({authToken:e,height:t,minHeight:o,maxHeight:r,disableRawMode:n,disableTaskList:i,disableCodeBlock:a,disableHighlight:l}={}){let[s]=mE(()=>{let m=cE(),c=xp(fE(uE(m)),{toolbar:{height:t,minHeight:o,maxHeight:r,showUploadButtons:!!e},image:{}});return c.convertElement.addConvertElementType("paragraph"),m.wysimark={disableRawMode:n??!0,disableTaskList:i,disableCodeBlock:a,disableHighlight:l??!0},m.getMarkdown=()=>at(m.children),m.setMarkdown=d=>{let p=fe(d),u=ge(p);m.children=u,m.selection=null,dE.select(m,pE.start(m,[0]))},c});return s}import{jsx as oe,jsxs as vp}from"react/jsx-runtime";function yE({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}){let[s,m]=kp(!1),[c,d]=kp(t),p=vt(!1),u=vt(void 0),h=vt(void 0),v=vt(null),S=vt(o);S.current=o;let P=kt(hE(()=>{let w=at(e.children);e.wysimark.prevValue={markdown:w,children:e.children},S.current(w)},r,{leading:!1,trailing:!0}),[e,r]),M=kt(()=>{h.current!==e.children&&(h.current=e.children,P())},[P]);if(!s){let w=v.current??t;if(v.current!==null&&(v.current=null),e.wysimark.prevValue==null||u.current==null){p.current=!0;let O=fe(w),Te=ge(O);e.children=Te,h.current=u.current=Te,e.wysimark.prevValue={markdown:w,children:Te}}else if(w!==e.wysimark.prevValue.markdown){p.current=!0;let O=fe(w),Te=ge(O);e.children=Te,e.selection=null,bE.select(e,gE.start(e,[0]))}}let B=kt(()=>{navigator.userAgent.toLowerCase().includes("firefox")&&EE.focus(e)},[e]),C=kt(()=>{P.flush()},[P]),D=w=>{let O=w.target.value;d(O),o(O)},T=kt(()=>{let w=e.getMarkdown();d(w)},[e]),x=()=>{s?(v.current=c,e.wysimark.prevValue=void 0,u.current=void 0,h.current=void 0):T(),m(!s)};e.wysimark.onImageChange=l,e.wysimark.onChange=o;let I=e.wysimark.disableRawMode;return vp("div",{style:{position:"relative"},children:[!I&&oe("div",{style:{position:"absolute",top:"5px",right:"25px",zIndex:10},children:oe("div",{onClick:x,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?g("switchToVisualEditor"):g("switchToRawMarkdown"),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(x(),w.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:ot(c).replace(/ /g,""),onChange:D,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(xE,{editor:e,initialValue:u.current,onChange:M,children:oe(yp,{renderLeaf:yE,onMouseDown:B,onBlur:C,placeholder:n,className:i,style:a})})})]})}import{jsx as wp}from"react/jsx-runtime";function PE({standaloneOptions:{onChange:e,placeholder:t,className:o,...r},standaloneMethodsRef:n}){let[i,a]=IE(r.initialMarkdown||""),l=wE(i),s=Nr(r);l.current=i,TE(n,()=>({getMarkdown(){return l.current},setMarkdown(c){l.current=c,a(c)}}),[l,a]);let m=vE(c=>{l.current=c,a(c),e?.(c)},[s]);return wp(Tp,{editor:s,value:i,className:o||"",onChange:m,placeholder:t})}function SA(e,t){let o=kE(),r=ME(e);return r.render(wp(PE,{standaloneMethodsRef:o,standaloneOptions:t})),{unmount(){try{r.unmount()}catch{}},getMarkdown(){return o.current?.getMarkdown()||""},setMarkdown(n){o.current?.setMarkdown(n)}}}export{Tp as Editable,SA as createWysimark,Nr as useEditor};
|
|
1471
|
+
`;import{Fragment as Pb,jsx as te,jsxs as yt}from"react/jsx-runtime";var Mb=xb("enter");function Yc({dest:e,close:t}){let o=Ib(),r=kb(null),[n,i]=xt({x:0,y:0}),a=go((x,I)=>{i(w=>({x:w.x+x,y:w.y+I}))},[]),l=j({src:r,dest:e},({src:x,dest:I},w)=>!x||!I?{left:0,top:0}:$t(x,w,{left:I.left-12,top:I.top+I.height},{margin:16})),s={...l,left:l.left+n.x,top:l.top+n.y},m=yb(()=>{let{selection:x}=o;return x&&!Tb.isCollapsed(x)?vb.string(o,x):""},[]),[c,d]=xt(""),[p,u]=xt(m),[h,v]=xt(m),[S,P]=xt(!1),M=()=>{let x=p.trim()||c,I=h.trim()||void 0;o.anchor.insertLink(c,x,{select:!0,title:I}),wb.focus(o),t()},B=go(x=>{d(x.currentTarget.value)},[d]),C=go(x=>{let I=x.currentTarget.value;u(I),S||v(I)},[u,v,S]),D=go(x=>{v(x.currentTarget.value),P(!0)},[v]),T=x=>{Mb(x)&&(x.preventDefault(),x.stopPropagation(),M())};return yt(Pb,{children:[te(Ee,{close:t}),yt(Ai,{ref:r,style:s,children:[te(ye,{onDrag:a}),yt("div",{style:{padding:"0.75em"},children:[te(Ht,{children:te(At,{type:"text",value:c,autoFocus:!0,placeholder:g("linkUrl"),onChange:B,onKeyDown:T})}),te(Ht,{style:{marginTop:"0.5em"},children:te(At,{type:"text",value:p,placeholder:g("linkText"),onChange:C,onKeyDown:T})}),yt(Ht,{style:{marginTop:"0.5em"},children:[te(At,{type:"text",value:h,placeholder:g("tooltipText"),onChange:D,onKeyDown:T}),yt(Pr,{onClick:M,children:[te(ho,{}),te(Tc,{})]}),te(Pr,{onClick:t,style:{marginLeft:"0.25em",background:"var(--shade-400)"},children:te(Fc,{})})]}),te(jc,{children:g("tooltipHint")})]})]})]})}var Cr=[{icon:ho,title:g("insertLink"),more:!0,hotkey:"mod+k",Component:Yc},{icon:Dc,title:g("insertImageFromUrl"),more:!0,Component:Qc},{icon:Lc,title:g("insertTable"),more:!0,Component:yc},{icon:Kc,title:g("horizontalRule"),hotkey:"super+-",action:e=>e.horizontalRule.insertHorizontalRule()}],Jc=Cr,Zc=Cr,ep=[{icon:Nc,title:g("insert"),more:!0,children:Cr}];import{Editor as Cb}from"slate";function Ze(e){let t=Cb.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:kr,title:g("bold"),hotkey:"mod+b",action:e=>e.marksPlugin.toggleBold(),active:e=>Ze(e).bold},{icon:Cc,title:g("italic"),hotkey:"mod+i",action:e=>e.marksPlugin.toggleItalic(),active:e=>Ze(e).italic},{icon:$c,title:g("strike"),hotkey:"super+k",action:e=>e.marksPlugin.toggleStrike(),active:e=>Ze(e).strike},{icon:zc,title:g("inlineCode"),hotkey:"mod+j",action:e=>e.inlineCode.toggleInlineCode(),active:e=>Ze(e).code},{icon:Hc,title:g("underline"),hotkey:"mod+u",action:e=>e.marksPlugin.toggleUnderline(),active:e=>Ze(e).underline},{icon:Vc,title:g("highlight"),hotkey:"mod+h",action:e=>e.marksPlugin.toggleHighlight(),active:e=>Ze(e).highlight,show:e=>!e.wysimark.disableHighlight}],Sr=tp,op=[{icon:kr,title:g("format"),more:!0,children:tp}];var rp=[{icon:Rc,title:g("bulletList"),hotkey:"super+8",action:e=>e.list.convertUnorderedList(!0)},{icon:Tr,title:g("numberedList"),hotkey:"super+7",action:e=>e.list.convertOrderedList(!0)},{icon:Ac,title:g("checkList"),hotkey:"super+9",action:e=>e.list.convertTaskList(!0),show:e=>!e.wysimark.disableTaskList}],Rr=[...rp,"divider",...wr],np=[{icon:Tr,title:g("list"),more:!0,children:[...rp,"divider",...wr]}];import{Editor as ip,Transforms as bo}from"slate";var ap=[{icon:vr,title:g("quote"),hotkey:"super+.",action:e=>{e.blockQuotePlugin.isActive()?e.blockQuotePlugin.outdent():e.blockQuotePlugin.indent()},active:e=>e.blockQuotePlugin.isActive()},{icon:Sc,title:g("increaseQuoteDepth"),action:e=>e.blockQuotePlugin.increaseDepth(),active:e=>e.blockQuotePlugin.canIncreaseDepth()},{icon:Bc,title:g("codeBlock"),action:e=>{let{selection:t}=e,o=E(e,"code-block");if(o){let[,r]=o,n=ip.string(e,r);bo.removeNodes(e,{at:r}),bo.insertNodes(e,{type:"paragraph",children:[{text:n}]},{at:r});return}if(t&&JSON.stringify(t.anchor.path)!==JSON.stringify(t.focus.path)){e.codeBlock.createCodeBlock({language:"text"});return}if(t&&(t.anchor.offset!==t.focus.offset||JSON.stringify(t.anchor.path)!==JSON.stringify(t.focus.path))){let r=ip.string(e,t);bo.delete(e),bo.insertNodes(e,{type:"code-block",language:"text",children:[{type:"code-block-line",children:[{text:r}]}]});return}e.codeBlock.createCodeBlock({language:"text"})},active:e=>!!E(e,"code-block"),show:e=>!e.wysimark.disableCodeBlock}],Lr=ap,lp=[{icon:vr,title:g("quote"),more:!0,children:ap}];var Sb=[...Wc,"divider",...Rr,"divider",...Sr,"divider",...Jc,"divider",...Lr],Rb=[...Ir,"divider",...Rr,"divider",...Sr,"divider",...Zc,"divider",...Lr],sp=[...Ir,"divider",...np,"divider",...op,"divider",...ep,"divider",...lp],mp=sp;var et=[Sb,Rb,sp];import{clsx as Lb}from"clsx";import{useCallback as zr,useRef as zb}from"react";import{ReactEditor as Bb,useSlate as Db,useSlateStatic as Nb}from"slate-react";import{jsx as Eo,jsxs as $b}from"react/jsx-runtime";function cp({item:e}){let t=Nb(),o=Db(),r=e.active?e.active(o):!1,n=zb(null),i=J({title:e.title,hotkey:()=>e.hotkey?Dt(e.hotkey):void 0}),a=H("menu"),l=zr(()=>{let c=n.current,d=e.children,p=e.Component;c&&(d?a.open(()=>Eo(Ae,{dest:c,items:d,close:a.close})):p&&a.open(()=>Eo(p,{dest:c,close:a.close})))},[e]),s=zr(()=>{if(e.action){e.action(t),Bb.focus(t);return}a.layer?a.close():l()},[a.layer,e]),m=zr(c=>{i.onMouseEnter(c),a.layer&&l()},[a.layer]);return $b(ji,{"data-item-type":"button",ref:n,onMouseEnter:m,onMouseLeave:i.onMouseLeave,onClick:s,className:Lb({"--active":r&&!Lo(e?.title)?.includes("Depth"),"--more":e.more,"--disabled":!r&&Lo(e?.title)?.includes("Depth")}),children:[Eo(e.icon,{}),e.more?Eo(vc,{}):null]})}import{jsx as tt}from"react/jsx-runtime";function Vb({item:e}){let t=Fb();return e==="divider"?tt(Qi,{"data-item-type":"divider",children:tt(Xi,{})}):(e.show===void 0?!0:e.show(t))?tt(cp,{item:e}):null}function Kb(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 _b(e,t,o){let r=0;for(let n of e)r+=n==="divider"?o:t;return r}var Wb=48;function pp(){let e=Ob(null),[t,o]=Ub(mp);return Ab(()=>{let r=()=>{let a=e.current;if(!a)throw new Error("Toolbar not found");let l=Kb(a);if(l){for(let s=0;s<et.length-1;s++)if(_b(et[s],l.button,l.divider)<l.toolbar-Wb){o(et[s]);return}o(et[et.length-1])}},n=Hb(r,150),i=setTimeout(r,0);return window.addEventListener("resize",n),()=>{clearTimeout(i),n.cancel(),window.removeEventListener("resize",n)}},[]),tt(Gi,{ref:e,children:tt(qi,{children:t.map((r,n)=>tt(Vb,{item:r},typeof r=="string"?n:r.title))})})}import{jsx as Br,jsxs as eE}from"react/jsx-runtime";function dp({attributes:e,Editable:t}){let o=Qb(null),r=Zb(),n=Jb(),i=qb(a=>{a.target===a.currentTarget&&(jb.select(r,Xb.end(r,[])),Yb.focus(r))},[r]);return Br(Li,{children:eE(Vi,{ref:o,className:Gb({"--focused":n}),style:{height:r.toolbar.height,minHeight:r.toolbar.minHeight,maxHeight:r.toolbar.maxHeight},onClick:i,children:[Br(pp,{}),Br(t,{as:Fi,...e,style:{overflowY:"auto"}})]})})}var up=k((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 Dr,Node as tE,Path as oE,Transforms as rE}from"slate";var fp=k(e=>(e.allowTrailingBlock=!0,{name:"trailing-block",editor:{normalizeNode:t=>{if(!Dr.isEditor(t[0]))return!1;let o=[e.children.length-1],r=tE.child(e,e.children.length-1);return(Dr.hasBlocks(e,r)||Dr.isVoid(e,r))&&rE.insertNodes(e,{type:"paragraph",children:[{text:""}]},{at:oE.next(o)}),!0}}}));import{Transforms as nE}from"slate";function iE(e,t){let o=fe(t),r=ge(o);nE.insertNodes(e,r)}function hp(e){return{pasteMarkdown:f(iE,e)}}var gp=k(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),we(t),!0}}}));import{jsx as lE}from"react/jsx-runtime";function aE(e){let t={...e.attributes,style:{...e.attributes.style,width:void 0,maxWidth:void 0}};return lE("span",{...t,children:e.children})}var bp=k((e,t,{createPolicy:o})=>(e.placeholder={},o({name:"placeholder",editableProps:{renderPlaceholder:aE}})));var Ep=[gp,ms,ga,xs,sm,Ss,gl,Fl,ql,pc,Is,fp,rm,ya,pm,os,fc,up,ul,bp];var sE=oi(Ep),{withSink:xp,SinkEditable:yp}=sE;import{useState as mE}from"react";import{createEditor as cE,Editor as pE,Transforms as dE}from"slate";import{withHistory as uE}from"slate-history";import{withReact as fE}from"slate-react";function Nr({authToken:e,height:t,minHeight:o,maxHeight:r,disableRawMode:n,disableTaskList:i,disableCodeBlock:a,disableHighlight:l}={}){let[s]=mE(()=>{let m=cE(),c=xp(fE(uE(m)),{toolbar:{height:t,minHeight:o,maxHeight:r,showUploadButtons:!!e},image:{}});return c.convertElement.addConvertElementType("paragraph"),m.wysimark={disableRawMode:n??!0,disableTaskList:i,disableCodeBlock:a,disableHighlight:l??!0},m.getMarkdown=()=>at(m.children),m.setMarkdown=d=>{let p=fe(d),u=ge(p);m.children=u,m.selection=null,dE.select(m,pE.start(m,[0]))},c});return s}import{jsx as oe,jsxs as vp}from"react/jsx-runtime";function yE({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}){let[s,m]=kp(!1),[c,d]=kp(t),p=vt(!1),u=vt(void 0),h=vt(void 0),v=vt(null),S=vt(o);S.current=o;let P=kt(hE(()=>{let w=at(e.children);e.wysimark.prevValue={markdown:w,children:e.children},S.current(w)},r,{leading:!1,trailing:!0}),[e,r]),M=kt(()=>{h.current!==e.children&&(h.current=e.children,P())},[P]);if(!s){let w=v.current??t;if(v.current!==null&&(v.current=null),e.wysimark.prevValue==null||u.current==null){p.current=!0;let O=fe(w),Te=ge(O);e.children=Te,h.current=u.current=Te,e.wysimark.prevValue={markdown:w,children:Te}}else if(w!==e.wysimark.prevValue.markdown){p.current=!0;let O=fe(w),Te=ge(O);e.children=Te,e.selection=null,bE.select(e,gE.start(e,[0]))}}let B=kt(()=>{navigator.userAgent.toLowerCase().includes("firefox")&&EE.focus(e)},[e]),C=kt(()=>{P.flush()},[P]),D=w=>{let O=w.target.value;d(O),o(O)},T=kt(()=>{let w=e.getMarkdown();d(w)},[e]),x=()=>{s?(v.current=c,e.wysimark.prevValue=void 0,u.current=void 0,h.current=void 0):T(),m(!s)};e.wysimark.onImageChange=l,e.wysimark.onChange=o;let I=e.wysimark.disableRawMode;return vp("div",{style:{position:"relative"},children:[!I&&oe("div",{style:{position:"absolute",top:"5px",right:"25px",zIndex:10},children:oe("div",{onClick:x,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?g("switchToVisualEditor"):g("switchToRawMarkdown"),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(x(),w.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:ot(c).replace(/ /g,""),onChange:D,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(xE,{editor:e,initialValue:u.current,onChange:M,children:oe(yp,{renderLeaf:yE,onMouseDown:B,onBlur:C,placeholder:n,className:i,style:a})})})]})}import{jsx as wp}from"react/jsx-runtime";function PE({standaloneOptions:{onChange:e,placeholder:t,className:o,...r},standaloneMethodsRef:n}){let[i,a]=IE(r.initialMarkdown||""),l=wE(i),s=Nr(r);l.current=i,TE(n,()=>({getMarkdown(){return l.current},setMarkdown(c){l.current=c,a(c)}}),[l,a]);let m=vE(c=>{l.current=c,a(c),e?.(c)},[s]);return wp(Tp,{editor:s,value:i,className:o||"",onChange:m,placeholder:t})}function SA(e,t){let o=kE(),r=ME(e);return r.render(wp(PE,{standaloneMethodsRef:o,standaloneOptions:t})),{unmount(){try{r.unmount()}catch{}},getMarkdown(){return o.current?.getMarkdown()||""},setMarkdown(n){o.current?.setMarkdown(n)}}}export{Tp as Editable,SA as createWysimark,Nr as useEditor};
|