@pretextbook/web-editor 0.0.3 → 0.0.5

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 CHANGED
@@ -910,7 +910,7 @@ $&`),i=i.replace(f,`$&
910
910
  `);else u[c].trim().startsWith("<title>")&&(u[c]+=`
911
911
  `);break;case"many":for(let c=0;c<u.length-1;c++)(u[c].trim().startsWith("</")||u[c].trim().startsWith("<")&&u[c+1].trim().startsWith("<"))&&(u[c]+=`
912
912
  `);break}return i=u.join(`
913
- `),i}const wx=Ce.create({name:"ptxFragment",topNode:!0,content:"title? introduction? chapter* section* subsection* worksheet*"}),xx=[iw.configure({defaultLanguage:"xml"}),wx,V8,vf,Of,bf,ew,I8,sw,ow,aw,T8,M8,C8,r6.configure({mode:"deepest"}),i6,n6],g1=({content:r,onChange:e})=>{const t=z.useRef(null),n=o7({extensions:xx,content:"",onContentError(a){console.log("Content error: ",a.error),a.disableCollaboration(),a.editor.setEditable(!1,!1)},enableContentCheck:!0,onUpdate:({editor:a})=>{t.current&&clearTimeout(t.current),t.current=setTimeout(()=>{e(bx(lw(a.getJSON())))},500)}});z.useEffect(()=>()=>{t.current&&clearTimeout(t.current)},[]);const i=z.useRef(!0);z.useEffect(()=>{if(n&&r!==n.getHTML()&&i.current){const a=r;if(n)try{n.commands.setContent(j9(a),{emitUpdate:!1})}catch(l){console.error("Error setting content: ",l)}}},[r,n]),z.useEffect(()=>{if(!n)return;const a=()=>{i.current=!1};return n.on("update",a),()=>{n.off("update",a)}},[n]),z.useEffect(()=>{i.current=!0},[r]);const[s,o]=z.useState(!1);return z.useEffect(()=>{n&&n.setEditable(s,!1)},[n,s]),X.jsxs("div",{className:"editor-panel",children:[X.jsxs("div",{className:"relative mb-2 flex items-center justify-center pt-2",children:[X.jsx("p",{className:"text-base font-medium m-0 text-center",children:"Simple Preview"}),X.jsxs("label",{className:"absolute right-0 font-semibold",children:[X.jsx("input",{className:"mr-2",type:"checkbox",checked:s,onChange:()=>o(!s)}),"Edit"]})]}),X.jsx("div",{className:(s?"editable":"read-only")+" ptx-page",children:X.jsx(t7,{editor:n})}),X.jsx(px,{editor:n})]})},y1=({content:r})=>{const e=(n,i,s)=>{const o=document.createElement("form");o.method="POST",o.action=n,o.target=s,o.style.display="none";for(const a in i)if(Object.hasOwnProperty.call(i,a)){const l=document.createElement("input");l.type="hidden",l.name=a,l.value=i[a],o.appendChild(l)}document.body.appendChild(o),o.submit(),o.remove()},t=()=>{const n=r,i="foobar";let s=window.buildToken;s===void 0&&(s=void 0),e("https://build.pretext.plus",{source:n,title:i,token:s},"fullPreview")};return X.jsxs("div",{className:"editor-panel",children:[X.jsxs("div",{className:"relative mb-2 flex items-center justify-center pt-2",children:[X.jsx("p",{className:"text-base font-medium m-0 text-center",children:"Full Preview"}),X.jsx("button",{className:"absolute right-0 rounded-sm px-3 py-1.5 text-xs font-semibold text-white bg-emerald-600 hover:bg-emerald-700 shadow-sm transition-colors",onClick:()=>t(),children:"Rebuild"})]}),X.jsx("div",{children:X.jsx("iframe",{style:{display:"flex",flexDirection:"column",width:"100%",height:"70vh"},name:"fullPreview",src:"https://build.pretext.plus"})})]})},Sx=r=>X.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-100 border-b border-gray-300",children:[X.jsx("div",{className:"left-side flex items-center space-x-4",children:r.title!==void 0&&r.onTitleChange&&X.jsxs("label",{className:"inline-block font-semibold pr-4",children:["Title"," ",X.jsx("input",{className:"w-[40vw] p-2 inline-block shadow-sm rounded-md border font-mono border-gray-400 focus:outline-blue-600",type:"text",value:r.title,onChange:e=>r.onTitleChange?.(e.target.value)})]})}),X.jsxs("div",{className:"right-side flex items-center space-x-4",children:[r.onSaveButton&&X.jsx("button",{className:"w-full sm:w-auto rounded-md px-3.5 py-2.5 !bg-green-600 hover:!bg-green-700 !text-white inline-block font-medium cursor-pointer",onClick:r.onSaveButton,children:r.saveButtonLabel||"Save"}),r.onCancelButton&&X.jsx("button",{className:"w-full sm:w-auto rounded-md px-3.5 py-2.5 !bg-gray-300 hover:!bg-gray-400 !text-black inline-block font-medium cursor-pointer ml-4",onClick:r.onCancelButton,children:r.cancelButtonLabel||"Cancel"}),X.jsxs("label",{className:"relative inline-flex cursor-pointer select-none items-center flex-col",children:[X.jsx("input",{type:"checkbox",checked:!r.isChecked,onChange:r.onChange,className:"sr-only"}),X.jsxs("div",{className:"flex items-center gap-2",children:[X.jsx("span",{className:"label flex items-center justify-center text-sm font-medium w-14",children:"Simple"}),X.jsx("span",{className:`slider flex h-6 w-[48px] items-center rounded-full p-1 duration-200 ${r.isChecked?"bg-[#212b36]":"bg-[#CCCCCE]"}`,children:X.jsx("span",{className:`dot h-4 w-4 rounded-full bg-white duration-200 ${r.isChecked?"translate-x-[20px]":""}`})}),X.jsx("span",{className:"label flex items-center justify-center text-sm font-medium w-14",children:"Full"})]}),X.jsx("span",{className:"mt-1 text-xs font-medium text-gray-600 text-center",children:"Preview Mode"}),X.jsx("input",{type:"checkbox",checked:r.isChecked,onChange:r.onChange,className:"sr-only"})]})]})]}),kx=`
913
+ `),i}const wx=Ce.create({name:"ptxFragment",topNode:!0,content:"title? introduction? chapter* section* subsection* worksheet*"}),xx=[iw.configure({defaultLanguage:"xml"}),wx,V8,vf,Of,bf,ew,I8,sw,ow,aw,T8,M8,C8,r6.configure({mode:"deepest"}),i6,n6],g1=({content:r,onChange:e})=>{const t=z.useRef(null),n=o7({extensions:xx,content:"",onContentError(a){console.log("Content error: ",a.error),a.disableCollaboration(),a.editor.setEditable(!1,!1)},enableContentCheck:!0,onUpdate:({editor:a})=>{t.current&&clearTimeout(t.current),t.current=setTimeout(()=>{e(bx(lw(a.getJSON())))},500)}});z.useEffect(()=>()=>{t.current&&clearTimeout(t.current)},[]);const i=z.useRef(!0);z.useEffect(()=>{if(n&&r!==n.getHTML()&&i.current){const a=r;if(n)try{n.commands.setContent(j9(a),{emitUpdate:!1})}catch(l){console.error("Error setting content: ",l)}}},[r,n]),z.useEffect(()=>{if(!n)return;const a=()=>{i.current=!1};return n.on("update",a),()=>{n.off("update",a)}},[n]),z.useEffect(()=>{i.current=!0},[r]);const[s,o]=z.useState(!1);return z.useEffect(()=>{n&&n.setEditable(s,!1)},[n,s]),X.jsxs("div",{className:"editor-panel",children:[X.jsxs("div",{className:"relative mb-2 flex items-center justify-center pt-2",children:[X.jsx("p",{className:"text-base font-medium m-0 text-center",children:"Simple Preview"}),X.jsxs("label",{className:"absolute right-0 font-semibold",children:[X.jsx("input",{className:"mr-2",type:"checkbox",checked:s,onChange:()=>o(!s)}),"Edit"]})]}),X.jsx("div",{className:(s?"editable":"read-only")+" ptx-page",children:X.jsx(t7,{editor:n})}),X.jsx(px,{editor:n})]})},y1=({content:r,title:e})=>{const t=(i,s,o)=>{const a=document.createElement("form");a.method="POST",a.action=i,a.target=o,a.style.display="none";for(const l in s)if(Object.hasOwnProperty.call(s,l)){const u=document.createElement("input");u.type="hidden",u.name=l,u.value=s[l],a.appendChild(u)}document.body.appendChild(a),a.submit(),a.remove()},n=()=>{const i=r,s=e||"Document Title";let o=window.buildToken;o===void 0&&(o=void 0),t("https://build.pretext.plus",{source:i,title:s,token:o},"fullPreview")};return X.jsxs("div",{className:"editor-panel",children:[X.jsxs("div",{className:"relative mb-2 flex items-center justify-center pt-2",children:[X.jsx("p",{className:"text-base font-medium m-0 text-center",children:"Full Preview"}),X.jsx("button",{className:"absolute right-0 rounded-sm px-3 py-1.5 text-xs font-semibold text-white bg-emerald-600 hover:bg-emerald-700 shadow-sm transition-colors",onClick:()=>n(),children:"Rebuild"})]}),X.jsx("div",{children:X.jsx("iframe",{style:{display:"flex",flexDirection:"column",width:"100%",height:"70vh"},name:"fullPreview",src:"https://build.pretext.plus"})})]})},Sx=r=>X.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-100 border-b border-gray-300",children:[X.jsx("div",{className:"left-side flex items-center space-x-4",children:r.title!==void 0&&r.onTitleChange&&X.jsxs("label",{className:"inline-block font-semibold pr-4",children:["Title"," ",X.jsx("input",{className:"w-[40vw] p-2 inline-block shadow-sm rounded-md border font-mono border-gray-400 focus:outline-blue-600",type:"text",value:r.title,onChange:e=>r.onTitleChange?.(e.target.value)})]})}),X.jsxs("div",{className:"right-side flex items-center space-x-4",children:[r.onSaveButton&&X.jsx("button",{className:"w-full sm:w-auto rounded-md px-3.5 py-2.5 !bg-green-600 hover:!bg-green-700 !text-white inline-block font-medium cursor-pointer",onClick:r.onSaveButton,children:r.saveButtonLabel||"Save"}),r.onCancelButton&&X.jsx("button",{className:"w-full sm:w-auto rounded-md px-3.5 py-2.5 !bg-gray-300 hover:!bg-gray-400 !text-black inline-block font-medium cursor-pointer ml-4",onClick:r.onCancelButton,children:r.cancelButtonLabel||"Cancel"}),X.jsxs("label",{className:"relative inline-flex cursor-pointer select-none items-center flex-col",children:[X.jsx("input",{type:"checkbox",checked:!r.isChecked,onChange:r.onChange,className:"sr-only"}),X.jsxs("div",{className:"flex items-center gap-2",children:[X.jsx("span",{className:"label flex items-center justify-center text-sm font-medium w-14",children:"Simple"}),X.jsx("span",{className:`slider flex h-6 w-[48px] items-center rounded-full p-1 duration-200 ${r.isChecked?"bg-[#212b36]":"bg-[#CCCCCE]"}`,children:X.jsx("span",{className:`dot h-4 w-4 rounded-full bg-white duration-200 ${r.isChecked?"translate-x-[20px]":""}`})}),X.jsx("span",{className:"label flex items-center justify-center text-sm font-medium w-14",children:"Full"})]}),X.jsx("span",{className:"mt-1 text-xs font-medium text-gray-600 text-center",children:"Preview Mode"}),X.jsx("input",{type:"checkbox",checked:r.isChecked,onChange:r.onChange,className:"sr-only"})]})]})]}),kx=`
914
914
  <section>
