@pretextbook/web-editor 0.5.3 → 0.5.4
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.es.js +1481 -1387
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/sectionUtils.d.ts +19 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1058,27 +1058,27 @@ 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`,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=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}
|
|
1065
1065
|
`+` `.repeat(r-s+1)+`^
|
|
1066
1066
|
`),this.column=r,this.excerpt=i,this.line=a,this.name=`XmlError`,this.pos=t}},te=class extends w{constructor(e,t=``){super(),this.name=e,this.content=t}get type(){return w.TYPE_PROCESSING_INSTRUCTION}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{name:this.name,content:this.content})}},ne=``,re=class{constructor(e,t={}){let n=this.document=new A;this.j=n,this.g=t,this.c=new f(e),this.g.includeOffsets&&(n.start=0,n.end=e.length),this.parse()}i(e,t){return e.parent=this.j,this.g.includeOffsets&&(e.start=this.c.f(t),e.end=this.c.f()),this.j.children.push(e),!0}y(e,t){let{children:n}=this.j,{length:r}=n;if(e=M(e),r>0){let t=n[r-1];if(t?.type===w.TYPE_TEXT){let n=t;return n.text+=e,this.g.includeOffsets&&(n.end=this.c.f()),!0}}return this.i(new T(e),t)}H(){let e=Object.create(null);for(;this.e();){let t=this.q();if(!t)break;let n=this.t()&&this.I();if(n===!1)throw this.a(`Attribute value expected`);if(t in e)throw this.a(`Duplicate attribute: ${t}`);if(t===`xml:space`&&n!=="default"&&n!==`preserve`)throw this.a('Value of the `xml:space` attribute must be "default" or "preserve"');e[t]=n}if(this.g.sortAttributes){let t=Object.keys(e).sort(),n=Object.create(null);for(let r=0;r<t.length;++r){let i=t[r];n[i]=e[i]}e=n}return e}I(){let{c:e}=this,t=e.m();if(t!==`"`&&t!==`'`)return!1;e.p();let n,r=!1,i=ne,a=t===`"`?p:m;matchLoop:for(;!e.B;)switch(n=e.x(a),n&&(this.o(n),i+=n.replace(h,` `)),e.m()){case t:r=!0;break matchLoop;case`&`:i+=this.C();continue;case`<`:throw this.a("Unescaped `<` is not allowed in an attribute value");default:break matchLoop}if(!r)throw this.a(`Unclosed attribute`);return e.p(),i}J(){let{c:e}=this,t=e.d;if(!e.b(`<![CDATA[`))return!1;let n=e.s(`]]>`);if(this.o(n),!e.b(`]]>`))throw this.a(`Unclosed CDATA section`);return this.g.preserveCdata?this.i(new E(M(n)),t):this.y(n,t)}K(){let{c:e}=this,t=e.d,n=e.x(g);if(!n)return!1;if(this.o(n),e.m(3)===`]]>`)throw this.a("Element content may not contain the CDATA section close delimiter `]]>`");return this.y(n,t)}D(){let{c:e}=this,t=e.d;if(!e.b(`<!--`))return!1;let n=e.s(`--`);if(this.o(n),!e.b(`-->`))throw e.m(2)===`--`?this.a("The string `--` isn't allowed inside a comment"):this.a(`Unclosed comment`);return this.g.preserveComments?this.i(new D(M(n)),t):!0}L(){let e=this.c.d,t=this.C();return t?this.y(t,e):!1}M(){let{c:e}=this,t=e.d;if(!e.b(`<!DOCTYPE`))return!1;let n=this.e()&&this.q();if(!n)throw this.a(`Expected a name`);let r,i;if(this.e()){if(e.b(`PUBLIC`)){if(r=this.e()&&this.N(),r===!1)throw this.a(`Expected a public identifier`);this.e()}if(r!==void 0||e.b(`SYSTEM`)){if(this.e(),i=this.r(),i===!1)throw this.a(`Expected a system identifier`);this.e()}}let a;if(e.b(`[`)){if(a=e.x(/\][\x20\t\r\n]*>/),!e.b(`]`))throw this.a(`Unclosed internal subset`);this.e()}if(!e.b(`>`))throw this.a(`Unclosed doctype declaration`);return this.g.preserveDocumentType?this.i(new j(n,r,i,a),t):!0}E(){let{c:e}=this,t=e.d;if(!e.b(`<`))return!1;let n=this.q();if(!n)return e.n(t),!1;let r=this.H(),i=!!e.b(`/>`),a=new k(n,r);if(a.parent=this.j,!i){if(!e.b(`>`))throw this.a(`Unclosed start tag for element \`${n}\``);this.j=a;do this.K();while(this.E()||this.L()||this.J()||this.F()||this.D());let t=e.d,r;if(!e.b(`</`)||!(r=this.q())||r!==n)throw e.n(t),this.a(`Missing end tag for element ${n}`);if(this.e(),!e.b(`>`))throw this.a(`Unclosed end tag for element ${n}`);this.j=a.parent}return this.i(a,t)}t(){return this.e(),this.c.b(`=`)?(this.e(),!0):!1}z(){return this.D()||this.F()||this.e()}q(){return y(this.c.m())?this.c.w(v):ne}F(){let{c:e}=this,t=e.d;if(!e.b(`<?`))return!1;let n=this.q();if(n){if(n.toLowerCase()===`xml`)throw e.n(t),this.a(`XML declaration isn't allowed here`)}else throw this.a(`Invalid processing instruction`);if(!this.e()){if(e.b(`?>`))return this.i(new te(n),t);throw this.a(`Whitespace is required after a processing instruction name`)}let r=e.s(`?>`);if(this.o(r),!e.b(`?>`))throw this.a(`Unterminated processing instruction`);return this.i(new te(n,M(r)),t)}O(){let{c:e}=this,t=e.d;for(this.P();this.z(););if(this.M())for(;this.z(););return t<e.d}N(){let e=this.c.d,t=this.r();if(t!==!1&&!/^[-\x20\r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(t))throw this.c.n(e),this.a(`Invalid character in public identifier`);return t}C(){let{c:e}=this;if(!e.b(`&`))return!1;let t=e.w(b);if(e.G()!==`;`)throw this.a("Unterminated reference (a reference must end with `;`)");let n;if(t[0]===`#`){let e=t[1]===`x`?parseInt(t.slice(2),16):parseInt(t.slice(1),10);if(isNaN(e))throw this.a(`Invalid character reference`);if(!S(e))throw this.a(`Character reference resolves to an invalid character`);n=String.fromCodePoint(e)}else if(n=_[t],n===void 0){let{ignoreUndefinedEntities:n,resolveUndefinedEntity:r}=this.g,i=`&${t};`;if(r){let e=r(i);if(e!=null){let t=typeof e;if(t!==`string`)throw TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${t}`);return e}}if(n)return i;throw e.n(-i.length),this.a(`Named entity isn't defined: ${i}`)}return n}r(){let{c:e}=this,t=e.b(`"`)||e.b(`'`);if(!t)return!1;let n=e.s(t);if(this.o(n),!e.b(t))throw this.a(`Missing end quote`);return n}e(){return!!this.c.w(x)}P(){let{c:e}=this,t=e.d;if(!e.b(`<?xml`))return!1;if(!this.e())throw this.a(`Invalid XML declaration`);let n=!!e.b(`version`)&&this.t()&&this.r();if(n===!1)throw this.a(`XML version is missing or invalid`);if(!/^1\.[0-9]+$/.test(n))throw this.a(`Invalid character in version number`);let r,i;if(this.e()){if(r=!!e.b(`encoding`)&&this.t()&&this.r(),r){if(!/^[A-Za-z][\w.-]*$/.test(r))throw this.a(`Invalid character in encoding name`);this.e()}if(i=!!e.b(`standalone`)&&this.t()&&this.r(),i){if(i!==`yes`&&i!==`no`)throw this.a('Only "yes" and "no" are permitted as values of `standalone`');this.e()}}if(!e.b(`?>`))throw this.a(`Invalid or unclosed XML declaration`);return this.g.preserveXmlDeclaration?this.i(new O(n,r||void 0,i||void 0),t):!0}a(e){let{c:t}=this;return new ee(e,t.d,t.h)}parse(){if(this.c.b(``),this.O(),!this.E())throw this.a(`Root element is missing or invalid`);for(;this.z(););if(!this.c.B)throw this.a(`Extra content at the end of the document`)}o(e){let{length:t}=e;for(let n=0;n<t;++n){let t=e.codePointAt(n);if(!S(t))throw this.c.n(-([...e].length-n)),this.a(`Invalid character`);t>65535&&(n+=1)}}};function M(e){let t=0;for(;(t=e.indexOf(`\r`,t))!==-1;)e=e[t+1]===`
|
|
1067
1067
|
`?e.slice(0,t)+e.slice(t+1):e.slice(0,t)+`
|
|
1068
|
-
`+e.slice(t+1);return e}function ie(e,t){return new re(e,t).document}}));function
|
|
1069
|
-
`,t);return r===-1?n:n===-1||n+1===r?r:n<r?n:r}var
|
|
1068
|
+
`+e.slice(t+1);return e}function ie(e,t){return new re(e,t).document}}));function v3(e){let t=String(e),n=[];return{toOffset:i,toPoint:r};function r(e){if(typeof e==`number`&&e>-1&&e<=t.length){let r=0;for(;;){let i=n[r];if(i===void 0){let e=y3(t,n[r-1]);i=e===-1?t.length+1:e+1,n[r]=i}if(i>e)return{line:r+1,column:e-(r>0?n[r-1]:0)+1,offset:e};r++}}}function i(e){if(e&&typeof e.line==`number`&&typeof e.column==`number`&&!Number.isNaN(e.line)&&!Number.isNaN(e.column)){for(;n.length<e.line;){let e=n[n.length-1],r=y3(t,e),i=r===-1?t.length+1:r+1;if(e===i)break;n.push(i)}let r=(e.line>1?n[e.line-2]:0)+e.column-1;if(r<n[e.line-1])return r}}}function y3(e,t){let n=e.indexOf(`\r`,t),r=e.indexOf(`
|
|
1069
|
+
`,t);return r===-1?n:n===-1||n+1===r?r:n<r?n:r}var b3=_3();function x3(e){let t=v3(e),n;try{n=(0,b3.parseXml)(String(e),{includeOffsets:!0,preserveCdata:!0,preserveComments:!0,preserveDocumentType:!0,preserveXmlDeclaration:!0})}catch(e){let n=e,r=new fJ("Could not parse XML with `@rgrove/parse-xml`",{cause:n,place:t.toPoint(n.pos),ruleId:`error`,source:`xast-util-from-xml`});throw r.fatal=!0,r.url=`https://github.com/syntax-tree/xast-util-from-xml#throws`,r}let r={location:t},i=w3(n,r);return j3(n,i,r),i}function S3(e){return{type:`cdata`,value:e.text}}function C3(e){return{type:`comment`,value:e.content}}function w3(e,t){return{type:`root`,children:A3(e.children,t)}}function T3(e){return{type:`doctype`,name:e.name,public:e.publicId||void 0,system:e.systemId||void 0}}function E3(e,t){let n=A3(e.children,t);return{type:`element`,name:e.name,attributes:{...e.attributes},children:n}}function D3(e){return{type:`instruction`,name:e.name,value:e.content}}function O3(e){return{type:`text`,value:e.text}}function k3(e){let t=[];return e.version&&t.push(`version="`+e.version+`"`),e.encoding&&t.push(`encoding="`+e.encoding+`"`),e.standalone&&t.push(`standalone="`+e.standalone+`"`),{type:`instruction`,name:`xml`,value:t.join(` `)}}function A3(e,t){let n=[],r=-1;for(;++r<e.length;){let i=e[r],a;i.type===`cdata`?a=S3(i):i.type===`comment`?a=C3(i):i.type===`doctype`?a=T3(i):i.type===`element`?a=E3(i,t):i.type===`pi`?a=D3(i):i.type===`text`?a=O3(i):i.type===`xmldecl`&&(a=k3(i)),a&&(j3(i,a,t),n.push(a))}return n}function j3(e,t,n){let r=e.start===-1?void 0:n.location.toPoint(e.start),i=e.end===-1?void 0:n.location.toPoint(e.end);r&&i&&(t.position={start:r,end:i})}function M3(){return`sec-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function N3(e){let t=e.children.find(e=>e.type===`element`&&e.name===`title`);return t?t.children.filter(e=>e.type===`text`).map(e=>e.value).join(``).trim():``}var P3=new Set([`book`,`article`,`slideshow`,`part`,`chapter`,...new Set([`introduction`,`section`,`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`,`conclusion`])]);function F3(e){let t=0,n=e.length;for(;t<n;){let n=e[t];if(n.type!==`text`||/\S/.test(n.value))break;t+=1}for(;n>t;){let t=e[n-1];if(t.type!==`text`||/\S/.test(t.value))break;--n}return e.slice(t,n)}function I3(e){return e.replace(/^(?:[ \t]*\r?\n)+/,``).replace(/(?:\r?\n[ \t]*)+$/,``)}function L3(e){try{return x3(e)}catch{return null}}function R3(e){let t=e.match(/^\s*<([A-Za-z_][\w.:-]*)\b[^>]*?>/);if(!t||t.index===void 0)return e;let n=e.slice(t.index+t[0].length),r=RegExp(`\\s*</${i6(t[1])}\\s*>\\s*$`);return I3(n.replace(r,``))}function z3(e,t){let n=L3(e);if(!n)return e;let r=n.children.find(e=>e.type===`element`);if(!r)return e;let i=r.children.findIndex(e=>e.type===`element`&&e.name===`title`),a={type:`element`,name:`title`,attributes:{},children:[{type:`text`,value:t}]};return i===-1?r.children.unshift(a):r.children.splice(i,1,a),TY(n)}function B3(e=`New Section`){let t=M3();return{id:t,xmlId:t,title:e,content:`<section xml:id="${t}">\n\t<title>${e}</title>\n\n\t<p>\n\n\t</p>\n\n</section>`,type:`section`,sourceFormat:`pretext`}}function V3(){let e=M3();return{id:e,xmlId:e,title:`Introduction`,content:`<introduction xml:id="${e}">\n\n\t<p>\n\n\t</p>\n\n</introduction>`,type:`introduction`,sourceFormat:`pretext`}}function H3(){let e=M3();return{id:e,xmlId:e,title:`Conclusion`,content:`<conclusion xml:id="${e}">\n\n\t<p>\n\n\t</p>\n\n</conclusion>`,type:`conclusion`,sourceFormat:`pretext`}}function U3(e){let t=L3(e);if(!t)return R3(e);let n=t.children.find(e=>e.type===`element`);return n?v6(TY({type:`root`,children:F3(n.children)})):e}function W3(e,t){return`<${t}>\n${I3(e)}\n</${t}>`}function G3(e,t){return e.trimStart().startsWith(`<${t}`)?e:W3(e,t)}function K3(e,t){if(t===`introduction`||t===`conclusion`)return e;let n=e.trimStart();return n.startsWith(`\\begin{section}`)?n.replace(/^\\begin\{section\}\s*\n?/,``).replace(/\n?\\end\{section\}\s*$/,``):e.replace(/^\\section\*?\{[^}]*\}\s*\n?/,``)}function q3(e,t,n,r){return t===`introduction`||t===`conclusion`?e:r?.trimStart().startsWith(`\\begin{section}`)?`\\begin{section}\n\n${e}\n\n\\end{section}`:`\\section{${n}}\n\n${e}`}function J3(e,t,n,r){if(t===`introduction`||t===`conclusion`)return e;let i=e.trimStart();return i.startsWith(`\\section`)||i.startsWith(`\\begin{section}`)?e:q3(e,t,n,r)}function Y3(e,t){return/\\section[*]?\{/.test(e)?e.replace(/^(\\section\*?\{)[^}]*/,(e,n)=>`${n}${t}`):e.includes(`\\begin{section}`)?/\\title\{/.test(e)?e.replace(/\\title\{[^}]*\}/,`\\title{${t}}`):e.replace(`\\begin{section}`,`\\begin{section}\n\n\\title{${t}}\n\n`):e}function X3(e){let t=/^\\section\*?\{([^}]*)\}/.exec(e);if(t)return t[1].trim();if(e.includes(`\\begin{section}`)){let t=/\\title\{([^}]*)\}/.exec(e);if(t)return t[1].trim()}return null}function Z3(e=`New Section`){let t=M3();return{id:t,xmlId:t,title:e,content:`\\section{${e}}\n\n`,type:`section`,sourceFormat:`latex`}}function Q3(){let e=M3();return{id:e,xmlId:e,title:`Introduction`,content:`% Introduction
|
|
1070
1070
|
|
|
1071
|
-
`,type:`introduction`,sourceFormat:`latex`}}function
|
|
1071
|
+
`,type:`introduction`,sourceFormat:`latex`}}function $3(){let e=M3();return{id:e,xmlId:e,title:`Conclusion`,content:`% Conclusion
|
|
1072
1072
|
|
|
1073
|
-
`,type:`conclusion`,sourceFormat:`latex`}}function
|
|
1073
|
+
`,type:`conclusion`,sourceFormat:`latex`}}function e6(e,t,n){if(n){let n=K3(t.content,t.type);return{...e,content:e.content.trimEnd()+`
|
|
1074
1074
|
|
|
1075
|
-
`+n.trimStart()}}let r=
|
|
1075
|
+
`+n.trimStart()}}let r=L3(e.content),i=L3(t.content),a=r?.children.find(e=>e.type===`element`),o=i?.children.find(e=>e.type===`element`);if(!a||!o)return{...e,content:e.content+`
|
|
1076
1076
|
|
|
1077
|
-
`+t.content};let s=o.children.filter(e=>!(e.type===`element`&&e.name===`title`)),c={...a,children:[...a.children,...s]};return{...e,content:TY({type:`root`,children:[c]})}}function
|
|
1077
|
+
`+t.content};let s=o.children.filter(e=>!(e.type===`element`&&e.name===`title`)),c={...a,children:[...a.children,...s]};return{...e,content:TY({type:`root`,children:[c]})}}function t6(e){try{let t=x3(e).children.find(e=>e.type===`element`);return t?{xmlId:t.attributes?.[`xml:id`]??``,label:t.attributes?.label??``}:{xmlId:``,label:``}}catch{return{xmlId:``,label:``}}}function n6(e){let t=L3(e);if(!t)return null;let n=t.children.find(e=>e.type===`element`);return!n||!P3.has(n.name)?null:{title:N3(n),type:n.name,xmlId:n.attributes?.[`xml:id`]??``,label:n.attributes?.label??``}}function r6(e,t){let n=t.type??e.type,r=t.title??e.title;try{let i=x3(e.content).children.find(e=>e.type===`element`);if(!i)return{...e,title:r,type:n};let a={...i,name:n,attributes:{...i.attributes}};t.xmlId!==void 0&&(t.xmlId===null||t.xmlId===``?delete a.attributes[`xml:id`]:a.attributes[`xml:id`]=t.xmlId),t.label!==void 0&&(t.label===null||t.label===``?delete a.attributes.label:a.attributes.label=t.label);let o=a.children.findIndex(e=>e.type===`element`&&e.name===`title`),s={type:`element`,name:`title`,attributes:{},children:[{type:`text`,value:r}]};o===-1?a.children=[s,...a.children]:a.children=[...a.children.slice(0,o),s,...a.children.slice(o+1)];let c=TY({type:`root`,children:[a]}),l=t.xmlId!==void 0&&t.xmlId!==null&&t.xmlId!==``?t.xmlId:e.xmlId;return{...e,title:r,type:n,xmlId:l,content:c}}catch{return{...e,title:r,type:n}}}function i6(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}var a6=new Set([`division`,...P3]),o6=Array.from(a6).join(`|`);function s6(e){let t=e===null?`ref="([^"]+)"`:`ref="${i6(e)}"`,n=`(?:${o6})`;return`<plus:${n}\\s[^>]*${t}[^>]*?(?:/>|>\\s*</plus:${n}>)`}function c6(e){let t=[],n=new RegExp(s6(null),`g`),r;for(;(r=n.exec(e))!==null;)t.push(r[1]);return t}function l6(e){let t=[],n=`(?:${o6})`,r=RegExp(`<plus:(${o6})\\s[^>]*ref="([^"]+)"[^>]*?(?:/>|>\\s*</plus:${n}>)`,`g`),i;for(;(i=r.exec(e))!==null;){let e=i[1],n=e===`division`?`section`:e;t.push({type:n,xmlId:i[2]})}return t}function u6(e){let t=[],n=/<plus:(image|doenet)\b[^>]*\bref="([^"]+)"/g,r;for(;(r=n.exec(e))!==null;)t.push({kind:r[1],ref:r[2]});return t}function d6(e,t,n=`pretext`){let r=`New ${t.charAt(0).toUpperCase()+t.slice(1)}`;return{id:e,xmlId:e,title:r,type:t,sourceFormat:n,content:n===`pretext`?`<${t} xml:id="${e}">\n<title>${r}</title>\n\n<p></p>\n\n</${t}>`:`\\section{${r}}\n\n`}}function f6(e,t,n,r){let i=`<plus:${n} ref="${t}"/>`;if(r!==null){let t=new RegExp(s6(r)).exec(e);if(t){let n=t.index+t[0].length;return e.slice(0,n)+`
|
|
1078
1078
|
`+i+e.slice(n)}}let a=e.lastIndexOf(`</`);return a===-1?e+`
|
|
1079
1079
|
`+i:e.slice(0,a)+i+`
|
|
1080
|
-
`+e.slice(a)}function
|
|
1080
|
+
`+e.slice(a)}function p6(e,t){let n=RegExp(`[ \t]*${s6(t)}[ \t]*\n?`,`g`);return e.replace(n,``)}function m6(e,t,n){let r=new RegExp(s6(t)).exec(e),i=r?v6(r[0]):`<plus:division ref="${t}"/>`,a=p6(e,t);if(n!==null){let e=new RegExp(s6(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))}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});
|
|
1083
|
+
`+a.slice(o)}function h6(e,t,n,r){let i=new RegExp(s6(t));return i.test(e)?e.replace(i,`<plus:${r} ref="${n}"/>`):e}function g6(e,t){let n=new RegExp(s6(t));return e.find(e=>n.test(e.content))??null}function _6(e,t){let n=e,r=null;for(let e of t)n=m6(n,e,r),r=e;return n}function v6(e){return e.replace(/<plus:([a-z-]+)((?:\s[^>]*?)?)>\s*<\/plus:\1>/g,(e,t,n)=>`<plus:${t}${n}/>`)}function y6(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 c6(i.content))r.push(e)}return n}function b6(e,t){let n=y6(e,t);return e.filter(e=>!n.has(e.xmlId))}function x6(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 c6(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 S6(e,t){let n=b6(e,t),r=new Set(n.map(e=>e.xmlId)),i=new Set;for(let e of n)for(let t of c6(e.content))r.has(t)&&i.add(t);return n.filter(e=>!i.has(e.xmlId))}var C6=new Set([`book`,`article`,`slideshow`]);function w6(e){try{let t=x3(e),n=t.children.find(e=>e.type===`element`),r=n?.name===`pretext`?n.children.find(e=>e.type===`element`&&C6.has(e.name)):n&&C6.has(n.name)?n:void 0;if(!r)return e;if(!r.attributes.label){let e=E6(t,`pretext-plus-preview`);return r.attributes.label=e,TY(t)}return e}catch(t){return console.error(`Error ensuring label:`,t),e}}function T6(e,t){return e.type===`element`&&e.attributes?.label===t?!0:`children`in e&&e.children?e.children.some(e=>e.type===`element`?T6(e,t):!1):!1}function E6(e,t){let n=t,r=1;for(;T6(e,n);)n=`${t}-${r}`,r++;return n}function D6(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`?K3(r.content,r.type):U3(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)=>D6(n,t,a))}function O6(e,t){return w6(D6(t,e,new Set))}function k6(e,t){return w6(`<pretext>\n${t.trim()?`${t.trim()}\n`:``}${e}\n</pretext>`)}function A6(e,t,n){return k6(D6(t,e,new Set),n)}var j6=new Set([`part`,`chapter`]);function M6(e,t,n,r){return k6(C6.has(e)?t:j6.has(e)?`<book>\n<title>${r}</title>\n${t}\n</book>`:`<article>\n<title>${r}</title>\n${t}\n</article>`,n)}var N6=`data:image/png;base64,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`,P6={image:`Images`,doenet:`Doenet`},F6=[`image`,`doenet`];function I6(e){let t=new Set,n=[];for(let{kind:r,ref:i}of u6(e)){let e=`${r}:${i}`;t.has(e)||(t.add(e),n.push({kind:r,ref:i}))}return n}var L6=({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=I6(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 `,P6[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=F6.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:F6.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:P6[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:N6,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`})})]})})},R6=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]})]})},z6={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`},B6=[`part`,`chapter`,`section`,`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`],V6=({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:B6.map(e=>(0,t.jsx)(`option`,{value:e,children:z6[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 H6(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 U6=({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=H6(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))})]})},W6=({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:z6[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)(U6,{items:f})})]}),h&&s&&(0,t.jsx)(V6,{draft:s,isLatex:p,isRoot:m,onDraftChange:l,onCommit:u,onCancel:d})]})},G6={image:`Images`,doenet:`Doenet`},K6=[`image`,`doenet`],q6=({onOpenAssetPicker:e})=>{let r=Q4(e=>e.divisions),i=Q4(e=>e.rootDivisionId),a=Q4(e=>e.activeDivisionId),o=Q4(e=>e.projectAssets)??[],s=Q4(e=>e.selectSection),c=Q4(e=>e.removeSection),l=Q4(e=>e.divisionContentChange),u=Q4(e=>e.insertAtCursor),d=Q4(e=>e.startSectionEdit),f=Q4(e=>e.setEditDraft),p=Q4(e=>e.commitSectionEdit),m=Q4(e=>e.cancelSectionEdit),h=Q4(e=>e.editingId),g=Q4(e=>e.editDraft),_=r?r.find(e=>e.xmlId===i)??r.find(e=>e.type===`book`||e.type===`article`||e.type===`slideshow`)??r[0]??null:null,v=_&&r?x6(r,_.xmlId):[],y=_&&r?S6(r,_.xmlId):[],b=(()=>{if(!r)return[];let e=new Set,t=[];for(let n of r)for(let r of u6(n.content)){let n=`${r.kind}:${r.ref}`;e.has(n)||(e.add(n),t.push(r))}return t})(),x=K6.map(e=>({kind:e,items:b.filter(t=>t.kind===e)})).filter(e=>e.items.length>0),[S,C]=(0,n.useState)(!1),[w,T]=(0,n.useState)(new Set),E=e=>!w.has(e),D=e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};(0,n.useEffect)(()=>{if(!a||!_)return;let e=new Map(v.map(e=>[e.division.xmlId,e])),t=new Set;t.add(_.xmlId);let n=a;for(;n;){let r=e.get(n);if(!r?.parentXmlId)break;t.add(r.parentXmlId),n=r.parentXmlId}T(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 O=new Set(v.map(e=>e.parentXmlId).filter(Boolean)),k=[];if(_){let e=new Set;E(_.xmlId)&&e.add(_.xmlId);for(let t of v)t.parentXmlId&&e.has(t.parentXmlId)&&(k.push(t),E(t.division.xmlId)&&e.add(t.division.xmlId))}let A=(e,t)=>{if(!r)return;let n=r.find(e=>e.xmlId===t);n&&l(n.xmlId,v6(p6(n.content,e)))},j=(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&&l(n.xmlId,v6(p6(n.content,e.xmlId)))}c(e.xmlId)}},ee=e=>{u(`<plus:${e.type} ref="${e.xmlId}"/>`)},te=e=>{_&&l(_.xmlId,v6(f6(_.content,e.xmlId,e.type,null)))},ne=(e,t)=>{u(`<plus:${e} ref="${t}"/>`)};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`ul`,{className:`pretext-plus-editor__toc-list`,role:`list`,children:[_&&(0,t.jsx)(W6,{division:_,depth:0,isActive:a===_.xmlId,hasChildren:O.has(_.xmlId),isExpanded:E(_.xmlId),onToggleExpand:()=>D(_.xmlId),editDraft:h===_.xmlId?g:null,onSelect:()=>s(_.xmlId),onDraftChange:f,onEditCommit:p,onEditCancel:m,menuItems:[{label:`Edit properties`,onClick:()=>d(_)}],isLatex:_.sourceFormat===`latex`,isRoot:!0}),k.length===0&&_&&E(_.xmlId)&&(0,t.jsx)(`li`,{className:`pretext-plus-editor__toc-no-sections`,children:(0,t.jsx)(`span`,{children:`No placed divisions`})}),k.map(e=>(0,t.jsx)(W6,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:O.has(e.division.xmlId),isExpanded:E(e.division.xmlId),onToggleExpand:()=>D(e.division.xmlId),editDraft:h===e.division.xmlId?g:null,onSelect:()=>s(e.division.xmlId),onDraftChange:f,onEditCommit:p,onEditCancel:m,menuItems:[{label:`Edit properties`,onClick:()=>d(e.division)},{label:`Remove from document`,onClick:()=>A(e.division.xmlId,e.parentXmlId)},{label:`Delete from project`,onClick:()=>j(e.division,e.parentXmlId),danger:!0}],isLatex:e.division.sourceFormat===`latex`},e.division.xmlId))]}),y.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:y.map(e=>{let i=r?x6(r,e.xmlId):[],o=new Set(i.map(e=>e.parentXmlId).filter(Boolean));return(0,t.jsxs)(n.Fragment,{children:[(0,t.jsx)(W6,{division:e,depth:0,isActive:a===e.xmlId,hasChildren:o.has(e.xmlId),isExpanded:E(e.xmlId),onToggleExpand:()=>D(e.xmlId),editDraft:h===e.xmlId?g:null,onSelect:()=>s(e.xmlId),onDraftChange:f,onEditCommit:p,onEditCancel:m,menuItems:[{label:`Edit properties`,onClick:()=>d(e)},{label:`Place in document`,onClick:()=>te(e)},{label:`Insert at cursor`,onClick:()=>ee(e)},{label:`Delete from project`,onClick:()=>j(e,null),danger:!0}],isLatex:e.sourceFormat===`latex`}),E(e.xmlId)&&i.map(e=>(0,t.jsx)(W6,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:o.has(e.division.xmlId),isExpanded:E(e.division.xmlId),onToggleExpand:()=>D(e.division.xmlId),editDraft:h===e.division.xmlId?g:null,onSelect:()=>s(e.division.xmlId),onDraftChange:f,onEditCommit:p,onEditCancel:m,menuItems:[{label:`Edit properties`,onClick:()=>d(e.division)},{label:`Insert at cursor`,onClick:()=>ee(e.division)},{label:`Delete from project`,onClick:()=>j(e.division,e.parentXmlId),danger:!0}],isLatex:e.division.sourceFormat===`latex`},e.division.xmlId))]},e.xmlId)})})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-assets`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-header`,children:(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-toggle`,onClick:()=>C(e=>!e),"aria-expanded":S,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-assets-chevron`,children:S?`▾`:`▸`}),(0,t.jsx)(`span`,{children:`Assets`}),b.length>0&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-assets-count`,children:b.length})]})}),S&&(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-body`,children:b.length===0?(0,t.jsxs)(`p`,{className:`pretext-plus-editor__toc-assets-empty`,children:[`No assets referenced in this document.`,` `,e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-add-link`,onClick:e,children:`Add one`})]}):(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-groups`,children:x.map(({kind:e,items:n})=>(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-group-header`,children:G6[e]}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__toc-assets-list`,children:n.map(({ref:n})=>(0,t.jsxs)(`li`,{className:`pretext-plus-editor__toc-asset-item`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-asset-name`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-label`,children:o.find(t=>t.kind===e&&t.ref===n)?.name??n}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-filename`,children:n})]}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-action-btn`,onClick:()=>ne(e,n),title:`Insert <plus:${e} ref="${n}"/> at cursor`,children:`Insert`})]},n))})]},e))})})]}),e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-btn`,onClick:e,children:`Manage Assets`})]})},J6=({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)(q6,{onOpenAssetPicker:r})]}),Y6=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 X6(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}=t6(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 Z6({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,$6=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 X6({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)(Z6,{store:r.store,children:(0,t.jsx)(e8,{...e,bindCallbacks:r.bindCallbacks})})},e8=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`?v6(e||``):e||``;if(t===re.content)return;if(ae(re.xmlId,t,M),M===`pretext`){let e=n6(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=g6(v,re.xmlId);if(n){let r=h6(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=X3(t);e!==null&&oe(re.xmlId,{title:e})}let n=new Set(v.map(e=>e.xmlId));for(let{xmlId:e,type:r}of l6(t))n.has(e)||(N(d6(e,r,M)),n.add(e))},ue=e=>{P(e)},de=()=>{let e=B3();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`?O6(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?M6(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=B3(),t=v6(W3(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)(J6,{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)(R6,{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)(Y6,{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)(L6,{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=$6,e.FeedbackLink=K4,e.FullPreview=$L,e.VisualEditor=XL,e.assembleFullProjectSource=A6,e.assembleProjectSource=O6,e.buildDivisionTree=x6,e.convertLatexToPretext=V4,e.createConclusion=H3,e.createIntroduction=V3,e.createLatexConclusion=$3,e.createLatexIntroduction=Q3,e.createNewLatexSection=Z3,e.createNewSection=B3,e.derivePretextContent=W4,e.detectSourceFormat=B4,e.ensureLatexSectionWrapper=J3,e.ensureSectionWrapper=G3,e.extractDivisionMetadata=n6,e.extractLatexDivisionTitle=X3,e.findDivisionParent=g6,e.getOrphanRoots=S6,e.getOrphanedDivisions=b6,e.getSectionAttributes=t6,e.insertDivisionRef=f6,e.mergeTwoSections=e6,e.moveDivisionRef=m6,e.normalizeSelfClosingRefs=v6,e.parseDivisionRefs=c6,e.postToIframe=QL,e.removeDivisionRef=p6,e.renameDivisionRef=h6,e.reorderDivisionRefs=_6,e.rewrapLatexSection=q3,e.rewrapSection=W3,e.stripLatexSectionWrapper=K3,e.stripSectionWrapper=U3,e.updateDivisionTitle=z3,e.updateLatexSectionTitle=Y3,e.updateSectionMetadata=r6,e.wrapDivisionForPreview=M6});
|
|
1084
1084
|
//# sourceMappingURL=index.js.map
|