@pretextbook/web-editor 0.5.1 → 0.5.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/dist/index.d.ts +1 -1
- package/dist/index.es.js +67 -52
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/sectionUtils.d.ts +24 -10
- package/dist/web-editor.css +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1058,7 +1058,7 @@ Expected it to be ${r}.`}var QU=class extends Error{name=`InvalidDocError`;const
|
|
|
1058
1058
|
`)}`:a.join(`
|
|
1059
1059
|
`)},p3=(e,t,n)=>{let r=[];if(e.trim()&&r.push(` <macros>${e}</macros>`),t.trim()&&r.push(` <latex-image-preamble>${t}</latex-image-preamble>`),n.trim())for(let e of n.trim().split(`
|
|
1060
1060
|
`))r.push(` ${e}`);return r.length===0?``:`<docinfo>\n${r.join(`
|
|
1061
|
-
`)}\n</docinfo>`},m3={macros:`LaTeX Macros`,preamble:`Image Macros`,other:`Other Elements`},h3={macros:`LaTeX macros available throughout the document. Stored in <macros> inside <docinfo>. Use \\newcommand to define new macros (avoid using \\def).`,preamble:`LaTeX macros for rendering TikZ/LaTeX images. Stored in <latex-image-preamble> inside <docinfo>.`,other:`Any additional <docinfo> child elements (e.g. <cross-references>, <rename>). Edit as raw XML — one element per line.`},g3=({docinfo:e,onClose:r,showCommonDocinfoControls:i=!1,commonDocinfo:a=``,initialUseCommonDocinfo:o=!1})=>{let[s,c]=(0,n.useState)(`macros`),[l,u]=(0,n.useState)(o),d=l3(e),[f,p]=(0,n.useState)(()=>s3(d,`macros`)),[m,h]=(0,n.useState)(()=>s3(d,`latex-image-preamble`)),[g,_]=(0,n.useState)(()=>c3(d,[`macros`,`latex-image-preamble`])),v=l3(a),[y,b]=(0,n.useState)(()=>s3(v,`macros`)),[x,S]=(0,n.useState)(()=>s3(v,`latex-image-preamble`)),[C,w]=(0,n.useState)(()=>c3(v,[`macros`,`latex-image-preamble`])),T=a.trim().length>0;(0,n.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r(void 0)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let E=()=>{r({docinfo:p3(f,m,g),commonDocinfo:p3(y,x,C),useCommonDocinfo:l})},D=()=>{if(!T)return;let e=l3(a);u3(e)||(p(t=>d3(t,s3(e,`macros`))),h(t=>d3(t,s3(e,`latex-image-preamble`))),_(t=>f3(t,e)))},O=s===`macros`?l?y:f:s===`preamble`?l?x:m:l?C:g,k=s===`other`?`xml`:`latex`,A=i&&l,j=s===`macros`?l?b:p:s===`preamble`?l?S:h:l?w:_;return(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-overlay`,onClick:()=>r(void 0),children:(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog${A?` pretext-plus-editor__dialog--common-mode`:``}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`pretext-plus-editor-docinfo-dialog-title`,onClick:e=>e.stopPropagation(),children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`h2`,{id:`pretext-plus-editor-docinfo-dialog-title`,className:`pretext-plus-editor__dialog-title`,children:`Edit docinfo/preamble elements`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-copy`,children:h3[s]}),i?(0,t.jsxs)(`label`,{className:`pretext-plus-editor__dialog-checkbox-row`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.currentTarget.checked)}),(0,t.jsx)(`span`,{children:`Use my common docinfo/preamble.`})]}):null,i&&!l?(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-common-import-row`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-link-button`,onClick:D,disabled:!T,children:`Import common docinfo`})}):null]}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:()=>r(void 0),"aria-label":`Close docinfo editor`,children:`Close`})]}),A?(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-common-mode-banner`,children:`You are editing your shared common docinfo/preamble. These values will apply to all projects that use this option.`}):null,(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-tab-bar`,role:`tablist`,children:[`macros`,`preamble`,`other`].map(e=>(0,t.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":s===e,className:`pretext-plus-editor__dialog-tab${s===e?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>c(e),children:m3[e]},e))}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single`,children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-section`,children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-editor`,children:(0,t.jsx)(Yn,{options:s===`other`?o3:a3,height:`100%`,language:k,value:O,onChange:e=>j(e??``)},`${s}-${l?`common`:`project`}`)})})})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:()=>r(void 0),children:`Cancel`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:E,children:`Save`})]})]})})},_3=`data:image/png;base64,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`,v3={image:`Images`,doenet:`Doenet`},y3=[`image`,`doenet`];function b3(e){let t=new Set,n=[],r=/<plus:(image|doenet)\b[^>]*\bref="([^"]+)"/g,i;for(;(i=r.exec(e))!==null;){let e=`${i[1]}:${i[2]}`;t.has(e)||(t.add(e),n.push({kind:i[1],ref:i[2]}))}return n}var x3=({open:e,onClose:r,onLoadAssets:i,onLoadLibraryAssets:a,onInsert:o,onAddFromLibrary:s,onUpload:c,onAddUrl:l,onCreateDoenet:u,onRemoveAsset:d})=>{let f=Q4(e=>e.activeEditorSource),p=Q4(e=>e.projectAssets)??[],m=Q4(e=>e.libraryAssets),h=!!(i||a),[g,_]=(0,n.useState)(null),[v,y]=(0,n.useState)(null),[b,x]=(0,n.useState)(!1),[S,C]=(0,n.useState)(null),w=g??p,T=v??m??w,E=new Set(w.map(e=>e.id)),[D,O]=(0,n.useState)(`in-document`),[k,A]=(0,n.useState)(null),[j,ee]=(0,n.useState)(`library`),[te,ne]=(0,n.useState)(`library`),[re,M]=(0,n.useState)(null),[ie,ae]=(0,n.useState)(!1),[oe,N]=(0,n.useState)(!1),[se,P]=(0,n.useState)(null),ce=(0,n.useRef)(null),[le,ue]=(0,n.useState)(``),[de,F]=(0,n.useState)(``),[fe,pe]=(0,n.useState)(!1),[me,he]=(0,n.useState)(null),[ge,I]=(0,n.useState)(``),[_e,ve]=(0,n.useState)(``),[ye,be]=(0,n.useState)(!1),[xe,Se]=(0,n.useState)(null),[Ce,L]=(0,n.useState)(null),we=(0,n.useCallback)(()=>{!i&&!a||(x(!0),C(null),Promise.all([i?.()??Promise.resolve(null),a?.()??Promise.resolve(null)]).then(([e,t])=>{e!==null&&_(e),t!==null&&y(t)}).catch(e=>{C(e instanceof Error?e.message:`Failed to load assets.`)}).finally(()=>x(!1)))},[i,a]);if((0,n.useEffect)(()=>{if(!e)return;we();let t=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,r,we]),!e)return null;let Te=b3(f),Ee=e=>{o(e),r()},R=(e,t)=>{let n=`${e}:${t}`;navigator.clipboard.writeText(`<plus:${e} ref="${t}"/>`).catch(()=>{}),L(n),setTimeout(()=>L(e=>e===n?null:e),2e3)},De=async e=>{if(!E.has(e.id)&&s){M(e.id);try{await s(e)}finally{M(null)}}Ee(e)},Oe=async e=>{if(c){P(null),N(!0);try{Ee(await c(e))}catch(e){P(e instanceof Error?e.message:`Upload failed.`),N(!1)}}},ke=async()=>{let e=le.trim();if(!e)return;let t=de.trim()||e;if(l){he(null),pe(!0);try{Ee(await l(e,t))}catch(e){he(e instanceof Error?e.message:`Failed to add URL.`),pe(!1)}}else Ee({id:`url-${Date.now()}`,name:t,ref:e.split(`/`).pop()??`image`,kind:`image`})},z=async()=>{let e=ge.trim(),t=_e.trim();if(!(!e||!t))if(u){Se(null),be(!0);try{Ee(await u(e,t))}catch(e){Se(e instanceof Error?e.message:`Failed to create activity.`),be(!1)}}else Ee({id:`doenet-${Date.now()}`,name:e,ref:t,kind:`doenet`})},Ae=e=>{let n=T.filter(t=>t.kind===e);return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-library`,children:[h&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-toolbar`,children:[S&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__asset-load-error`,children:S}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__asset-library-refresh`,onClick:we,disabled:b,children:b?`Loading…`:`Refresh`})]}),b&&n.length===0?(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-empty-text`,children:`Loading…`}):n.length===0?(0,t.jsxs)(`p`,{className:`pretext-plus-editor__am-empty-text`,children:[`No `,v3[e].toLowerCase(),` assets in your library.`]}):(0,t.jsx)(`ul`,{className:`pretext-plus-editor__am-list`,children:n.map(e=>{let n=E.has(e.id),r=re===e.id;return(0,t.jsx)(`li`,{children:(0,t.jsxs)(`button`,{type:`button`,className:[`pretext-plus-editor__am-lib-row`,n?`pretext-plus-editor__am-lib-row--in-project`:``].filter(Boolean).join(` `),onClick:()=>De(e),disabled:r||!e.ref,title:e.ref?n?`Insert "${e.ref}"`:`Add to project & insert "${e.ref}"`:`Asset has no reference — cannot insert`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-info`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-name`,children:e.name}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-ref`,children:r?`Adding…`:e.ref})]}),n&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-badge`,children:`✓`})]})},e.id)})})]})};return(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-overlay`,onClick:e=>e.target===e.currentTarget&&r(),children:(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog pretext-plus-editor__dialog--asset-manager`,role:`dialog`,"aria-modal":`true`,"aria-label":`Asset manager`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsx)(`h2`,{className:`pretext-plus-editor__dialog-title`,children:`Assets`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${D===`in-document`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>O(`in-document`),children:[`In Document`,Te.length>0&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__asset-tab-count`,children:Te.length})]}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${D===`add`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>{O(`add`),A(null)},children:`Add Asset`})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single pretext-plus-editor__am-body`,children:D===`in-document`?(()=>{if(Te.length===0)return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-placeholder`,children:[(0,t.jsx)(`p`,{children:`No assets referenced in this document yet.`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:()=>{O(`add`),A(null)},children:`Add an asset`})]});let e=y3.reduce((e,t)=>(e[t]=Te.filter(e=>e.kind===t).map(e=>({ref:e.ref,asset:w.find(t=>t.kind===e.kind&&t.ref===e.ref)})),e),{image:[],doenet:[]});return(0,t.jsx)(`div`,{className:`pretext-plus-editor__am-in-doc`,children:y3.filter(t=>e[t].length>0).map(n=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-group`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-header`,children:[(0,t.jsx)(`span`,{"aria-hidden":`true`,children:`📁`}),(0,t.jsx)(`span`,{children:v3[n]}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-count`,children:e[n].length})]}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__am-list`,children:e[n].map(({ref:e,asset:i})=>{let a=`${n}:${e}`;return(0,t.jsxs)(`li`,{className:`pretext-plus-editor__am-doc-row`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-info`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-name`,children:i?.name??e}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-ref`,children:e})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-actions`,children:[i&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn`,onClick:()=>Ee(i),title:`Insert <plus:${n} ref="${e}"/>`,children:`Insert`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn${Ce===a?` pretext-plus-editor__am-action-btn--done`:``}`,onClick:()=>R(n,e),title:`Copy <plus:${n} ref="${e}"/>`,children:Ce===a?`Copied!`:`Copy`}),d&&i&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn pretext-plus-editor__am-action-btn--danger`,onClick:()=>{d(i),r()},title:`Remove from project`,children:`Remove`})]})]},e)})})]},n))})})():k===null?(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-picker`,children:[(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-kind-picker-label`,children:`What kind of asset?`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-cards`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__am-kind-card`,onClick:()=>{A(`image`),ee(`library`)},children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-icon`,"aria-hidden":`true`,children:`🖼️`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-label`,children:`Image`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-hint`,children:`PNG, JPEG, SVG, etc.`})]}),(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__am-kind-card`,onClick:()=>{A(`doenet`),ne(`library`)},children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-icon`,"aria-hidden":`true`,children:(0,t.jsx)(`img`,{src:_3,alt:`Doenet`})}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-label`,children:`Doenet`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-hint`,children:`Interactive activity`})]})]})]}):k===`image`?(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-back-btn`,onClick:()=>A(null),children:`← Back`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar pretext-plus-editor__am-sub-tabs`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${j===`library`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ee(`library`),children:`Library`}),c&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${j===`upload`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ee(`upload`),children:`Upload`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${j===`url`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ee(`url`),children:`External URL`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure-body`,children:[j===`library`&&Ae(`image`),j===`upload`&&c&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-upload`,children:[(0,t.jsxs)(`div`,{className:[`pretext-plus-editor__am-drop-zone`,ie?`pretext-plus-editor__am-drop-zone--active`:``,oe?`pretext-plus-editor__am-drop-zone--uploading`:``].filter(Boolean).join(` `),onDragOver:e=>{e.preventDefault(),ae(!0)},onDragLeave:()=>ae(!1),onDrop:e=>{e.preventDefault(),ae(!1);let t=e.dataTransfer.files[0];t&&Oe(t)},onClick:()=>!oe&&ce.current?.click(),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),ce.current?.click())},"aria-label":`Upload image — click or drag and drop`,children:[(0,t.jsx)(`input`,{ref:ce,type:`file`,accept:`image/*`,className:`pretext-plus-editor__dialog-file-input`,onChange:e=>{let t=e.target.files?.[0];t&&Oe(t)}}),oe?(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-drop-text`,children:`Uploading…`}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-drop-icon`,"aria-hidden":`true`,children:`↑`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-drop-text`,children:`Drag & drop an image, or click to browse`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`PNG, JPEG, GIF, SVG, WebP`})]})]}),se&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:se})]}),j===`url`&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-url-form`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-url-value`,children:`Image URL`}),(0,t.jsx)(`input`,{id:`am-url-value`,type:`url`,className:`pretext-plus-editor__am-input`,placeholder:`https://example.com/image.png`,value:le,onChange:e=>ue(e.target.value),disabled:fe,autoFocus:!0}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-url-name`,children:[`Name `,(0,t.jsx)(`span`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`(optional)`})]}),(0,t.jsx)(`input`,{id:`am-url-name`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`My image`,value:de,onChange:e=>F(e.target.value),disabled:fe}),me&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:me}),le.trim()&&(0,t.jsx)(`img`,{src:le.trim(),alt:`Preview`,className:`pretext-plus-editor__am-url-preview`,onError:e=>{e.currentTarget.style.display=`none`}}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:ke,disabled:!le.trim()||fe,children:fe?`Adding…`:l?`Add to Library & Insert`:`Insert`})]})]})]}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-back-btn`,onClick:()=>A(null),children:`← Back`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar pretext-plus-editor__am-sub-tabs`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${te===`library`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ne(`library`),children:`Library`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${te===`create`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ne(`create`),children:`Create New`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure-body`,children:[te===`library`&&Ae(`doenet`),te===`create`&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-create-form`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-doenet-name`,children:`Name`}),(0,t.jsx)(`input`,{id:`am-doenet-name`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`My Activity`,value:ge,onChange:e=>I(e.target.value),disabled:ye,autoFocus:!0}),(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-doenet-ref`,children:`Reference ID`}),(0,t.jsx)(`input`,{id:`am-doenet-ref`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`my-activity`,value:_e,onChange:e=>ve(e.target.value),disabled:ye}),(0,t.jsxs)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:[`The reference ID is used in the inserted tag: `,(0,t.jsx)(`code`,{children:`<plus:doenet ref="${_e||`my-activity`}"/>`})]}),xe&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:xe}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:z,disabled:!ge.trim()||!_e.trim()||ye,children:ye?`Creating…`:u?`Create & Insert`:`Insert`})]})]})]})}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:r,children:`Close`})})]})})},S3=e=>{let n=Q4(e=>e.showFullPreview),r=Q4(e=>e.setShowFullPreview),i=Q4(e=>e.title),a=Q4(e=>e.updateTitle),o;return o=e.showPreviewModeToggle===!1?null:(0,t.jsxs)(`label`,{className:`pretext-plus-editor__preview-toggle`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:!n,onChange:()=>r(!n),className:`pretext-plus-editor__preview-toggle-input`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__preview-toggle-container`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-label`,children:`Simple`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-slider ${n?`pretext-plus-editor__preview-toggle-slider--active`:``}`,children:(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-dot ${n?`pretext-plus-editor__preview-toggle-dot--active`:``}`})}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-label`,children:`Full`})]}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-caption`,children:`Preview Mode`}),(0,t.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>r(!n),className:`pretext-plus-editor__preview-toggle-input`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-bar`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__menu-left`,children:(0,t.jsxs)(`label`,{className:`pretext-plus-editor__title-label`,children:[`Title`,` `,(0,t.jsx)(`input`,{className:`pretext-plus-editor__title-input`,type:`text`,value:i,onChange:e=>a(e.target.value)})]})}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-right`,children:[e.onSaveButton&&(0,t.jsx)(`button`,{className:`pretext-plus-editor__button pretext-plus-editor__button--save`,onClick:e.onSaveButton,children:e.saveButtonLabel||`Save`}),e.onCancelButton&&(0,t.jsx)(`button`,{className:`pretext-plus-editor__button pretext-plus-editor__button--cancel`,onClick:e.onCancelButton,children:e.cancelButtonLabel||`Cancel`}),(0,t.jsx)($4,{label:`Give feedback`,context:`main-editor`}),o]})]})},C3={book:`Book`,article:`Article`,slideshow:`Slideshow`,part:`Part`,chapter:`Chapter`,section:`Section`,worksheet:`Worksheet`,handout:`Handout`,exercises:`Exercises`,references:`References`,glossary:`Glossary`,solutions:`Solutions`,"reading-questions":`Reading Questions`,introduction:`Introduction`,conclusion:`Conclusion`},w3=[`part`,`chapter`,`section`,`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`],T3=({draft:e,isLatex:n,isRoot:r=!1,onDraftChange:i,onCommit:a,onCancel:o})=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-edit-form`,children:[(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Title`}),(0,t.jsx)(`input`,{type:`text`,value:e.title,onChange:t=>i({...e,title:t.target.value}),onKeyDown:e=>{e.key===`Enter`&&a(),e.key===`Escape`&&o()},autoFocus:!0})]}),!n&&(0,t.jsxs)(t.Fragment,{children:[!r&&(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Type`}),(0,t.jsx)(`select`,{value:e.type,onChange:t=>i({...e,type:t.target.value}),children:w3.map(e=>(0,t.jsx)(`option`,{value:e,children:C3[e]},e))})]}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`xml:id`}),(0,t.jsx)(`input`,{type:`text`,value:e.xmlId,placeholder:`optional`,onChange:t=>i({...e,xmlId:t.target.value})})]}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`label`}),(0,t.jsx)(`input`,{type:`text`,value:e.label,placeholder:`optional`,onChange:t=>i({...e,label:t.target.value})})]})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-edit-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-edit-save`,onClick:a,children:`Save`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-edit-cancel`,onClick:o,children:`Cancel`})]})]});function E3(e){let t=e?.parentElement??null;for(;t;){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null}var D3=({items:e})=>{let[r,i]=(0,n.useState)(!1),[a,o]=(0,n.useState)(`below`),s=(0,n.useRef)(null),c=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!r)return;let e=e=>{s.current&&!s.current.contains(e.target)&&i(!1)},t=e=>{e.key===`Escape`&&i(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]),(0,n.useLayoutEffect)(()=>{if(!r)return;let e=c.current,t=s.current;if(!e||!t)return;let n=E3(t)??document.documentElement,i=e.getBoundingClientRect(),a=n.getBoundingClientRect(),l=t.getBoundingClientRect(),u=a.bottom-l.bottom,d=l.top-a.top;o(i.height>u&&d>u?`above`:`below`)},[r]);let l=e=>{i(!1),e()};return(0,t.jsxs)(`div`,{ref:s,className:`pretext-plus-editor__toc-div-menu`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-div-menu-trigger`,onClick:e=>{e.stopPropagation(),i(e=>(e||o(`below`),!e))},"aria-haspopup":`true`,"aria-expanded":r,title:`More options`,children:`⋮`}),r&&(0,t.jsx)(`div`,{ref:c,className:[`pretext-plus-editor__toc-div-menu-popup`,a===`above`?`pretext-plus-editor__toc-div-menu-popup--above`:`pretext-plus-editor__toc-div-menu-popup--below`].join(` `),children:e.map(e=>(0,t.jsx)(`button`,{type:`button`,className:[`pretext-plus-editor__toc-div-menu-item`,e.danger?`pretext-plus-editor__toc-div-menu-item--danger`:``].filter(Boolean).join(` `),onClick:()=>l(e.onClick),children:e.label},e.label))})]})},O3=({division:e,depth:n,isActive:r,hasChildren:i,isExpanded:a,onToggleExpand:o,editDraft:s,onSelect:c,onDraftChange:l,onEditCommit:u,onEditCancel:d,menuItems:f,isLatex:p,isRoot:m=!1})=>{let h=s!==null;return(0,t.jsxs)(`li`,{className:[`pretext-plus-editor__toc-item`,`pretext-plus-editor__toc-item--${e.type}`,r?`pretext-plus-editor__toc-item--active`:``,h?`pretext-plus-editor__toc-item--editing`:``].filter(Boolean).join(` `),children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-item-row`,style:n>0?{paddingLeft:`${n*14}px`}:void 0,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-expand-btn`,onClick:o,"aria-label":a?`Collapse`:`Expand`,tabIndex:i?0:-1,style:{visibility:i?`visible`:`hidden`},children:a?`▾`:`▸`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-select`,onClick:c,"aria-current":r?`true`:void 0,title:C3[e.type]??e.type,children:(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-title`,children:e.title||(0,t.jsx)(`em`,{children:`Untitled`})})}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-actions`,children:(0,t.jsx)(D3,{items:f})})]}),h&&s&&(0,t.jsx)(T3,{draft:s,isLatex:p,isRoot:m,onDraftChange:l,onCommit:u,onCancel:d})]})},k3=p(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{XmlCdata:()=>E,XmlComment:()=>D,XmlDeclaration:()=>O,XmlDocument:()=>A,XmlDocumentType:()=>j,XmlElement:()=>k,XmlError:()=>ee,XmlNode:()=>w,XmlProcessingInstruction:()=>te,XmlText:()=>T,parseXml:()=>ie}),t.exports=c(l);var u=``,d=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,f=class{constructor(e){if(this.k=this.u(e,!0),this.d=0,this.length=e.length,this.l=this.k!==this.length,this.h=e,this.l){let t=[];for(let n=0,r=0;r<this.k;++r)t[r]=n,n+=e.codePointAt(n)>65535?2:1;this.A=t}}get B(){return this.d>=this.k}u(e,t=this.l){return t?e.replace(d,`_`).length:e.length}p(e=1){this.d=Math.min(this.k,this.d+e)}f(e=this.d){return this.l?this.A[e]??1/0:e}G(e=1){let t=this.m(e);return this.p(e),t}v(e){let t=this.f(),n=this.h.slice(t,t+e);return this.p(this.u(n)),n}w(e){let{length:t,l:n,h:r}=this,i=this.f(),a=i;if(n)for(;a<t;){let t=r[a],n=t>=`\ud800`&&t<=`\udbff`;if(n&&(t+=r[a+1]),!e(t))break;a+=n?2:1}else for(;a<t&&e(r[a]);)++a;return this.v(a-i)}b(e){let{length:t}=e,n=this.f();return e===this.h.slice(n,n+t)?(this.p(t===1?1:this.u(e)),e):u}x(e){let t=this.h.slice(this.f()).search(e);return t>0?this.v(t):u}s(e){let t=this.f(),n=this.h.indexOf(e,t);return n>0?this.v(n-t):u}m(e=1){let{d:t,h:n}=this;return this.l?n.slice(this.f(t),this.f(t+e)):n.slice(t,t+e)}n(e=0){this.d=e>=0?Math.min(this.k,e):Math.max(0,this.d+e)}},p=/["&<]/,m=/['&<]/,h=/\r\n|[\n\r\t]/g,g=/<|&|]]>/,_=Object.freeze(Object.assign(Object.create(null),{amp:`&`,apos:`'`,gt:`>`,lt:`<`,quot:`"`}));function v(e){let t=e.codePointAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||t===45||t===46||t===183||t>=768&&t<=879||t===8255||t===8256||y(e,t)}function y(e,t=e.codePointAt(0)){return t>=97&&t<=122||t>=65&&t<=90||t===58||t===95||t>=192&&t<=214||t>=216&&t<=246||t>=248&&t<=767||t>=880&&t<=893||t>=895&&t<=8191||t===8204||t===8205||t>=8304&&t<=8591||t>=11264&&t<=12271||t>=12289&&t<=55295||t>=63744&&t<=64975||t>=65008&&t<=65533||t>=65536&&t<=983039}function b(e){return e===`#`||v(e)}function x(e){let t=e.codePointAt(0);return t===32||t===9||t===10||t===13}function S(e){return e>=32&&e<=55295||e===10||e===9||e===13||e>=57344&&e<=65533||e>=65536&&e<=1114111}var C=class e{constructor(){this.parent=null,this.start=-1,this.end=-1}get document(){return this.parent?.document??null}get isRootNode(){return this.parent!==null&&this.parent===this.document&&this.type===e.TYPE_ELEMENT}get preserveWhitespace(){return!!this.parent?.preserveWhitespace}get type(){return``}toJSON(){let e={type:this.type};return this.isRootNode&&(e.isRootNode=!0),this.preserveWhitespace&&(e.preserveWhitespace=!0),this.start!==-1&&(e.start=this.start,e.end=this.end),e}};C.TYPE_CDATA=`cdata`,C.TYPE_COMMENT=`comment`,C.TYPE_DOCUMENT=`document`,C.TYPE_DOCUMENT_TYPE=`doctype`,C.TYPE_ELEMENT=`element`,C.TYPE_PROCESSING_INSTRUCTION=`pi`,C.TYPE_TEXT=`text`,C.TYPE_XML_DECLARATION=`xmldecl`;var w=C,T=class extends w{constructor(e=``){super(),this.text=e}get type(){return w.TYPE_TEXT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{text:this.text})}},E=class extends T{get type(){return w.TYPE_CDATA}},D=class extends w{constructor(e=``){super(),this.content=e}get type(){return w.TYPE_COMMENT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{content:this.content})}},O=class extends w{constructor(e,t,n){super(),this.version=e,this.encoding=t??null,this.standalone=n??null}get type(){return w.TYPE_XML_DECLARATION}toJSON(){let e=w.prototype.toJSON.call(this);e.version=this.version;for(let t of[`encoding`,`standalone`])this[t]!==null&&(e[t]=this[t]);return e}},k=class e extends w{constructor(e,t=Object.create(null),n=[]){super(),this.name=e,this.attributes=t,this.children=n}get isEmpty(){return this.children.length===0}get preserveWhitespace(){let t=this;for(;t instanceof e;){if(`xml:space`in t.attributes)return t.attributes[`xml:space`]===`preserve`;t=t.parent}return!1}get text(){return this.children.map(e=>`text`in e?e.text:``).join(``)}get type(){return w.TYPE_ELEMENT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{name:this.name,attributes:this.attributes,children:this.children.map(e=>e.toJSON())})}},A=class extends w{constructor(e=[]){super(),this.children=e}get document(){return this}get root(){for(let e of this.children)if(e instanceof k)return e;return null}get text(){return this.children.map(e=>`text`in e?e.text:``).join(``)}get type(){return w.TYPE_DOCUMENT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{children:this.children.map(e=>e.toJSON())})}},j=class extends w{constructor(e,t,n,r){super(),this.name=e,this.publicId=t??null,this.systemId=n??null,this.internalSubset=r??null}get type(){return w.TYPE_DOCUMENT_TYPE}toJSON(){let e=w.prototype.toJSON.call(this);e.name=this.name;for(let t of[`publicId`,`systemId`,`internalSubset`])this[t]!==null&&(e[t]=this[t]);return e}},ee=class extends Error{constructor(e,t,n){let r=1,i=``,a=1;for(let e=0;e<t;++e){let t=n[e];t===`
|
|
1061
|
+
`)}\n</docinfo>`},m3={macros:`LaTeX Macros`,preamble:`Image Macros`,other:`Other Elements`},h3={macros:`LaTeX macros available throughout the document. Stored in <macros> inside <docinfo>. Use \\newcommand to define new macros (avoid using \\def).`,preamble:`LaTeX macros for rendering TikZ/LaTeX images. Stored in <latex-image-preamble> inside <docinfo>.`,other:`Any additional <docinfo> child elements (e.g. <cross-references>, <rename>). Edit as raw XML — one element per line.`},g3=({docinfo:e,onClose:r,showCommonDocinfoControls:i=!1,commonDocinfo:a=``,initialUseCommonDocinfo:o=!1})=>{let[s,c]=(0,n.useState)(`macros`),[l,u]=(0,n.useState)(o),d=l3(e),[f,p]=(0,n.useState)(()=>s3(d,`macros`)),[m,h]=(0,n.useState)(()=>s3(d,`latex-image-preamble`)),[g,_]=(0,n.useState)(()=>c3(d,[`macros`,`latex-image-preamble`])),v=l3(a),[y,b]=(0,n.useState)(()=>s3(v,`macros`)),[x,S]=(0,n.useState)(()=>s3(v,`latex-image-preamble`)),[C,w]=(0,n.useState)(()=>c3(v,[`macros`,`latex-image-preamble`])),T=a.trim().length>0;(0,n.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r(void 0)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let E=()=>{r({docinfo:p3(f,m,g),commonDocinfo:p3(y,x,C),useCommonDocinfo:l})},D=()=>{if(!T)return;let e=l3(a);u3(e)||(p(t=>d3(t,s3(e,`macros`))),h(t=>d3(t,s3(e,`latex-image-preamble`))),_(t=>f3(t,e)))},O=s===`macros`?l?y:f:s===`preamble`?l?x:m:l?C:g,k=s===`other`?`xml`:`latex`,A=i&&l,j=s===`macros`?l?b:p:s===`preamble`?l?S:h:l?w:_;return(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-overlay`,onClick:()=>r(void 0),children:(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog${A?` pretext-plus-editor__dialog--common-mode`:``}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`pretext-plus-editor-docinfo-dialog-title`,onClick:e=>e.stopPropagation(),children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`h2`,{id:`pretext-plus-editor-docinfo-dialog-title`,className:`pretext-plus-editor__dialog-title`,children:`Edit docinfo/preamble elements`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-copy`,children:h3[s]}),i?(0,t.jsxs)(`label`,{className:`pretext-plus-editor__dialog-checkbox-row`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.currentTarget.checked)}),(0,t.jsx)(`span`,{children:`Use my common docinfo/preamble.`})]}):null,i&&!l?(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-common-import-row`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-link-button`,onClick:D,disabled:!T,children:`Import common docinfo`})}):null]}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:()=>r(void 0),"aria-label":`Close docinfo editor`,children:`Close`})]}),A?(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-common-mode-banner`,children:`You are editing your shared common docinfo/preamble. These values will apply to all projects that use this option.`}):null,(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-tab-bar`,role:`tablist`,children:[`macros`,`preamble`,`other`].map(e=>(0,t.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":s===e,className:`pretext-plus-editor__dialog-tab${s===e?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>c(e),children:m3[e]},e))}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single`,children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-section`,children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-editor`,children:(0,t.jsx)(Yn,{options:s===`other`?o3:a3,height:`100%`,language:k,value:O,onChange:e=>j(e??``)},`${s}-${l?`common`:`project`}`)})})})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:()=>r(void 0),children:`Cancel`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:E,children:`Save`})]})]})})},_3=`data:image/png;base64,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`,v3={image:`Images`,doenet:`Doenet`},y3=[`image`,`doenet`];function b3(e){let t=new Set,n=[],r=/<plus:(image|doenet)\b[^>]*\bref="([^"]+)"/g,i;for(;(i=r.exec(e))!==null;){let e=`${i[1]}:${i[2]}`;t.has(e)||(t.add(e),n.push({kind:i[1],ref:i[2]}))}return n}var x3=({open:e,onClose:r,onLoadAssets:i,onLoadLibraryAssets:a,onInsert:o,onAddFromLibrary:s,onUpload:c,onAddUrl:l,onCreateDoenet:u,onRemoveAsset:d})=>{let f=Q4(e=>e.activeEditorSource),p=Q4(e=>e.projectAssets)??[],m=Q4(e=>e.libraryAssets),h=!!(i||a),[g,_]=(0,n.useState)(null),[v,y]=(0,n.useState)(null),[b,x]=(0,n.useState)(!1),[S,C]=(0,n.useState)(null),w=g??p,T=v??m??w,E=new Set(w.map(e=>e.id)),[D,O]=(0,n.useState)(`in-document`),[k,A]=(0,n.useState)(null),[j,ee]=(0,n.useState)(`library`),[te,ne]=(0,n.useState)(`library`),[re,M]=(0,n.useState)(null),[ie,ae]=(0,n.useState)(!1),[oe,N]=(0,n.useState)(!1),[se,P]=(0,n.useState)(null),ce=(0,n.useRef)(null),[le,ue]=(0,n.useState)(``),[de,F]=(0,n.useState)(``),[fe,pe]=(0,n.useState)(!1),[me,he]=(0,n.useState)(null),[ge,I]=(0,n.useState)(``),[_e,ve]=(0,n.useState)(``),[ye,be]=(0,n.useState)(!1),[xe,Se]=(0,n.useState)(null),[Ce,L]=(0,n.useState)(null),we=(0,n.useCallback)(()=>{!i&&!a||(x(!0),C(null),Promise.all([i?.()??Promise.resolve(null),a?.()??Promise.resolve(null)]).then(([e,t])=>{e!==null&&_(e),t!==null&&y(t)}).catch(e=>{C(e instanceof Error?e.message:`Failed to load assets.`)}).finally(()=>x(!1)))},[i,a]);if((0,n.useEffect)(()=>{if(!e)return;we();let t=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,r,we]),!e)return null;let Te=b3(f),Ee=e=>{o(e),r()},R=(e,t)=>{let n=`${e}:${t}`;navigator.clipboard.writeText(`<plus:${e} ref="${t}"/>`).catch(()=>{}),L(n),setTimeout(()=>L(e=>e===n?null:e),2e3)},De=async e=>{if(!E.has(e.id)&&s){M(e.id);try{await s(e)}finally{M(null)}}Ee(e)},Oe=async e=>{if(c){P(null),N(!0);try{Ee(await c(e))}catch(e){P(e instanceof Error?e.message:`Upload failed.`),N(!1)}}},ke=async()=>{let e=le.trim();if(!e)return;let t=de.trim()||e;if(l){he(null),pe(!0);try{Ee(await l(e,t))}catch(e){he(e instanceof Error?e.message:`Failed to add URL.`),pe(!1)}}else Ee({id:`url-${Date.now()}`,name:t,ref:e.split(`/`).pop()??`image`,kind:`image`})},z=async()=>{let e=ge.trim(),t=_e.trim();if(!(!e||!t))if(u){Se(null),be(!0);try{Ee(await u(e,t))}catch(e){Se(e instanceof Error?e.message:`Failed to create activity.`),be(!1)}}else Ee({id:`doenet-${Date.now()}`,name:e,ref:t,kind:`doenet`})},Ae=e=>{let n=T.filter(t=>t.kind===e);return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-library`,children:[h&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-toolbar`,children:[S&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__asset-load-error`,children:S}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__asset-library-refresh`,onClick:we,disabled:b,children:b?`Loading…`:`Refresh`})]}),b&&n.length===0?(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-empty-text`,children:`Loading…`}):n.length===0?(0,t.jsxs)(`p`,{className:`pretext-plus-editor__am-empty-text`,children:[`No `,v3[e].toLowerCase(),` assets in your library.`]}):(0,t.jsx)(`ul`,{className:`pretext-plus-editor__am-list`,children:n.map(e=>{let n=E.has(e.id),r=re===e.id;return(0,t.jsx)(`li`,{children:(0,t.jsxs)(`button`,{type:`button`,className:[`pretext-plus-editor__am-lib-row`,n?`pretext-plus-editor__am-lib-row--in-project`:``].filter(Boolean).join(` `),onClick:()=>De(e),disabled:r||!e.ref,title:e.ref?n?`Insert "${e.ref}"`:`Add to project & insert "${e.ref}"`:`Asset has no reference — cannot insert`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-info`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-name`,children:e.name}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-ref`,children:r?`Adding…`:e.ref})]}),n&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-badge`,children:`✓`})]})},e.id)})})]})};return(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-overlay`,onClick:e=>e.target===e.currentTarget&&r(),children:(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog pretext-plus-editor__dialog--asset-manager`,role:`dialog`,"aria-modal":`true`,"aria-label":`Asset manager`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsx)(`h2`,{className:`pretext-plus-editor__dialog-title`,children:`Assets`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${D===`in-document`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>O(`in-document`),children:[`In Document`,Te.length>0&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__asset-tab-count`,children:Te.length})]}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${D===`add`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>{O(`add`),A(null)},children:`Add Asset`})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single`,children:D===`in-document`?(()=>{if(Te.length===0)return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-placeholder`,children:[(0,t.jsx)(`p`,{children:`No assets referenced in this document yet.`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:()=>{O(`add`),A(null)},children:`Add an asset`})]});let e=y3.reduce((e,t)=>(e[t]=Te.filter(e=>e.kind===t).map(e=>({ref:e.ref,asset:w.find(t=>t.kind===e.kind&&t.ref===e.ref)})),e),{image:[],doenet:[]});return(0,t.jsx)(`div`,{className:`pretext-plus-editor__am-in-doc`,children:y3.filter(t=>e[t].length>0).map(n=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-group`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-header`,children:[(0,t.jsx)(`span`,{"aria-hidden":`true`,children:`📁`}),(0,t.jsx)(`span`,{children:v3[n]}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-count`,children:e[n].length})]}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__am-list`,children:e[n].map(({ref:e,asset:i})=>{let a=`${n}:${e}`;return(0,t.jsxs)(`li`,{className:`pretext-plus-editor__am-doc-row`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-info`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-name`,children:i?.name??e}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-ref`,children:e})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-actions`,children:[i&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn`,onClick:()=>Ee(i),title:`Insert <plus:${n} ref="${e}"/>`,children:`Insert`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn${Ce===a?` pretext-plus-editor__am-action-btn--done`:``}`,onClick:()=>R(n,e),title:`Copy <plus:${n} ref="${e}"/>`,children:Ce===a?`Copied!`:`Copy`}),d&&i&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn pretext-plus-editor__am-action-btn--danger`,onClick:()=>{d(i),r()},title:`Remove from project`,children:`Remove`})]})]},e)})})]},n))})})():k===null?(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-picker`,children:[(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-kind-picker-label`,children:`What kind of asset?`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-cards`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__am-kind-card`,onClick:()=>{A(`image`),ee(`library`)},children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-icon`,"aria-hidden":`true`,children:`🖼️`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-label`,children:`Image`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-hint`,children:`PNG, JPEG, SVG, etc.`})]}),(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__am-kind-card`,onClick:()=>{A(`doenet`),ne(`library`)},children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-icon`,"aria-hidden":`true`,children:(0,t.jsx)(`img`,{src:_3,alt:`Doenet`})}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-label`,children:`Doenet`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-hint`,children:`Interactive activity`})]})]})]}):k===`image`?(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-back-btn`,onClick:()=>A(null),children:`← Back`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar pretext-plus-editor__am-sub-tabs`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${j===`library`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ee(`library`),children:`Library`}),c&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${j===`upload`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ee(`upload`),children:`Upload`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${j===`url`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ee(`url`),children:`External URL`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure-body`,children:[j===`library`&&Ae(`image`),j===`upload`&&c&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-upload`,children:[(0,t.jsxs)(`div`,{className:[`pretext-plus-editor__am-drop-zone`,ie?`pretext-plus-editor__am-drop-zone--active`:``,oe?`pretext-plus-editor__am-drop-zone--uploading`:``].filter(Boolean).join(` `),onDragOver:e=>{e.preventDefault(),ae(!0)},onDragLeave:()=>ae(!1),onDrop:e=>{e.preventDefault(),ae(!1);let t=e.dataTransfer.files[0];t&&Oe(t)},onClick:()=>!oe&&ce.current?.click(),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),ce.current?.click())},"aria-label":`Upload image — click or drag and drop`,children:[(0,t.jsx)(`input`,{ref:ce,type:`file`,accept:`image/*`,className:`pretext-plus-editor__dialog-file-input`,onChange:e=>{let t=e.target.files?.[0];t&&Oe(t)}}),oe?(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-drop-text`,children:`Uploading…`}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-drop-icon`,"aria-hidden":`true`,children:`↑`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-drop-text`,children:`Drag & drop an image, or click to browse`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`PNG, JPEG, GIF, SVG, WebP`})]})]}),se&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:se})]}),j===`url`&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-url-form`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-url-value`,children:`Image URL`}),(0,t.jsx)(`input`,{id:`am-url-value`,type:`url`,className:`pretext-plus-editor__am-input`,placeholder:`https://example.com/image.png`,value:le,onChange:e=>ue(e.target.value),disabled:fe,autoFocus:!0}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-url-name`,children:[`Name `,(0,t.jsx)(`span`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`(optional)`})]}),(0,t.jsx)(`input`,{id:`am-url-name`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`My image`,value:de,onChange:e=>F(e.target.value),disabled:fe}),me&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:me}),le.trim()&&(0,t.jsx)(`img`,{src:le.trim(),alt:`Preview`,className:`pretext-plus-editor__am-url-preview`,onError:e=>{e.currentTarget.style.display=`none`}}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:ke,disabled:!le.trim()||fe,children:fe?`Adding…`:l?`Add to Library & Insert`:`Insert`})]})]})]}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-back-btn`,onClick:()=>A(null),children:`← Back`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar pretext-plus-editor__am-sub-tabs`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${te===`library`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ne(`library`),children:`Library`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${te===`create`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ne(`create`),children:`Create New`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure-body`,children:[te===`library`&&Ae(`doenet`),te===`create`&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-create-form`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-doenet-name`,children:`Name`}),(0,t.jsx)(`input`,{id:`am-doenet-name`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`My Activity`,value:ge,onChange:e=>I(e.target.value),disabled:ye,autoFocus:!0}),(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-doenet-ref`,children:`Reference ID`}),(0,t.jsx)(`input`,{id:`am-doenet-ref`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`my-activity`,value:_e,onChange:e=>ve(e.target.value),disabled:ye}),(0,t.jsxs)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:[`The reference ID is used in the inserted tag: `,(0,t.jsx)(`code`,{children:`<plus:doenet ref="${_e||`my-activity`}"/>`})]}),xe&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:xe}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:z,disabled:!ge.trim()||!_e.trim()||ye,children:ye?`Creating…`:u?`Create & Insert`:`Insert`})]})]})]})}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:r,children:`Close`})})]})})},S3=e=>{let n=Q4(e=>e.showFullPreview),r=Q4(e=>e.setShowFullPreview),i=Q4(e=>e.title),a=Q4(e=>e.updateTitle),o;return o=e.showPreviewModeToggle===!1?null:(0,t.jsxs)(`label`,{className:`pretext-plus-editor__preview-toggle`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:!n,onChange:()=>r(!n),className:`pretext-plus-editor__preview-toggle-input`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__preview-toggle-container`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-label`,children:`Simple`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-slider ${n?`pretext-plus-editor__preview-toggle-slider--active`:``}`,children:(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-dot ${n?`pretext-plus-editor__preview-toggle-dot--active`:``}`})}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-label`,children:`Full`})]}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-caption`,children:`Preview Mode`}),(0,t.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>r(!n),className:`pretext-plus-editor__preview-toggle-input`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-bar`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__menu-left`,children:(0,t.jsxs)(`label`,{className:`pretext-plus-editor__title-label`,children:[`Title`,` `,(0,t.jsx)(`input`,{className:`pretext-plus-editor__title-input`,type:`text`,value:i,onChange:e=>a(e.target.value)})]})}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-right`,children:[e.onSaveButton&&(0,t.jsx)(`button`,{className:`pretext-plus-editor__button pretext-plus-editor__button--save`,onClick:e.onSaveButton,children:e.saveButtonLabel||`Save`}),e.onCancelButton&&(0,t.jsx)(`button`,{className:`pretext-plus-editor__button pretext-plus-editor__button--cancel`,onClick:e.onCancelButton,children:e.cancelButtonLabel||`Cancel`}),(0,t.jsx)($4,{label:`Give feedback`,context:`main-editor`}),o]})]})},C3={book:`Book`,article:`Article`,slideshow:`Slideshow`,part:`Part`,chapter:`Chapter`,section:`Section`,worksheet:`Worksheet`,handout:`Handout`,exercises:`Exercises`,references:`References`,glossary:`Glossary`,solutions:`Solutions`,"reading-questions":`Reading Questions`,introduction:`Introduction`,conclusion:`Conclusion`},w3=[`part`,`chapter`,`section`,`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`],T3=({draft:e,isLatex:n,isRoot:r=!1,onDraftChange:i,onCommit:a,onCancel:o})=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-edit-form`,children:[(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Title`}),(0,t.jsx)(`input`,{type:`text`,value:e.title,onChange:t=>i({...e,title:t.target.value}),onKeyDown:e=>{e.key===`Enter`&&a(),e.key===`Escape`&&o()},autoFocus:!0})]}),!n&&(0,t.jsxs)(t.Fragment,{children:[!r&&(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Type`}),(0,t.jsx)(`select`,{value:e.type,onChange:t=>i({...e,type:t.target.value}),children:w3.map(e=>(0,t.jsx)(`option`,{value:e,children:C3[e]},e))})]}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`xml:id`}),(0,t.jsx)(`input`,{type:`text`,value:e.xmlId,placeholder:`optional`,onChange:t=>i({...e,xmlId:t.target.value})})]}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`label`}),(0,t.jsx)(`input`,{type:`text`,value:e.label,placeholder:`optional`,onChange:t=>i({...e,label:t.target.value})})]})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-edit-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-edit-save`,onClick:a,children:`Save`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-edit-cancel`,onClick:o,children:`Cancel`})]})]});function E3(e){let t=e?.parentElement??null;for(;t;){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null}var D3=({items:e})=>{let[r,i]=(0,n.useState)(!1),[a,o]=(0,n.useState)(`below`),s=(0,n.useRef)(null),c=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!r)return;let e=e=>{s.current&&!s.current.contains(e.target)&&i(!1)},t=e=>{e.key===`Escape`&&i(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]),(0,n.useLayoutEffect)(()=>{if(!r)return;let e=c.current,t=s.current;if(!e||!t)return;let n=E3(t)??document.documentElement,i=e.getBoundingClientRect(),a=n.getBoundingClientRect(),l=t.getBoundingClientRect(),u=a.bottom-l.bottom,d=l.top-a.top;o(i.height>u&&d>u?`above`:`below`)},[r]);let l=e=>{i(!1),e()};return(0,t.jsxs)(`div`,{ref:s,className:`pretext-plus-editor__toc-div-menu`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-div-menu-trigger`,onClick:e=>{e.stopPropagation(),i(e=>(e||o(`below`),!e))},"aria-haspopup":`true`,"aria-expanded":r,title:`More options`,children:`⋮`}),r&&(0,t.jsx)(`div`,{ref:c,className:[`pretext-plus-editor__toc-div-menu-popup`,a===`above`?`pretext-plus-editor__toc-div-menu-popup--above`:`pretext-plus-editor__toc-div-menu-popup--below`].join(` `),children:e.map(e=>(0,t.jsx)(`button`,{type:`button`,className:[`pretext-plus-editor__toc-div-menu-item`,e.danger?`pretext-plus-editor__toc-div-menu-item--danger`:``].filter(Boolean).join(` `),onClick:()=>l(e.onClick),children:e.label},e.label))})]})},O3=({division:e,depth:n,isActive:r,hasChildren:i,isExpanded:a,onToggleExpand:o,editDraft:s,onSelect:c,onDraftChange:l,onEditCommit:u,onEditCancel:d,menuItems:f,isLatex:p,isRoot:m=!1})=>{let h=s!==null;return(0,t.jsxs)(`li`,{className:[`pretext-plus-editor__toc-item`,`pretext-plus-editor__toc-item--${e.type}`,r?`pretext-plus-editor__toc-item--active`:``,h?`pretext-plus-editor__toc-item--editing`:``].filter(Boolean).join(` `),children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-item-row`,style:n>0?{paddingLeft:`${n*14}px`}:void 0,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-expand-btn`,onClick:o,"aria-label":a?`Collapse`:`Expand`,tabIndex:i?0:-1,style:{visibility:i?`visible`:`hidden`},children:a?`▾`:`▸`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-select`,onClick:c,"aria-current":r?`true`:void 0,title:C3[e.type]??e.type,children:(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-title`,children:e.title||(0,t.jsx)(`em`,{children:`Untitled`})})}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-actions`,children:(0,t.jsx)(D3,{items:f})})]}),h&&s&&(0,t.jsx)(T3,{draft:s,isLatex:p,isRoot:m,onDraftChange:l,onCommit:u,onCancel:d})]})},k3=p(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{XmlCdata:()=>E,XmlComment:()=>D,XmlDeclaration:()=>O,XmlDocument:()=>A,XmlDocumentType:()=>j,XmlElement:()=>k,XmlError:()=>ee,XmlNode:()=>w,XmlProcessingInstruction:()=>te,XmlText:()=>T,parseXml:()=>ie}),t.exports=c(l);var u=``,d=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,f=class{constructor(e){if(this.k=this.u(e,!0),this.d=0,this.length=e.length,this.l=this.k!==this.length,this.h=e,this.l){let t=[];for(let n=0,r=0;r<this.k;++r)t[r]=n,n+=e.codePointAt(n)>65535?2:1;this.A=t}}get B(){return this.d>=this.k}u(e,t=this.l){return t?e.replace(d,`_`).length:e.length}p(e=1){this.d=Math.min(this.k,this.d+e)}f(e=this.d){return this.l?this.A[e]??1/0:e}G(e=1){let t=this.m(e);return this.p(e),t}v(e){let t=this.f(),n=this.h.slice(t,t+e);return this.p(this.u(n)),n}w(e){let{length:t,l:n,h:r}=this,i=this.f(),a=i;if(n)for(;a<t;){let t=r[a],n=t>=`\ud800`&&t<=`\udbff`;if(n&&(t+=r[a+1]),!e(t))break;a+=n?2:1}else for(;a<t&&e(r[a]);)++a;return this.v(a-i)}b(e){let{length:t}=e,n=this.f();return e===this.h.slice(n,n+t)?(this.p(t===1?1:this.u(e)),e):u}x(e){let t=this.h.slice(this.f()).search(e);return t>0?this.v(t):u}s(e){let t=this.f(),n=this.h.indexOf(e,t);return n>0?this.v(n-t):u}m(e=1){let{d:t,h:n}=this;return this.l?n.slice(this.f(t),this.f(t+e)):n.slice(t,t+e)}n(e=0){this.d=e>=0?Math.min(this.k,e):Math.max(0,this.d+e)}},p=/["&<]/,m=/['&<]/,h=/\r\n|[\n\r\t]/g,g=/<|&|]]>/,_=Object.freeze(Object.assign(Object.create(null),{amp:`&`,apos:`'`,gt:`>`,lt:`<`,quot:`"`}));function v(e){let t=e.codePointAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||t===45||t===46||t===183||t>=768&&t<=879||t===8255||t===8256||y(e,t)}function y(e,t=e.codePointAt(0)){return t>=97&&t<=122||t>=65&&t<=90||t===58||t===95||t>=192&&t<=214||t>=216&&t<=246||t>=248&&t<=767||t>=880&&t<=893||t>=895&&t<=8191||t===8204||t===8205||t>=8304&&t<=8591||t>=11264&&t<=12271||t>=12289&&t<=55295||t>=63744&&t<=64975||t>=65008&&t<=65533||t>=65536&&t<=983039}function b(e){return e===`#`||v(e)}function x(e){let t=e.codePointAt(0);return t===32||t===9||t===10||t===13}function S(e){return e>=32&&e<=55295||e===10||e===9||e===13||e>=57344&&e<=65533||e>=65536&&e<=1114111}var C=class e{constructor(){this.parent=null,this.start=-1,this.end=-1}get document(){return this.parent?.document??null}get isRootNode(){return this.parent!==null&&this.parent===this.document&&this.type===e.TYPE_ELEMENT}get preserveWhitespace(){return!!this.parent?.preserveWhitespace}get type(){return``}toJSON(){let e={type:this.type};return this.isRootNode&&(e.isRootNode=!0),this.preserveWhitespace&&(e.preserveWhitespace=!0),this.start!==-1&&(e.start=this.start,e.end=this.end),e}};C.TYPE_CDATA=`cdata`,C.TYPE_COMMENT=`comment`,C.TYPE_DOCUMENT=`document`,C.TYPE_DOCUMENT_TYPE=`doctype`,C.TYPE_ELEMENT=`element`,C.TYPE_PROCESSING_INSTRUCTION=`pi`,C.TYPE_TEXT=`text`,C.TYPE_XML_DECLARATION=`xmldecl`;var w=C,T=class extends w{constructor(e=``){super(),this.text=e}get type(){return w.TYPE_TEXT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{text:this.text})}},E=class extends T{get type(){return w.TYPE_CDATA}},D=class extends w{constructor(e=``){super(),this.content=e}get type(){return w.TYPE_COMMENT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{content:this.content})}},O=class extends w{constructor(e,t,n){super(),this.version=e,this.encoding=t??null,this.standalone=n??null}get type(){return w.TYPE_XML_DECLARATION}toJSON(){let e=w.prototype.toJSON.call(this);e.version=this.version;for(let t of[`encoding`,`standalone`])this[t]!==null&&(e[t]=this[t]);return e}},k=class e extends w{constructor(e,t=Object.create(null),n=[]){super(),this.name=e,this.attributes=t,this.children=n}get isEmpty(){return this.children.length===0}get preserveWhitespace(){let t=this;for(;t instanceof e;){if(`xml:space`in t.attributes)return t.attributes[`xml:space`]===`preserve`;t=t.parent}return!1}get text(){return this.children.map(e=>`text`in e?e.text:``).join(``)}get type(){return w.TYPE_ELEMENT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{name:this.name,attributes:this.attributes,children:this.children.map(e=>e.toJSON())})}},A=class extends w{constructor(e=[]){super(),this.children=e}get document(){return this}get root(){for(let e of this.children)if(e instanceof k)return e;return null}get text(){return this.children.map(e=>`text`in e?e.text:``).join(``)}get type(){return w.TYPE_DOCUMENT}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{children:this.children.map(e=>e.toJSON())})}},j=class extends w{constructor(e,t,n,r){super(),this.name=e,this.publicId=t??null,this.systemId=n??null,this.internalSubset=r??null}get type(){return w.TYPE_DOCUMENT_TYPE}toJSON(){let e=w.prototype.toJSON.call(this);e.name=this.name;for(let t of[`publicId`,`systemId`,`internalSubset`])this[t]!==null&&(e[t]=this[t]);return e}},ee=class extends Error{constructor(e,t,n){let r=1,i=``,a=1;for(let e=0;e<t;++e){let t=n[e];t===`
|
|
1062
1062
|
`?(r=1,i=``,a+=1):(r+=1,i+=t)}let o=n.indexOf(`
|
|
1063
1063
|
`,t);i+=o===-1?n.slice(t):n.slice(t,o);let s=0;i.length>50&&(r<40?i=i.slice(0,50):(s=r-20,i=i.slice(s,r+30))),super(`${e} (line ${a}, column ${r})
|
|
1064
1064
|
${i}
|
|
@@ -1080,5 +1080,5 @@ Expected it to be ${r}.`}var QU=class extends Error{name=`InvalidDocError`;const
|
|
|
1080
1080
|
`+e.slice(a)}function S6(e,t){let n=RegExp(`[ \t]*${_6(t)}[ \t]*\n?`,`g`);return e.replace(n,``)}function C6(e,t,n){let r=new RegExp(_6(t)).exec(e),i=r?D6(r[0]):`<plus:division ref="${t}"/>`,a=S6(e,t);if(n!==null){let e=new RegExp(_6(n)).exec(a);if(e){let t=e.index+e[0].length;return a.slice(0,t)+`
|
|
1081
1081
|
`+i+a.slice(t)}}let o=a.lastIndexOf(`</`);return o===-1?a+`
|
|
1082
1082
|
`+i:a.slice(0,o)+i+`
|
|
1083
|
-
`+a.slice(o)}function w6(e,t,n,r){let i=new RegExp(_6(t));return i.test(e)?e.replace(i,`<plus:${r} ref="${n}"/>`):e}function T6(e,t){let n=new RegExp(_6(t));return e.find(e=>n.test(e.content))??null}function E6(e,t){let n=e,r=null;for(let e of t)n=C6(n,e,r),r=e;return n}function D6(e){return e.replace(/<plus:([a-z-]+)((?:\s[^>]*?)?)>\s*<\/plus:\1>/g,(e,t,n)=>`<plus:${t}${n}/>`)}function O6(e,t){let n=new Set,r=[t];for(;r.length>0;){let t=r.pop();if(n.has(t))continue;n.add(t);let i=e.find(e=>e.xmlId===t);if(i)for(let e of v6(i.content))r.push(e)}return n}function k6(e,t){let n=O6(e,t);return e.filter(e=>!n.has(e.xmlId))}function A6(e,t){let n=[],r=new Set([t]),i=(t,a)=>{let o=e.find(e=>e.xmlId===t);if(o)for(let s of v6(o.content)){if(r.has(s))continue;let o=e.find(e=>e.xmlId===s);o&&(r.add(s),n.push({division:o,depth:a,parentXmlId:t}),i(s,a+1))}};return i(t,0),n}function j6(e,t){let n=k6(e,t),r=new Set(n.map(e=>e.xmlId)),i=new Set;for(let e of n)for(let t of v6(e.content))r.has(t)&&i.add(t);return n.filter(e=>!i.has(e.xmlId))}function M6(e,t,n){let r=t.find(t=>t.xmlId===e);if(!r)return`<!-- missing division: ${e} -->`;if(n.has(e))return`<!-- circular reference: ${e} -->`;let i;if(r.sourceFormat===`pretext`)i=r.content;else{let{pretextSource:e,pretextError:t}=W4(r.sourceFormat===`latex`?i6(r.content,r.type):t6(r.content),r.sourceFormat),n=e??`<!-- conversion error: ${t} -->`;i=`<${r.type} xml:id="${r.xmlId}">\n<title>${r.title}</title>\n\n${n}\n</${r.type}>`}if(r.sourceFormat!==`pretext`)return i;let a=new Set(n).add(e);return i.replace(/<plus:[a-z-]+\s[^>]*ref="([^"]+)"[^>]*?(?:\/>|>\s*<\/plus:[a-z-]+>)/g,(e,n)=>M6(n,t,a))}function N6(e,t){return M6(t,e,new Set)}var P6=new Set([`part`,`chapter`]),F6=new Set([`book`,`article`,`slideshow`]);function I6(e,t,n,r){let i=F6.has(e)?t:P6.has(e)?`<book label="preview">\n<title>${r}</title>\n${t}\n</book>`:`<article label="preview">\n<title>${r}</title>\n${t}\n</article>`;return`<pretext>\n${n.trim()?`${n.trim()}\n`:``}${i}\n</pretext>`}var L6=({onOpenAssetPicker:e})=>{let r=Q4(e=>e.divisions),i=Q4(e=>e.rootDivisionId),a=Q4(e=>e.activeDivisionId),o=Q4(e=>e.selectSection),s=Q4(e=>e.removeSection),c=Q4(e=>e.divisionContentChange),l=Q4(e=>e.insertAtCursor),u=Q4(e=>e.startSectionEdit),d=Q4(e=>e.setEditDraft),f=Q4(e=>e.commitSectionEdit),p=Q4(e=>e.cancelSectionEdit),m=Q4(e=>e.editingId),h=Q4(e=>e.editDraft),g=r?r.find(e=>e.xmlId===i)??r.find(e=>e.type===`book`||e.type===`article`||e.type===`slideshow`)??r[0]??null:null,_=g&&r?A6(r,g.xmlId):[],v=g&&r?j6(r,g.xmlId):[],[y,b]=(0,n.useState)(new Set),x=e=>!y.has(e),S=e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};(0,n.useEffect)(()=>{if(!a||!g)return;let e=new Map(_.map(e=>[e.division.xmlId,e])),t=new Set;t.add(g.xmlId);let n=a;for(;n;){let r=e.get(n);if(!r?.parentXmlId)break;t.add(r.parentXmlId),n=r.parentXmlId}b(e=>{if([...t].every(t=>!e.has(t)))return e;let n=new Set(e);return t.forEach(e=>n.delete(e)),n})},[a]);let C=new Set(_.map(e=>e.parentXmlId).filter(Boolean)),w=[];if(g){let e=new Set;x(g.xmlId)&&e.add(g.xmlId);for(let t of _)t.parentXmlId&&e.has(t.parentXmlId)&&(w.push(t),x(t.division.xmlId)&&e.add(t.division.xmlId))}let T=(e,t)=>{if(!r)return;let n=r.find(e=>e.xmlId===t);n&&c(n.xmlId,D6(S6(n.content,e)))},E=(e,t)=>{if(window.confirm(`Delete "${e.title||`Untitled`}"? This permanently removes the division.`)){if(t&&r){let n=r.find(e=>e.xmlId===t);n&&c(n.xmlId,D6(S6(n.content,e.xmlId)))}s(e.xmlId)}},D=e=>{l(`<plus:${e.type} ref="${e.xmlId}"/>`)},O=e=>{g&&c(g.xmlId,D6(x6(g.content,e.xmlId,e.type,null)))};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`ul`,{className:`pretext-plus-editor__toc-list`,role:`list`,children:[g&&(0,t.jsx)(O3,{division:g,depth:0,isActive:a===g.xmlId,hasChildren:C.has(g.xmlId),isExpanded:x(g.xmlId),onToggleExpand:()=>S(g.xmlId),editDraft:m===g.xmlId?h:null,onSelect:()=>o(g.xmlId),onDraftChange:d,onEditCommit:f,onEditCancel:p,menuItems:[{label:`Edit properties`,onClick:()=>u(g)}],isLatex:g.sourceFormat===`latex`,isRoot:!0}),w.length===0&&g&&x(g.xmlId)&&(0,t.jsx)(`li`,{className:`pretext-plus-editor__toc-no-sections`,children:(0,t.jsx)(`span`,{children:`No placed divisions`})}),w.map(e=>(0,t.jsx)(O3,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:C.has(e.division.xmlId),isExpanded:x(e.division.xmlId),onToggleExpand:()=>S(e.division.xmlId),editDraft:m===e.division.xmlId?h:null,onSelect:()=>o(e.division.xmlId),onDraftChange:d,onEditCommit:f,onEditCancel:p,menuItems:[{label:`Edit properties`,onClick:()=>u(e.division)},{label:`Remove from document`,onClick:()=>T(e.division.xmlId,e.parentXmlId)},{label:`Delete from project`,onClick:()=>E(e.division,e.parentXmlId),danger:!0}],isLatex:e.division.sourceFormat===`latex`},e.division.xmlId))]}),v.length>0&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-orphans`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-orphans-heading`,children:`Unplaced divisions`}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__toc-list`,children:v.map(e=>{let i=r?A6(r,e.xmlId):[],s=new Set(i.map(e=>e.parentXmlId).filter(Boolean));return(0,t.jsxs)(n.Fragment,{children:[(0,t.jsx)(O3,{division:e,depth:0,isActive:a===e.xmlId,hasChildren:s.has(e.xmlId),isExpanded:x(e.xmlId),onToggleExpand:()=>S(e.xmlId),editDraft:m===e.xmlId?h:null,onSelect:()=>o(e.xmlId),onDraftChange:d,onEditCommit:f,onEditCancel:p,menuItems:[{label:`Edit properties`,onClick:()=>u(e)},{label:`Place in document`,onClick:()=>O(e)},{label:`Insert at cursor`,onClick:()=>D(e)},{label:`Delete from project`,onClick:()=>E(e,null),danger:!0}],isLatex:e.sourceFormat===`latex`}),x(e.xmlId)&&i.map(e=>(0,t.jsx)(O3,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:s.has(e.division.xmlId),isExpanded:x(e.division.xmlId),onToggleExpand:()=>S(e.division.xmlId),editDraft:m===e.division.xmlId?h:null,onSelect:()=>o(e.division.xmlId),onDraftChange:d,onEditCommit:f,onEditCancel:p,menuItems:[{label:`Edit properties`,onClick:()=>u(e.division)},{label:`Insert at cursor`,onClick:()=>D(e.division)},{label:`Delete from project`,onClick:()=>E(e.division,e.parentXmlId),danger:!0}],isLatex:e.division.sourceFormat===`latex`},e.division.xmlId))]},e.xmlId)})})]}),e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-btn`,onClick:e,children:`Manage Assets`})]})},R6=({isCollapsed:e,onToggleCollapse:n,onOpenAssetPicker:r})=>e?(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc pretext-plus-editor__toc--collapsed`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-toggle`,onClick:n,"aria-label":`Expand table of contents`,title:`Expand table of contents`,children:`☰`})}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-header`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-heading`,children:`Contents`}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-header-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-toggle`,onClick:n,"aria-label":`Collapse table of contents`,title:`Collapse table of contents`,children:`✕`})})]}),(0,t.jsx)(L6,{onOpenAssetPicker:r})]}),z6=class extends n.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.props.onError?.(e,t),console.error(`ErrorBoundary caught an error:`,e,t)}componentDidUpdate(e){if(this.state.error===null)return;let{resetKeys:t}=this.props,n=e.resetKeys;t&&n&&(t.length!==n.length||t.some((e,t)=>!Object.is(e,n[t])))&&this.reset()}reset=()=>{this.setState({error:null})};render(){let{error:e}=this.state;return e===null?this.props.children:this.props.fallback?this.props.fallback(e,this.reset):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__error-boundary`,role:`alert`,children:[(0,t.jsx)(`strong`,{children:`Something went wrong rendering this view.`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__error-boundary-detail`,children:e.message}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__error-boundary-retry`,onClick:this.reset,children:`Try again`})]})}};function B6(e){let t=()=>{},n={cbs:{selectDivision:t,addDivision:t,removeDivision:t,updateDivision:t,divisionContentChange:t,handleDivisionContentChange:t,assetInsert:t,updateTitle:t}};return{store:J4()((t,r)=>({source:e.source,sourceFormat:e.sourceFormat,projectAssets:void 0,libraryAssets:void 0,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,projectType:e.projectType,projectUrl:void 0,divisions:e.divisions,rootDivisionId:void 0,activeDivisionId:e.activeDivisionId,canConvertToPretext:!0,activeEditorSource:e.source,hasFeedback:!1,isTocCollapsed:!1,showFullPreview:!0,isNarrowScreen:typeof window<`u`?window.innerWidth<800:!1,activeTab:`editor`,isLatexDialogOpen:!1,isConvertDialogOpen:!1,isDocinfoEditorOpen:!1,isAssetPickerOpen:!1,editingId:null,editDraft:null,syncState:e=>t(e),applyExternalUpdate:e=>t(e),setDivisionContent:(e,n)=>t(t=>{if(!t.divisions)return{};let r=!1,i=t.divisions.map(t=>t.xmlId===e&&t.content!==n?(r=!0,{...t,content:n}):t);return r?{divisions:i}:{}}),patchDivision:(e,n)=>t(t=>t.divisions?{divisions:t.divisions.map(t=>t.xmlId===e?{...t,...n.title!==void 0&&{title:n.title},...n.type!==void 0&&{type:n.type},...n.xmlId!=null&&{xmlId:n.xmlId},...n.sourceFormat!==void 0&&{sourceFormat:n.sourceFormat}}:t)}:{}),addDivisionToPool:e=>t(t=>{let n=t.divisions??[];return n.some(t=>t.xmlId===e.xmlId)?{}:{divisions:[...n,e]}}),removeDivisionFromPool:e=>t(t=>({divisions:(t.divisions??[]).filter(t=>t.xmlId!==e)})),setActiveDivisionId:e=>t({activeDivisionId:e}),setTitle:e=>t({title:e}),setDocinfo:({docinfo:e,commonDocinfo:n,useCommonDocinfo:r})=>t({docinfo:e,commonDocinfo:n,useCommonDocinfo:r}),setShowFullPreview:e=>t({showFullPreview:e}),setActiveTab:e=>t({activeTab:e}),setIsNarrowScreen:e=>t({isNarrowScreen:e}),setIsTocCollapsed:e=>t(t=>({isTocCollapsed:typeof e==`function`?e(t.isTocCollapsed):e})),openModal:e=>t({[e]:!0}),closeModal:e=>t({[e]:!1}),selectSection:e=>n.cbs.selectDivision(e),addSection:e=>n.cbs.addDivision(e),removeSection:e=>n.cbs.removeDivision(e),updateSection:(e,t)=>n.cbs.updateDivision(e,t),divisionContentChange:(e,t)=>n.cbs.divisionContentChange?.(e,t),startSectionEdit:e=>{let{xmlId:n,label:r}=p6(e.content);t({editingId:e.xmlId,editDraft:{title:e.title,type:e.type,xmlId:n,label:r}})},setEditDraft:e=>t({editDraft:e}),commitSectionEdit:()=>{let{editingId:e,editDraft:i}=r();e&&i&&n.cbs.updateDivision(e,{title:i.title.trim()||void 0,type:i.type,xmlId:i.xmlId.trim()||null,label:i.label.trim()||null}),t({editingId:null,editDraft:null})},cancelSectionEdit:()=>t({editingId:null,editDraft:null}),insertAsset:e=>n.cbs.assetInsert(e),insertAtCursor:e=>n.cbs.insertContentAtCursor?.(e),updateTitle:e=>n.cbs.updateTitle(e),feedbackSubmit:e=>n.cbs.feedbackSubmit?.(e)})),bindCallbacks:e=>{n.cbs=e}}}function V6({store:e,children:n}){return(0,t.jsx)(Z4.Provider,{value:e,children:n})}var H6=(e,t)=>e.find(e=>t?e.xmlId===t:e.type===`book`||e.type===`article`||e.type===`slideshow`)??e[0]??null,U6=e=>{let[r]=(0,n.useState)(()=>{let t=H6(e.divisions,e.rootDivisionId),n=e.activeDivisionId??t?.xmlId??null,r=e.divisions.find(e=>e.xmlId===n)??t;return B6({source:r?.content??``,sourceFormat:r?.sourceFormat??`pretext`,title:e.title??`Document Title`,docinfo:e.docinfo??``,commonDocinfo:e.commonDocinfo??``,useCommonDocinfo:e.useCommonDocinfo??!1,projectType:e.projectType,divisions:e.divisions,activeDivisionId:n})});return(0,t.jsx)(V6,{store:r.store,children:(0,t.jsx)(W6,{...e,bindCallbacks:r.bindCallbacks})})},W6=e=>{let{bindCallbacks:r}=e,i=Q4(e=>e.showFullPreview),a=Q4(e=>e.isNarrowScreen),o=Q4(e=>e.setIsNarrowScreen),s=Q4(e=>e.activeTab),c=Q4(e=>e.setActiveTab),l=Q4(e=>e.isTocCollapsed),u=Q4(e=>e.setIsTocCollapsed),d=Q4(e=>e.isLatexDialogOpen),f=Q4(e=>e.isConvertDialogOpen),p=Q4(e=>e.isDocinfoEditorOpen),m=Q4(e=>e.isAssetPickerOpen),h=Q4(e=>e.openModal),g=Q4(e=>e.closeModal),_=Q4(e=>e.syncState),v=Q4(e=>e.divisions)??[],y=Q4(e=>e.activeDivisionId),b=Q4(e=>e.title),x=Q4(e=>e.docinfo),S=Q4(e=>e.commonDocinfo),C=Q4(e=>e.useCommonDocinfo),w=Q4(e=>e.applyExternalUpdate),T=Q4(e=>e.setDivisionContent),E=Q4(e=>e.patchDivision),D=Q4(e=>e.addDivisionToPool),O=Q4(e=>e.removeDivisionFromPool),k=Q4(e=>e.setActiveDivisionId),A=Q4(e=>e.setTitle),j=Q4(e=>e.setDocinfo),ee=(0,n.useRef)(null),te=(0,n.useRef)(null),ne=H6(v,e.rootDivisionId),re=v.find(e=>e.xmlId===y)??v[0]??null,M=re?.sourceFormat??`pretext`,ie=re?.content??``,ae=(t,n,r,i)=>{T(t,n),e.onContentChange({xmlId:t,sourceContent:n,sourceFormat:r,pretextSource:r===`pretext`?n:void 0,...i})},oe=(t,n)=>{E(t,n),e.onDivisionUpdate?.(t,n)},N=t=>{D(t),e.onDivisionAdd?.(t)},se=t=>{O(t),e.onDivisionRemove?.(t)},P=t=>{k(t),e.onDivisionSelect?.(t)},ce=(0,n.useMemo)(()=>{if(!re||M===`pretext`)return;let e=W4(ie,M);return e.pretextError?void 0:e.pretextSource},[re,M,ie]),le=e=>{if(!re)return;let t=M===`pretext`?D6(e||``):e||``;if(t===re.content)return;if(ae(re.xmlId,t,M),M===`pretext`){let e=m6(t);if(e){oe(re.xmlId,{title:e.title,type:e.type,xmlId:e.xmlId||null,label:e.label||null});let t=e.xmlId||re.xmlId;if(t!==re.xmlId||e.type!==re.type){let n=T6(v,re.xmlId);if(n){let r=w6(n.content,re.xmlId,t,e.type);r!==n.content&&ae(n.xmlId,r,n.sourceFormat)}}e.xmlId&&e.xmlId!==re.xmlId&&P(e.xmlId)}}else if(M===`latex`&&re.type===`section`){let e=c6(t);e!==null&&oe(re.xmlId,{title:e})}let n=new Set(v.map(e=>e.xmlId));for(let{xmlId:e,type:r}of y6(t))n.has(e)||(N(b6(e,r,M)),n.add(e))},ue=e=>{P(e)},de=()=>{let e=Q3();N(e),k(e.xmlId)},F=e=>e.ref?`<plus:${e.kind} ref="${e.ref}"/>`:``,fe=t=>{let n=F(t);n&&te.current?.insertAtCursor(n),e.onAssetInsert?.(t)};(0,n.useEffect)(()=>{let e=()=>o(window.innerWidth<800);return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[o]);let pe=M!==`pretext`;(0,n.useLayoutEffect)(()=>{r({selectDivision:ue,addDivision:()=>de(),removeDivision:e=>se(e),updateDivision:(e,t)=>oe(e,t),divisionContentChange:(e,t)=>{ae(e,t,v.find(t=>t.xmlId===e)?.sourceFormat??`pretext`)},handleDivisionContentChange:le,assetInsert:fe,insertContentAtCursor:e=>te.current?.insertAtCursor(e),updateTitle:t=>{A(t),e.onTitleChange?.(t)},feedbackSubmit:e.onFeedbackSubmit})}),(0,n.useEffect)(()=>{_({source:ie,sourceFormat:M,projectAssets:e.projectAssets,libraryAssets:e.libraryAssets,projectType:e.projectType,projectUrl:e.projectUrl,rootDivisionId:ne?.xmlId,canConvertToPretext:ce!==void 0,activeEditorSource:ie,hasFeedback:e.onFeedbackSubmit!==void 0})});let me=(0,n.useRef)({divisions:e.divisions,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,activeDivisionId:e.activeDivisionId});(0,n.useEffect)(()=>{let t=me.current,n={},r=!1;if(e.divisions!==t.divisions){n.divisions=e.divisions;let t=H6(e.divisions,e.rootDivisionId);(y==null||!e.divisions.some(e=>e.xmlId===y))&&(n.activeDivisionId=t?.xmlId??null),r=!0}e.title!==void 0&&e.title!==t.title&&(n.title=e.title,r=!0),e.docinfo!==void 0&&e.docinfo!==t.docinfo&&(n.docinfo=e.docinfo,r=!0),e.commonDocinfo!==void 0&&e.commonDocinfo!==t.commonDocinfo&&(n.commonDocinfo=e.commonDocinfo,r=!0),e.useCommonDocinfo!==void 0&&e.useCommonDocinfo!==t.useCommonDocinfo&&(n.useCommonDocinfo=e.useCommonDocinfo,r=!0),e.activeDivisionId!==void 0&&e.activeDivisionId!==t.activeDivisionId&&(n.activeDivisionId=e.activeDivisionId,r=!0),r&&w(n),me.current={divisions:e.divisions,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,activeDivisionId:e.activeDivisionId}});let he=C?S:x,ge=re?M===`pretext`?N6(v,re.xmlId):ce===void 0?void 0:`<${re.type} xml:id="${re.xmlId}">\n<title>${re.title}</title>\n\n${ce}\n</${re.type}>`:void 0,I=re&&ge!==void 0?I6(re.type,ge,he,re.title):void 0,_e=()=>ee.current?.rebuild(),ve=()=>{e.onSave?.(),ee.current?.rebuild()},ye=t=>{let n=t.ctrlKey||t.metaKey;n&&t.key===`Enter`&&e.onPreviewRebuild?(t.preventDefault(),_e()):n&&t.key===`s`&&(t.preventDefault(),ve())},be=()=>{if(!re||!ce)return;let e=Q3(),t=D6(n6(ce,re.type));N({id:e.xmlId,xmlId:e.xmlId,title:re.title,type:re.type,sourceFormat:`pretext`,content:t})},xe=(0,t.jsx)(Ps,{ref:te,content:ie,sourceFormat:M,onChange:le,onRebuild:e.onPreviewRebuild?_e:void 0,onSave:ve,onOpenLatexImport:()=>h(`isLatexDialogOpen`),onOpenDocinfoEditor:()=>h(`isDocinfoEditorOpen`),onOpenConvertToPretext:pe&&ce!==void 0?()=>h(`isConvertDialogOpen`):void 0,canConvertToPretext:ce!==void 0,onOpenAssets:e.projectAssets!==void 0&&M===`pretext`?()=>h(`isAssetPickerOpen`):void 0}),Se;Se=i&&e.onPreviewRebuild?(0,t.jsx)($L,{ref:ee,content:I||``,title:b,onRebuild:e.onPreviewRebuild}):(0,t.jsx)(XL,{content:ie,canEdit:M===`pretext`,editDisabledReason:M===`markdown`?`Visual editing is not available for Markdown documents.`:M===`latex`?`Visual editing is not available for LaTeX documents.`:``,onChange:e=>le(e)});let Ce=(0,t.jsx)(R6,{isCollapsed:l,onToggleCollapse:()=>u(e=>!e),onOpenAssetPicker:e.projectAssets===void 0?void 0:()=>h(`isAssetPickerOpen`)}),L=`pretext-plus-tab-editor`,we=`pretext-plus-tab-preview`,Te=`pretext-plus-tabpanel`,Ee=a&&Ce?(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-drawer`,children:l?(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-drawer-toggle`,onClick:()=>u(!1),children:`☰ Contents`}):(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-drawer-open`,children:Ce})}):null,R;return R=a?(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tabs`,children:[Ee,(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tab-list`,role:`tablist`,children:[(0,t.jsx)(`button`,{type:`button`,id:L,role:`tab`,"aria-controls":Te,"aria-selected":s===`editor`,tabIndex:s===`editor`?0:-1,className:`pretext-plus-editor__tab-button ${s===`editor`?`is-active`:``}`,onClick:()=>c(`editor`),children:`Editor`}),(0,t.jsx)(`button`,{type:`button`,id:we,role:`tab`,"aria-controls":Te,"aria-selected":s===`preview`,tabIndex:s===`preview`?0:-1,className:`pretext-plus-editor__tab-button ${s===`preview`?`is-active`:``}`,onClick:()=>c(`preview`),children:`Preview`})]}),(0,t.jsx)(`div`,{id:Te,className:`pretext-plus-editor__tab-panel`,role:`tabpanel`,"aria-labelledby":s===`editor`?L:we,children:(0,t.jsx)(`div`,{style:{height:`100%`},children:s===`editor`?xe:Se})})]}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__sectioned-layout`,children:[Ce,(0,t.jsxs)(gt,{orientation:`horizontal`,className:`pretext-plus-editor__splitter`,children:[(0,t.jsx)(yt,{className:`pretext-plus-editor__editor-panel`,children:xe}),(0,t.jsx)(St,{className:`pretext-plus-editor__resize-handle`,children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__resize-dots`})}),(0,t.jsx)(yt,{className:`pretext-plus-editor__preview-panel`,children:Se})]})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor`,onKeyDown:ye,children:[(0,t.jsx)(S3,{onSaveButton:e.onSaveButton,saveButtonLabel:e.saveButtonLabel,onCancelButton:e.onCancelButton,cancelButtonLabel:e.cancelButtonLabel,showPreviewModeToggle:e.onPreviewRebuild!==void 0}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__editor-displays`,children:[(0,t.jsx)(z6,{resetKeys:[ie,y],children:R}),d?(0,t.jsx)(e3,{onClose:()=>g(`isLatexDialogOpen`)}):null,f&&re&&ce?(0,t.jsx)(i3,{sourceContent:ie,sourceFormat:M,pretextSource:ce,onConfirm:be,onClose:()=>g(`isConvertDialogOpen`)}):null,p?(0,t.jsx)(g3,{docinfo:x,showCommonDocinfoControls:!0,commonDocinfo:S,initialUseCommonDocinfo:C,onClose:t=>{if(g(`isDocinfoEditorOpen`),t!==void 0){j({docinfo:t.docinfo,commonDocinfo:t.commonDocinfo,useCommonDocinfo:t.useCommonDocinfo}),e.onCommonDocinfoChange?.(t.commonDocinfo),e.onUseCommonDocinfoChange?.(t.useCommonDocinfo);let n=ne??re;ae(n?.xmlId??``,n?.content??``,n?.sourceFormat??`pretext`,{docinfo:t.docinfo,commonDocinfo:t.commonDocinfo,useCommonDocinfo:t.useCommonDocinfo})}}}):null,m&&e.projectAssets!==void 0?(0,t.jsx)(x3,{open:m,onClose:()=>g(`isAssetPickerOpen`),onLoadAssets:e.onLoadAssets,onLoadLibraryAssets:e.onLoadLibraryAssets,onAddFromLibrary:e.onAssetAddFromLibrary,onUpload:e.onAssetUpload,onAddUrl:e.onAssetAddUrl,onCreateDoenet:e.onCreateDoenet,onRemoveAsset:e.onAssetRemove,onInsert:fe}):null]})]})};e.CodeEditor=Ps,e.DocinfoEditor=g3,e.Editors=U6,e.FeedbackLink=K4,e.FullPreview=$L,e.VisualEditor=XL,e.assembleProjectSource=N6,e.buildDivisionTree=A6,e.convertLatexToPretext=V4,e.createConclusion=e6,e.createIntroduction=$3,e.createLatexConclusion=d6,e.createLatexIntroduction=u6,e.createNewLatexSection=l6,e.createNewSection=Q3,e.derivePretextContent=W4,e.detectSourceFormat=B4,e.ensureLatexSectionWrapper=o6,e.ensureSectionWrapper=r6,e.extractDivisionMetadata=m6,e.extractLatexDivisionTitle=c6,e.findDivisionParent=T6,e.getOrphanRoots=j6,e.getOrphanedDivisions=k6,e.getSectionAttributes=p6,e.insertDivisionRef=x6,e.mergeTwoSections=f6,e.moveDivisionRef=C6,e.normalizeSelfClosingRefs=D6,e.parseDivisionRefs=v6,e.postToIframe=QL,e.removeDivisionRef=S6,e.renameDivisionRef=w6,e.reorderDivisionRefs=E6,e.rewrapLatexSection=a6,e.rewrapSection=n6,e.stripLatexSectionWrapper=i6,e.stripSectionWrapper=t6,e.updateDivisionTitle=Z3,e.updateLatexSectionTitle=s6,e.updateSectionMetadata=h6,e.wrapDivisionForPreview=I6});
|
|
1083
|
+
`+a.slice(o)}function w6(e,t,n,r){let i=new RegExp(_6(t));return i.test(e)?e.replace(i,`<plus:${r} ref="${n}"/>`):e}function T6(e,t){let n=new RegExp(_6(t));return e.find(e=>n.test(e.content))??null}function E6(e,t){let n=e,r=null;for(let e of t)n=C6(n,e,r),r=e;return n}function D6(e){return e.replace(/<plus:([a-z-]+)((?:\s[^>]*?)?)>\s*<\/plus:\1>/g,(e,t,n)=>`<plus:${t}${n}/>`)}function O6(e,t){let n=new Set,r=[t];for(;r.length>0;){let t=r.pop();if(n.has(t))continue;n.add(t);let i=e.find(e=>e.xmlId===t);if(i)for(let e of v6(i.content))r.push(e)}return n}function k6(e,t){let n=O6(e,t);return e.filter(e=>!n.has(e.xmlId))}function A6(e,t){let n=[],r=new Set([t]),i=(t,a)=>{let o=e.find(e=>e.xmlId===t);if(o)for(let s of v6(o.content)){if(r.has(s))continue;let o=e.find(e=>e.xmlId===s);o&&(r.add(s),n.push({division:o,depth:a,parentXmlId:t}),i(s,a+1))}};return i(t,0),n}function j6(e,t){let n=k6(e,t),r=new Set(n.map(e=>e.xmlId)),i=new Set;for(let e of n)for(let t of v6(e.content))r.has(t)&&i.add(t);return n.filter(e=>!i.has(e.xmlId))}var M6=new Set([`book`,`article`,`slideshow`]);function N6(e){try{let t=N3(e),n=t.children.find(e=>e.type===`element`),r=n?.name===`pretext`?n.children.find(e=>e.type===`element`):n;if(!r)return e;if(!r.attributes.label){let e=F6(t,`pretext-plus-preview`);return r.attributes.label=e,console.log(`Added label="${e}" to root element ${r.name} for previewing.`),TY(t)}return e}catch(t){return console.error(`Error ensuring label:`,t),e}}function P6(e,t){return e.type===`element`&&e.attributes?.label===t?!0:`children`in e&&e.children?e.children.some(e=>e.type===`element`?P6(e,t):!1):!1}function F6(e,t){let n=t,r=1;for(;P6(e,n);)n=`${t}-${r}`,r++;return n}function I6(e,t,n){let r=t.find(t=>t.xmlId===e);if(!r)return`<!-- missing division: ${e} -->`;if(n.has(e))return`<!-- circular reference: ${e} -->`;let i;if(r.sourceFormat===`pretext`)i=r.content;else{let{pretextSource:e,pretextError:t}=W4(r.sourceFormat===`latex`?i6(r.content,r.type):t6(r.content),r.sourceFormat),n=e??`<!-- conversion error: ${t} -->`;i=`<${r.type} xml:id="${r.xmlId}">\n<title>${r.title}</title>\n\n${n}\n</${r.type}>`}if(r.sourceFormat!==`pretext`)return i;let a=new Set(n).add(e);return i.replace(/<plus:[a-z-]+\s[^>]*ref="([^"]+)"[^>]*?(?:\/>|>\s*<\/plus:[a-z-]+>)/g,(e,n)=>I6(n,t,a))}function L6(e,t){return N6(I6(t,e,new Set))}function R6(e,t){return N6(`<pretext>\n${t.trim()?`${t.trim()}\n`:``}${e}\n</pretext>`)}function z6(e,t,n){return R6(I6(t,e,new Set),n)}var B6=new Set([`part`,`chapter`]);function V6(e,t,n,r){return R6(M6.has(e)?t:B6.has(e)?`<book>\n<title>${r}</title>\n${t}\n</book>`:`<article>\n<title>${r}</title>\n${t}\n</article>`,n)}var H6=({onOpenAssetPicker:e})=>{let r=Q4(e=>e.divisions),i=Q4(e=>e.rootDivisionId),a=Q4(e=>e.activeDivisionId),o=Q4(e=>e.selectSection),s=Q4(e=>e.removeSection),c=Q4(e=>e.divisionContentChange),l=Q4(e=>e.insertAtCursor),u=Q4(e=>e.startSectionEdit),d=Q4(e=>e.setEditDraft),f=Q4(e=>e.commitSectionEdit),p=Q4(e=>e.cancelSectionEdit),m=Q4(e=>e.editingId),h=Q4(e=>e.editDraft),g=r?r.find(e=>e.xmlId===i)??r.find(e=>e.type===`book`||e.type===`article`||e.type===`slideshow`)??r[0]??null:null,_=g&&r?A6(r,g.xmlId):[],v=g&&r?j6(r,g.xmlId):[],[y,b]=(0,n.useState)(new Set),x=e=>!y.has(e),S=e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};(0,n.useEffect)(()=>{if(!a||!g)return;let e=new Map(_.map(e=>[e.division.xmlId,e])),t=new Set;t.add(g.xmlId);let n=a;for(;n;){let r=e.get(n);if(!r?.parentXmlId)break;t.add(r.parentXmlId),n=r.parentXmlId}b(e=>{if([...t].every(t=>!e.has(t)))return e;let n=new Set(e);return t.forEach(e=>n.delete(e)),n})},[a]);let C=new Set(_.map(e=>e.parentXmlId).filter(Boolean)),w=[];if(g){let e=new Set;x(g.xmlId)&&e.add(g.xmlId);for(let t of _)t.parentXmlId&&e.has(t.parentXmlId)&&(w.push(t),x(t.division.xmlId)&&e.add(t.division.xmlId))}let T=(e,t)=>{if(!r)return;let n=r.find(e=>e.xmlId===t);n&&c(n.xmlId,D6(S6(n.content,e)))},E=(e,t)=>{if(window.confirm(`Delete "${e.title||`Untitled`}"? This permanently removes the division.`)){if(t&&r){let n=r.find(e=>e.xmlId===t);n&&c(n.xmlId,D6(S6(n.content,e.xmlId)))}s(e.xmlId)}},D=e=>{l(`<plus:${e.type} ref="${e.xmlId}"/>`)},O=e=>{g&&c(g.xmlId,D6(x6(g.content,e.xmlId,e.type,null)))};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`ul`,{className:`pretext-plus-editor__toc-list`,role:`list`,children:[g&&(0,t.jsx)(O3,{division:g,depth:0,isActive:a===g.xmlId,hasChildren:C.has(g.xmlId),isExpanded:x(g.xmlId),onToggleExpand:()=>S(g.xmlId),editDraft:m===g.xmlId?h:null,onSelect:()=>o(g.xmlId),onDraftChange:d,onEditCommit:f,onEditCancel:p,menuItems:[{label:`Edit properties`,onClick:()=>u(g)}],isLatex:g.sourceFormat===`latex`,isRoot:!0}),w.length===0&&g&&x(g.xmlId)&&(0,t.jsx)(`li`,{className:`pretext-plus-editor__toc-no-sections`,children:(0,t.jsx)(`span`,{children:`No placed divisions`})}),w.map(e=>(0,t.jsx)(O3,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:C.has(e.division.xmlId),isExpanded:x(e.division.xmlId),onToggleExpand:()=>S(e.division.xmlId),editDraft:m===e.division.xmlId?h:null,onSelect:()=>o(e.division.xmlId),onDraftChange:d,onEditCommit:f,onEditCancel:p,menuItems:[{label:`Edit properties`,onClick:()=>u(e.division)},{label:`Remove from document`,onClick:()=>T(e.division.xmlId,e.parentXmlId)},{label:`Delete from project`,onClick:()=>E(e.division,e.parentXmlId),danger:!0}],isLatex:e.division.sourceFormat===`latex`},e.division.xmlId))]}),v.length>0&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-orphans`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-orphans-heading`,children:`Unplaced divisions`}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__toc-list`,children:v.map(e=>{let i=r?A6(r,e.xmlId):[],s=new Set(i.map(e=>e.parentXmlId).filter(Boolean));return(0,t.jsxs)(n.Fragment,{children:[(0,t.jsx)(O3,{division:e,depth:0,isActive:a===e.xmlId,hasChildren:s.has(e.xmlId),isExpanded:x(e.xmlId),onToggleExpand:()=>S(e.xmlId),editDraft:m===e.xmlId?h:null,onSelect:()=>o(e.xmlId),onDraftChange:d,onEditCommit:f,onEditCancel:p,menuItems:[{label:`Edit properties`,onClick:()=>u(e)},{label:`Place in document`,onClick:()=>O(e)},{label:`Insert at cursor`,onClick:()=>D(e)},{label:`Delete from project`,onClick:()=>E(e,null),danger:!0}],isLatex:e.sourceFormat===`latex`}),x(e.xmlId)&&i.map(e=>(0,t.jsx)(O3,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:s.has(e.division.xmlId),isExpanded:x(e.division.xmlId),onToggleExpand:()=>S(e.division.xmlId),editDraft:m===e.division.xmlId?h:null,onSelect:()=>o(e.division.xmlId),onDraftChange:d,onEditCommit:f,onEditCancel:p,menuItems:[{label:`Edit properties`,onClick:()=>u(e.division)},{label:`Insert at cursor`,onClick:()=>D(e.division)},{label:`Delete from project`,onClick:()=>E(e.division,e.parentXmlId),danger:!0}],isLatex:e.division.sourceFormat===`latex`},e.division.xmlId))]},e.xmlId)})})]}),e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-btn`,onClick:e,children:`Manage Assets`})]})},U6=({isCollapsed:e,onToggleCollapse:n,onOpenAssetPicker:r})=>e?(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc pretext-plus-editor__toc--collapsed`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-toggle`,onClick:n,"aria-label":`Expand table of contents`,title:`Expand table of contents`,children:`☰`})}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-header`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-heading`,children:`Contents`}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-header-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-toggle`,onClick:n,"aria-label":`Collapse table of contents`,title:`Collapse table of contents`,children:`✕`})})]}),(0,t.jsx)(H6,{onOpenAssetPicker:r})]}),W6=class extends n.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.props.onError?.(e,t),console.error(`ErrorBoundary caught an error:`,e,t)}componentDidUpdate(e){if(this.state.error===null)return;let{resetKeys:t}=this.props,n=e.resetKeys;t&&n&&(t.length!==n.length||t.some((e,t)=>!Object.is(e,n[t])))&&this.reset()}reset=()=>{this.setState({error:null})};render(){let{error:e}=this.state;return e===null?this.props.children:this.props.fallback?this.props.fallback(e,this.reset):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__error-boundary`,role:`alert`,children:[(0,t.jsx)(`strong`,{children:`Something went wrong rendering this view.`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__error-boundary-detail`,children:e.message}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__error-boundary-retry`,onClick:this.reset,children:`Try again`})]})}};function G6(e){let t=()=>{},n={cbs:{selectDivision:t,addDivision:t,removeDivision:t,updateDivision:t,divisionContentChange:t,handleDivisionContentChange:t,assetInsert:t,updateTitle:t}};return{store:J4()((t,r)=>({source:e.source,sourceFormat:e.sourceFormat,projectAssets:void 0,libraryAssets:void 0,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,projectType:e.projectType,projectUrl:void 0,divisions:e.divisions,rootDivisionId:void 0,activeDivisionId:e.activeDivisionId,canConvertToPretext:!0,activeEditorSource:e.source,hasFeedback:!1,isTocCollapsed:!1,showFullPreview:!0,isNarrowScreen:typeof window<`u`?window.innerWidth<800:!1,activeTab:`editor`,isLatexDialogOpen:!1,isConvertDialogOpen:!1,isDocinfoEditorOpen:!1,isAssetPickerOpen:!1,editingId:null,editDraft:null,syncState:e=>t(e),applyExternalUpdate:e=>t(e),setDivisionContent:(e,n)=>t(t=>{if(!t.divisions)return{};let r=!1,i=t.divisions.map(t=>t.xmlId===e&&t.content!==n?(r=!0,{...t,content:n}):t);return r?{divisions:i}:{}}),patchDivision:(e,n)=>t(t=>t.divisions?{divisions:t.divisions.map(t=>t.xmlId===e?{...t,...n.title!==void 0&&{title:n.title},...n.type!==void 0&&{type:n.type},...n.xmlId!=null&&{xmlId:n.xmlId},...n.sourceFormat!==void 0&&{sourceFormat:n.sourceFormat}}:t)}:{}),addDivisionToPool:e=>t(t=>{let n=t.divisions??[];return n.some(t=>t.xmlId===e.xmlId)?{}:{divisions:[...n,e]}}),removeDivisionFromPool:e=>t(t=>({divisions:(t.divisions??[]).filter(t=>t.xmlId!==e)})),setActiveDivisionId:e=>t({activeDivisionId:e}),setTitle:e=>t({title:e}),setDocinfo:({docinfo:e,commonDocinfo:n,useCommonDocinfo:r})=>t({docinfo:e,commonDocinfo:n,useCommonDocinfo:r}),setShowFullPreview:e=>t({showFullPreview:e}),setActiveTab:e=>t({activeTab:e}),setIsNarrowScreen:e=>t({isNarrowScreen:e}),setIsTocCollapsed:e=>t(t=>({isTocCollapsed:typeof e==`function`?e(t.isTocCollapsed):e})),openModal:e=>t({[e]:!0}),closeModal:e=>t({[e]:!1}),selectSection:e=>n.cbs.selectDivision(e),addSection:e=>n.cbs.addDivision(e),removeSection:e=>n.cbs.removeDivision(e),updateSection:(e,t)=>n.cbs.updateDivision(e,t),divisionContentChange:(e,t)=>n.cbs.divisionContentChange?.(e,t),startSectionEdit:e=>{let{xmlId:n,label:r}=p6(e.content);t({editingId:e.xmlId,editDraft:{title:e.title,type:e.type,xmlId:n,label:r}})},setEditDraft:e=>t({editDraft:e}),commitSectionEdit:()=>{let{editingId:e,editDraft:i}=r();e&&i&&n.cbs.updateDivision(e,{title:i.title.trim()||void 0,type:i.type,xmlId:i.xmlId.trim()||null,label:i.label.trim()||null}),t({editingId:null,editDraft:null})},cancelSectionEdit:()=>t({editingId:null,editDraft:null}),insertAsset:e=>n.cbs.assetInsert(e),insertAtCursor:e=>n.cbs.insertContentAtCursor?.(e),updateTitle:e=>n.cbs.updateTitle(e),feedbackSubmit:e=>n.cbs.feedbackSubmit?.(e)})),bindCallbacks:e=>{n.cbs=e}}}function K6({store:e,children:n}){return(0,t.jsx)(Z4.Provider,{value:e,children:n})}var q6=(e,t)=>e.find(e=>t?e.xmlId===t:e.type===`book`||e.type===`article`||e.type===`slideshow`)??e[0]??null,J6=e=>{let[r]=(0,n.useState)(()=>{let t=q6(e.divisions,e.rootDivisionId),n=e.activeDivisionId??t?.xmlId??null,r=e.divisions.find(e=>e.xmlId===n)??t;return G6({source:r?.content??``,sourceFormat:r?.sourceFormat??`pretext`,title:e.title??`Document Title`,docinfo:e.docinfo??``,commonDocinfo:e.commonDocinfo??``,useCommonDocinfo:e.useCommonDocinfo??!1,projectType:e.projectType,divisions:e.divisions,activeDivisionId:n})});return(0,t.jsx)(K6,{store:r.store,children:(0,t.jsx)(Y6,{...e,bindCallbacks:r.bindCallbacks})})},Y6=e=>{let{bindCallbacks:r}=e,i=Q4(e=>e.showFullPreview),a=Q4(e=>e.isNarrowScreen),o=Q4(e=>e.setIsNarrowScreen),s=Q4(e=>e.activeTab),c=Q4(e=>e.setActiveTab),l=Q4(e=>e.isTocCollapsed),u=Q4(e=>e.setIsTocCollapsed),d=Q4(e=>e.isLatexDialogOpen),f=Q4(e=>e.isConvertDialogOpen),p=Q4(e=>e.isDocinfoEditorOpen),m=Q4(e=>e.isAssetPickerOpen),h=Q4(e=>e.openModal),g=Q4(e=>e.closeModal),_=Q4(e=>e.syncState),v=Q4(e=>e.divisions)??[],y=Q4(e=>e.activeDivisionId),b=Q4(e=>e.title),x=Q4(e=>e.docinfo),S=Q4(e=>e.commonDocinfo),C=Q4(e=>e.useCommonDocinfo),w=Q4(e=>e.applyExternalUpdate),T=Q4(e=>e.setDivisionContent),E=Q4(e=>e.patchDivision),D=Q4(e=>e.addDivisionToPool),O=Q4(e=>e.removeDivisionFromPool),k=Q4(e=>e.setActiveDivisionId),A=Q4(e=>e.setTitle),j=Q4(e=>e.setDocinfo),ee=(0,n.useRef)(null),te=(0,n.useRef)(null),ne=q6(v,e.rootDivisionId),re=v.find(e=>e.xmlId===y)??v[0]??null,M=re?.sourceFormat??`pretext`,ie=re?.content??``,ae=(t,n,r,i)=>{T(t,n),e.onContentChange({xmlId:t,sourceContent:n,sourceFormat:r,pretextSource:r===`pretext`?n:void 0,...i})},oe=(t,n)=>{E(t,n),e.onDivisionUpdate?.(t,n)},N=t=>{D(t),e.onDivisionAdd?.(t)},se=t=>{O(t),e.onDivisionRemove?.(t)},P=t=>{k(t),e.onDivisionSelect?.(t)},ce=(0,n.useMemo)(()=>{if(!re||M===`pretext`)return;let e=W4(ie,M);return e.pretextError?void 0:e.pretextSource},[re,M,ie]),le=e=>{if(!re)return;let t=M===`pretext`?D6(e||``):e||``;if(t===re.content)return;if(ae(re.xmlId,t,M),M===`pretext`){let e=m6(t);if(e){oe(re.xmlId,{title:e.title,type:e.type,xmlId:e.xmlId||null,label:e.label||null});let t=e.xmlId||re.xmlId;if(t!==re.xmlId||e.type!==re.type){let n=T6(v,re.xmlId);if(n){let r=w6(n.content,re.xmlId,t,e.type);r!==n.content&&ae(n.xmlId,r,n.sourceFormat)}}e.xmlId&&e.xmlId!==re.xmlId&&P(e.xmlId)}}else if(M===`latex`&&re.type===`section`){let e=c6(t);e!==null&&oe(re.xmlId,{title:e})}let n=new Set(v.map(e=>e.xmlId));for(let{xmlId:e,type:r}of y6(t))n.has(e)||(N(b6(e,r,M)),n.add(e))},ue=e=>{P(e)},de=()=>{let e=Q3();N(e),k(e.xmlId)},F=e=>e.ref?`<plus:${e.kind} ref="${e.ref}"/>`:``,fe=t=>{let n=F(t);n&&te.current?.insertAtCursor(n),e.onAssetInsert?.(t)};(0,n.useEffect)(()=>{let e=()=>o(window.innerWidth<800);return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[o]);let pe=M!==`pretext`;(0,n.useLayoutEffect)(()=>{r({selectDivision:ue,addDivision:()=>de(),removeDivision:e=>se(e),updateDivision:(e,t)=>oe(e,t),divisionContentChange:(e,t)=>{ae(e,t,v.find(t=>t.xmlId===e)?.sourceFormat??`pretext`)},handleDivisionContentChange:le,assetInsert:fe,insertContentAtCursor:e=>te.current?.insertAtCursor(e),updateTitle:t=>{A(t),e.onTitleChange?.(t)},feedbackSubmit:e.onFeedbackSubmit})}),(0,n.useEffect)(()=>{_({source:ie,sourceFormat:M,projectAssets:e.projectAssets,libraryAssets:e.libraryAssets,projectType:e.projectType,projectUrl:e.projectUrl,rootDivisionId:ne?.xmlId,canConvertToPretext:ce!==void 0,activeEditorSource:ie,hasFeedback:e.onFeedbackSubmit!==void 0})});let me=(0,n.useRef)({divisions:e.divisions,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,activeDivisionId:e.activeDivisionId});(0,n.useEffect)(()=>{let t=me.current,n={},r=!1;if(e.divisions!==t.divisions){n.divisions=e.divisions;let t=q6(e.divisions,e.rootDivisionId);(y==null||!e.divisions.some(e=>e.xmlId===y))&&(n.activeDivisionId=t?.xmlId??null),r=!0}e.title!==void 0&&e.title!==t.title&&(n.title=e.title,r=!0),e.docinfo!==void 0&&e.docinfo!==t.docinfo&&(n.docinfo=e.docinfo,r=!0),e.commonDocinfo!==void 0&&e.commonDocinfo!==t.commonDocinfo&&(n.commonDocinfo=e.commonDocinfo,r=!0),e.useCommonDocinfo!==void 0&&e.useCommonDocinfo!==t.useCommonDocinfo&&(n.useCommonDocinfo=e.useCommonDocinfo,r=!0),e.activeDivisionId!==void 0&&e.activeDivisionId!==t.activeDivisionId&&(n.activeDivisionId=e.activeDivisionId,r=!0),r&&w(n),me.current={divisions:e.divisions,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,activeDivisionId:e.activeDivisionId}});let he=C?S:x,ge=re?M===`pretext`?L6(v,re.xmlId):ce===void 0?void 0:`<${re.type} xml:id="${re.xmlId}">\n<title>${re.title}</title>\n\n${ce}\n</${re.type}>`:void 0,I=re&&ge!==void 0?V6(re.type,ge,he,re.title):void 0,_e=()=>ee.current?.rebuild(),ve=()=>{e.onSave?.(),ee.current?.rebuild()},ye=t=>{let n=t.ctrlKey||t.metaKey;n&&t.key===`Enter`&&e.onPreviewRebuild?(t.preventDefault(),_e()):n&&t.key===`s`&&(t.preventDefault(),ve())},be=()=>{if(!re||!ce)return;let e=Q3(),t=D6(n6(ce,re.type));N({id:e.xmlId,xmlId:e.xmlId,title:re.title,type:re.type,sourceFormat:`pretext`,content:t})},xe=(0,t.jsx)(Ps,{ref:te,content:ie,sourceFormat:M,onChange:le,onRebuild:e.onPreviewRebuild?_e:void 0,onSave:ve,onOpenLatexImport:()=>h(`isLatexDialogOpen`),onOpenDocinfoEditor:()=>h(`isDocinfoEditorOpen`),onOpenConvertToPretext:pe&&ce!==void 0?()=>h(`isConvertDialogOpen`):void 0,canConvertToPretext:ce!==void 0,onOpenAssets:e.projectAssets!==void 0&&M===`pretext`?()=>h(`isAssetPickerOpen`):void 0}),Se;Se=i&&e.onPreviewRebuild?(0,t.jsx)($L,{ref:ee,content:I||``,title:b,onRebuild:e.onPreviewRebuild}):(0,t.jsx)(XL,{content:ie,canEdit:M===`pretext`,editDisabledReason:M===`markdown`?`Visual editing is not available for Markdown documents.`:M===`latex`?`Visual editing is not available for LaTeX documents.`:``,onChange:e=>le(e)});let Ce=(0,t.jsx)(U6,{isCollapsed:l,onToggleCollapse:()=>u(e=>!e),onOpenAssetPicker:e.projectAssets===void 0?void 0:()=>h(`isAssetPickerOpen`)}),L=`pretext-plus-tab-editor`,we=`pretext-plus-tab-preview`,Te=`pretext-plus-tabpanel`,Ee;return Ee=a?(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tabs`,children:[Ce,(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tabs-main`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tab-list`,role:`tablist`,children:[(0,t.jsx)(`button`,{type:`button`,id:L,role:`tab`,"aria-controls":Te,"aria-selected":s===`editor`,tabIndex:s===`editor`?0:-1,className:`pretext-plus-editor__tab-button ${s===`editor`?`is-active`:``}`,onClick:()=>c(`editor`),children:`Editor`}),(0,t.jsx)(`button`,{type:`button`,id:we,role:`tab`,"aria-controls":Te,"aria-selected":s===`preview`,tabIndex:s===`preview`?0:-1,className:`pretext-plus-editor__tab-button ${s===`preview`?`is-active`:``}`,onClick:()=>c(`preview`),children:`Preview`})]}),(0,t.jsx)(`div`,{id:Te,className:`pretext-plus-editor__tab-panel`,role:`tabpanel`,"aria-labelledby":s===`editor`?L:we,children:(0,t.jsx)(`div`,{style:{height:`100%`},children:s===`editor`?xe:Se})})]})]}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__sectioned-layout`,children:[Ce,(0,t.jsxs)(gt,{orientation:`horizontal`,className:`pretext-plus-editor__splitter`,children:[(0,t.jsx)(yt,{className:`pretext-plus-editor__editor-panel`,children:xe}),(0,t.jsx)(St,{className:`pretext-plus-editor__resize-handle`,children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__resize-dots`})}),(0,t.jsx)(yt,{className:`pretext-plus-editor__preview-panel`,children:Se})]})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor`,onKeyDown:ye,children:[(0,t.jsx)(S3,{onSaveButton:e.onSaveButton,saveButtonLabel:e.saveButtonLabel,onCancelButton:e.onCancelButton,cancelButtonLabel:e.cancelButtonLabel,showPreviewModeToggle:e.onPreviewRebuild!==void 0}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__editor-displays`,children:[(0,t.jsx)(W6,{resetKeys:[ie,y],children:Ee}),d?(0,t.jsx)(e3,{onClose:()=>g(`isLatexDialogOpen`)}):null,f&&re&&ce?(0,t.jsx)(i3,{sourceContent:ie,sourceFormat:M,pretextSource:ce,onConfirm:be,onClose:()=>g(`isConvertDialogOpen`)}):null,p?(0,t.jsx)(g3,{docinfo:x,showCommonDocinfoControls:!0,commonDocinfo:S,initialUseCommonDocinfo:C,onClose:t=>{if(g(`isDocinfoEditorOpen`),t!==void 0){j({docinfo:t.docinfo,commonDocinfo:t.commonDocinfo,useCommonDocinfo:t.useCommonDocinfo}),e.onCommonDocinfoChange?.(t.commonDocinfo),e.onUseCommonDocinfoChange?.(t.useCommonDocinfo);let n=ne??re;ae(n?.xmlId??``,n?.content??``,n?.sourceFormat??`pretext`,{docinfo:t.docinfo,commonDocinfo:t.commonDocinfo,useCommonDocinfo:t.useCommonDocinfo})}}}):null,m&&e.projectAssets!==void 0?(0,t.jsx)(x3,{open:m,onClose:()=>g(`isAssetPickerOpen`),onLoadAssets:e.onLoadAssets,onLoadLibraryAssets:e.onLoadLibraryAssets,onAddFromLibrary:e.onAssetAddFromLibrary,onUpload:e.onAssetUpload,onAddUrl:e.onAssetAddUrl,onCreateDoenet:e.onCreateDoenet,onRemoveAsset:e.onAssetRemove,onInsert:fe}):null]})]})};e.CodeEditor=Ps,e.DocinfoEditor=g3,e.Editors=J6,e.FeedbackLink=K4,e.FullPreview=$L,e.VisualEditor=XL,e.assembleFullProjectSource=z6,e.assembleProjectSource=L6,e.buildDivisionTree=A6,e.convertLatexToPretext=V4,e.createConclusion=e6,e.createIntroduction=$3,e.createLatexConclusion=d6,e.createLatexIntroduction=u6,e.createNewLatexSection=l6,e.createNewSection=Q3,e.derivePretextContent=W4,e.detectSourceFormat=B4,e.ensureLatexSectionWrapper=o6,e.ensureSectionWrapper=r6,e.extractDivisionMetadata=m6,e.extractLatexDivisionTitle=c6,e.findDivisionParent=T6,e.getOrphanRoots=j6,e.getOrphanedDivisions=k6,e.getSectionAttributes=p6,e.insertDivisionRef=x6,e.mergeTwoSections=f6,e.moveDivisionRef=C6,e.normalizeSelfClosingRefs=D6,e.parseDivisionRefs=v6,e.postToIframe=QL,e.removeDivisionRef=S6,e.renameDivisionRef=w6,e.reorderDivisionRefs=E6,e.rewrapLatexSection=a6,e.rewrapSection=n6,e.stripLatexSectionWrapper=i6,e.stripSectionWrapper=t6,e.updateDivisionTitle=Z3,e.updateLatexSectionTitle=s6,e.updateSectionMetadata=h6,e.wrapDivisionForPreview=V6});
|
|
1084
1084
|
//# sourceMappingURL=index.js.map
|