915
915
  <title>My Section</title>
916
916
  <p>
@@ -989,5 +989,5 @@ $&`),i=i.replace(f,`$&
989
989
 
990
990
  <p> And that's the end of the demo. Thanks for coming!</p>
991
991
  </section>
992
- `,Tx=r=>{const[e,t]=z.useState(r.content||kx),[n,i]=z.useState(r.title||"Document Title"),[s,o]=z.useState(!1);let a;return s?a=X.jsx(y1,{content:e}):a=X.jsx(g1,{content:e,onChange:l=>{t(l||""),r.onContentChange(l)}}),X.jsxs("div",{children:[X.jsx(Sx,{isChecked:s,onChange:()=>o(!s),title:n,onTitleChange:l=>{i(l),r.onTitleChange?.(l)},onSaveButton:r.onSaveButton,saveButtonLabel:r.saveButtonLabel,onCancelButton:r.onCancelButton,cancelButtonLabel:r.cancelButtonLabel}),X.jsxs(mu,{style:{height:"80vh",width:"98vw"},children:[X.jsx(Ko,{className:"flex",children:X.jsx(Nu,{content:e,onChange:l=>{t(l||""),r.onContentChange(l)}})}),X.jsx(Ko,{className:"flex",children:a})]}),X.jsx("textarea",{value:e,readOnly:!0,style:{display:"none",width:"98vw",height:"20vh",marginTop:"10px"}})]})};Bt.CodeEditor=Nu,Bt.Editors=Tx,Bt.FullPreview=y1,Bt.VisualEditor=g1,Object.defineProperty(Bt,Symbol.toStringTag,{value:"Module"})}));
992
+ `,Tx=r=>{const[e,t]=z.useState(r.content||kx),[n,i]=z.useState(r.title||"Document Title"),[s,o]=z.useState(!1);let a;return s?a=X.jsx(y1,{content:e,title:n}):a=X.jsx(g1,{content:e,onChange:l=>{t(l||""),r.onContentChange(l)}}),X.jsxs("div",{children:[X.jsx(Sx,{isChecked:s,onChange:()=>o(!s),title:n,onTitleChange:l=>{i(l),r.onTitleChange?.(l)},onSaveButton:r.onSaveButton,saveButtonLabel:r.saveButtonLabel,onCancelButton:r.onCancelButton,cancelButtonLabel:r.cancelButtonLabel}),X.jsxs(mu,{style:{height:"80vh",width:"98vw"},children:[X.jsx(Ko,{className:"flex",children:X.jsx(Nu,{content:e,onChange:l=>{t(l||""),r.onContentChange(l)}})}),X.jsx(Ko,{className:"flex",children:a})]}),X.jsx("textarea",{value:e,readOnly:!0,style:{display:"none",width:"98vw",height:"20vh",marginTop:"10px"}})]})};Bt.CodeEditor=Nu,Bt.Editors=Tx,Bt.FullPreview=y1,Bt.VisualEditor=g1,Object.defineProperty(Bt,Symbol.toStringTag,{value:"Module"})}));
993
993
  //# sourceMappingURL=index.js.map