@pretextbook/import 0.11.0 → 0.12.0
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/engine-routing-08ynicii.cjs +3 -0
- package/dist/engine-routing-Bu0zM4aw.js +179 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +131 -122
- package/dist/lib/engine-routing.d.ts +65 -0
- package/dist/react/import-wizard.d.ts +9 -3
- package/dist/react.cjs +2 -2
- package/dist/react.js +502 -495
- package/package.json +1 -1
- package/dist/import-mode-CV7gCDzF.cjs +0 -3
- package/dist/import-mode-DQ8g5P8P.js +0 -122
package/dist/react.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),I=require("./upload-BnRj1gU1.cjs"),A=require("./engine-routing-08ynicii.cjs");var ge={exports:{}},oe={};var Ie;function Ke(){if(Ie)return oe;Ie=1;var r=Symbol.for("react.transitional.element"),i=Symbol.for("react.fragment");function u(m,p,d){var y=null;if(d!==void 0&&(y=""+d),p.key!==void 0&&(y=""+p.key),"key"in p){d={};for(var R in p)R!=="key"&&(d[R]=p[R])}else d=p;return p=d.ref,{$$typeof:r,type:m,key:y,ref:p!==void 0?p:null,props:d}}return oe.Fragment=i,oe.jsx=u,oe.jsxs=u,oe}var ce={};var De;function Ve(){return De||(De=1,process.env.NODE_ENV!=="production"&&(function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===G?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case K:return"Fragment";case V:return"Profiler";case C:return"StrictMode";case ne:return"Suspense";case ie:return"SuspenseList";case ve:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case D:return"Portal";case P:return t.displayName||"Context";case b:return(t._context.displayName||"Context")+".Consumer";case _:var l=t.render;return t=t.displayName,t||(t=l.displayName||l.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case de:return l=t.displayName||null,l!==null?l:r(t.type)||"Memo";case ae:l=t._payload,t=t._init;try{return r(t(l))}catch{}}return null}function i(t){return""+t}function u(t){try{i(t);var l=!1}catch{l=!0}if(l){l=console;var f=l.error,g=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return f.call(l,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",g),i(t)}}function m(t){if(t===K)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===ae)return"<...>";try{var l=r(t);return l?"<"+l+">":"<...>"}catch{return"<...>"}}function p(){var t=J.A;return t===null?null:t.getOwner()}function d(){return Error("react-stack-top-frame")}function y(t){if(ue.call(t,"key")){var l=Object.getOwnPropertyDescriptor(t,"key").get;if(l&&l.isReactWarning)return!1}return t.key!==void 0}function R(t,l){function f(){le||(le=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",l))}f.isReactWarning=!0,Object.defineProperty(t,"key",{get:f,configurable:!0})}function h(){var t=r(this.type);return xe[t]||(xe[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function k(t,l,f,g,B,O){var v=f.ref;return t={$$typeof:T,type:t,key:l,props:f,_owner:g},(v!==void 0?v:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:h}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:B}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:O}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function E(t,l,f,g,B,O){var v=l.children;if(v!==void 0)if(g)if(me(v)){for(g=0;g<v.length;g++)w(v[g]);Object.freeze&&Object.freeze(v)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else w(v);if(ue.call(l,"key")){v=r(t);var L=Object.keys(l).filter(function(se){return se!=="key"});g=0<L.length?"{key: someKey, "+L.join(": ..., ")+": ...}":"{key: someKey}",te[v+g]||(L=0<L.length?"{"+L.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,b,g,k,g),ne[g+b]=!0)}if(g=null,f!==void 0&&(u(f),g=""+f),N(l)&&(u(l.key),g=""+l.key),"key"in l){f={};for(var Q in l)Q!=="key"&&(f[Q]=l[Q])}else f=l;return g&&C(f,typeof t=="function"?t.displayName||t.name||"Unknown":t),T(t,g,f,p(),U,Z)}function y(t){v(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===V&&(t._payload.status==="fulfilled"?v(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function v(t){return typeof t=="object"&&t!==null&&t.$$typeof===P}var F=o,P=Symbol.for("react.transitional.element"),I=Symbol.for("react.portal"),Y=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),B=Symbol.for("react.profiler"),j=Symbol.for("react.consumer"),R=Symbol.for("react.context"),A=Symbol.for("react.forward_ref"),te=Symbol.for("react.suspense"),ce=Symbol.for("react.suspense_list"),ie=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),he=Symbol.for("react.activity"),fe=Symbol.for("react.client.reference"),G=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W=Object.prototype.hasOwnProperty,de=Array.isArray,se=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(t){return t()}};var J,H={},re=F.react_stack_bottom_frame.bind(F,i)(),X=se(m(i)),ne={};oe.Fragment=Y,oe.jsx=function(t,l,f){var b=1e4>G.recentlyCreatedOwnerStacks++;return E(t,l,f,!1,b?Error("react-stack-top-frame"):re,b?se(m(t)):X)},oe.jsxs=function(t,l,f){var b=1e4>G.recentlyCreatedOwnerStacks++;return E(t,l,f,!0,b?Error("react-stack-top-frame"):re,b?se(m(t)):X)}})()),oe}var Re;function Ye(){return Re||(Re=1,process.env.NODE_ENV==="production"?pe.exports=Ue():pe.exports=ze()),pe.exports}var e=Ye();function Be(){const[r,c]=o.useState(0),u=o.useRef(Date.now());return o.useEffect(()=>{const m=setInterval(()=>{c(Math.floor((Date.now()-u.current)/1e3))},1e3);return()=>clearInterval(m)},[]),r}function We(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function _e({message:r="Processing your file…",onCancel:c}){const u=Be();return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16 text-slate-600",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-700 border-t-transparent"}),e.jsx("p",{className:"text-sm",children:r}),e.jsx("p",{className:"text-xs tabular-nums text-slate-500",children:We(u)}),u>=10?e.jsx("p",{className:"max-w-xs text-center text-xs text-slate-500",children:"Large documents can take a while. You can keep working in other tabs."}):null,c?e.jsx("button",{type:"button",onClick:c,className:"mt-2 rounded border border-slate-300 px-3 py-1.5 text-xs font-medium text-slate-700 hover:bg-slate-50",children:"Cancel"}):null]})}const Ae=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],qe={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:Ae,convertFile:D.handleImportUploadFile,prepare:async r=>{const{files:c,assets:u}=await D.extractUpload(r);return{fileName:r.name,files:c,assets:u,analysis:D.analyzeImportSources(c)}},convertPrepared:(r,c)=>D.importProjectFromFiles(r.files,{...c,assets:r.assets})};function Ne(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const Ce={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function Ke(r){const c=r.reason==="manifest-target"?`project.ptx target “${r.targetName}”`:r.reason==="latex-root"?"LaTeX document":r.reason==="pretext-root"?"PreTeXt document":r.reason==="markdown-root"?"Markdown document":"possible document";return r.title?`${r.title} — ${c}`:c}function Ve(r){return r.candidates.filter(u=>u.reason==="manifest-target").length>1?!0:r.manifest&&r.primary?.reason==="manifest-target"?!1:r.formats.length>1||r.candidates.length>1||r.extraRoots.length>0}function Ge({onConfirm:r,onCancel:c,importOptions:u,defaultDocumentKind:m="auto",defaultImportMode:p=K.DEFAULT_IMPORT_MODE,lockImportMode:i=!1,onImportModeChange:N,engines:C,insertTarget:h}){const T=C&&C.length>0?C:[qe],E=o.useRef(null),[y,v]=o.useState({name:"upload"}),[F,P]=o.useState(!1),[I,Y]=o.useState(m),[_,B]=o.useState(null),[j,R]=o.useState(null),[A,te]=o.useState([]),[ce,ie]=o.useState(new Set),[V,he]=o.useState(T[0].id),[fe,G]=o.useState(p),[W,de]=o.useState(!1),[se,J]=o.useState(new Set),[H,re]=o.useState(null),[X,ne]=o.useState("auto"),[t,l]=o.useState(null),[f,b]=o.useState({}),[U,Z]=o.useState(!1),g=o.useRef(!1),k=T.find(n=>n.id===V)??T[0],Q=k.acceptExtensions??Ae,O=y.name==="review"?y.result:null,ue=o.useMemo(()=>O&&(_!==null||j!==null||A.length>0)?D.rebuildImport(O,{splitLevel:_??void 0,targetTag:j??void 0,selection:A}):O,[O,_,j,A]),be=o.useMemo(()=>O?D.outlineDivisions(O.pretextSource):[],[O]),z=o.useMemo(()=>new Map(ue?K.fileChangesForImport(ue).map(n=>[n.path,n]):[]),[ue]),ye=o.useMemo(()=>h?{kind:"insert",targetTag:j??h.defaultTargetTag,takenIds:new Set(h.takenIds),hrefBase:h.hrefBase}:void 0,[h,j]),ge=()=>({...u??{documentKind:I==="auto"?void 0:I},...ye?{destination:ye}:{},...h?.externalDir?{externalDir:h.externalDir}:{}}),we=n=>D.analyzeImportSources(n.files,{sourceFormat:X==="auto"?void 0:X,mainFile:t??void 0}),Ie=n=>{g.current=!0,k.cancel?.(),v(n?{name:"sources",prepared:n}:{name:"upload"})},Oe=async n=>{g.current=!1,v({name:"processing"}),await Ne();try{const a=we(n).extraRoots.map(x=>({path:x.path,include:f[x.path]?.include??!0,level:f[x.path]?.level})),S=await k.convertPrepared(n,{...ge(),sourceFormat:X==="auto"?void 0:X,mainFile:t??void 0,attachRoots:a});"pretextError"in S?v({name:"error",message:S.pretextError}):v({name:"review",result:S})}catch(d){if(g.current)return;v({name:"error",message:d instanceof Error?d.message:"An unexpected error occurred."})}},Se=async n=>{g.current=!1,v({name:"processing"}),await Ne();try{if(k.prepare&&k.convertPrepared){const a=await k.prepare(n);if(re(a),ne("auto"),l(null),b({}),Ve(a.analysis)){v({name:"sources",prepared:a});return}await Ne();const S=await k.convertPrepared(a,ge());v("pretextError"in S?{name:"error",message:S.pretextError}:{name:"review",result:S});return}const d=await k.convertFile(n,ge());"pretextError"in d?v({name:"error",message:d.pretextError}):v({name:"review",result:d})}catch(d){if(g.current)return;v({name:"error",message:d instanceof Error?d.message:"An unexpected error occurred."})}},je=()=>{v({name:"upload"}),G(p),de(!1),J(new Set),ie(new Set),B(null),R(null),te([]),re(null)};function ke(n,d){return[...n].sort((a,S)=>a===d?-1:S===d?1:a.localeCompare(S))}function Ee(n,d){const a=K.filesForImportMode(n,d),S=d==="converted"?n.projectLayout.mainSourcePath:n.sourcePath,x=ke(Object.keys(a),S)[0];J(x?new Set([x]):new Set)}function Le(n){J(d=>{const a=new Set(d);return a.has(n)?a.delete(n):a.add(n),a})}if(y.name==="processing")return e.jsx(_e,{onCancel:k.cancel?()=>Ie(H):void 0});if(y.name==="error")return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800",children:[e.jsx("p",{className:"font-semibold",children:"Import failed"}),e.jsx("p",{className:"mt-1",children:y.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:je,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(y.name==="sources"){const n=y.prepared,d=we(n),a=d.manifest,S=d.primary?.path??"";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:"Choose what to import"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[n.fileName," contains more than one possible starting point."]})]}),a?e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm text-blue-900",children:[e.jsxs("p",{className:"font-medium",children:["Found ",a.manifestPath," — an existing PreTeXt project."]}),e.jsxs("p",{className:"mt-1 text-blue-800",children:["Its publication file, assets, and directory layout will be kept as they are. Targets:"," ",a.targets.map(x=>x.name).join(", "),"."]})]}):null,e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Source format"}),e.jsxs("select",{value:X,onChange:x=>{ne(x.currentTarget.value),l(null),b({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",d.primary?` (${Ce[d.primary.format]})`:""]}),d.formats.map(x=>e.jsx("option",{value:x,children:Ce[x]},x))]})]})}),d.candidates.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Main document"}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:d.candidates.map(x=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:x.path,checked:S===x.path,onChange:()=>{l(x.path),b({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:x.path}),e.jsx("span",{className:"block text-slate-500",children:Ke(x)})]})]},x.path))})]}):null,d.extraRoots.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Other documents"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"These files also stand on their own. Attach them to the main document, or leave them out."}),e.jsx("div",{className:"mt-3 flex flex-col gap-2",children:d.extraRoots.map(x=>{const ae=f[x.path],L=ae?.include??!0;return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm",children:[e.jsxs("label",{className:"flex flex-1 cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:L,onChange:q=>b(M=>({...M,[x.path]:{...M[x.path],include:q.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:x.path}),x.title?e.jsxs("span",{className:"text-slate-500",children:["— ",x.title]}):null]}),e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Attach as"}),e.jsxs("select",{value:ae?.level??"auto",disabled:!L,onChange:q=>b(M=>({...M,[x.path]:{include:M[x.path]?.include??!0,level:q.currentTarget.value==="auto"?void 0:q.currentTarget.value}})),className:"rounded border border-slate-300 px-2 py-1 text-sm disabled:opacity-50",children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"chapter",children:"Chapter"}),e.jsx("option",{value:"section",children:"Section"})]})]})]},x.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:je,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Oe(n),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(y.name==="review"){let n=function(s){G(s),N?.(s),W&&Ee(a,s)},d=function(s){ie(w=>{const ee=new Set(w);return ee.has(s)?ee.delete(s):ee.add(s),ee})};const a=ue??y.result,S=a.splitLevel,x=A.length>0,ae=K.hasNativeImportMode(a)&&!x,L=ae?K.resolveImportMode(a,fe):"converted",q=a.detectedSourceFormat==="markdown"?"Markdown":"LaTeX",M=a.warnings.length,Me=Object.keys(a.outputFiles).length,$=a.insert,me=a.destination.kind==="insert"?a.destination.targetTag:void 0,$e=h?.targetTags??[...D.DIVISION_LADDER],ve=K.filesForImportMode(a,L),Xe=L==="converted"?a.projectLayout.mainSourcePath:a.sourcePath,xe=ke(Object.keys(ve),Xe);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-slate-700",children:"Import Summary"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsx("dt",{className:"text-slate-500",children:"Source"}),e.jsx("dd",{className:"font-medium text-slate-900",children:a.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:Me}),h?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Destination"}),e.jsxs("dd",{className:"font-medium text-slate-900",children:["Inserted into ",h.documentLabel]})]}):null,a.projectLayout.preserved?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Existing project"}),e.jsx("dd",{className:"font-medium text-slate-900",children:"Kept publication file, assets, and layout"})]}):null,a.attachedRoots.length>0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Attached"}),e.jsx("dd",{className:"font-medium text-slate-900",children:a.attachedRoots.map(s=>`${s.title} (${s.level})`).join(", ")})]}):null]})]}),M>0?e.jsxs("details",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-amber-800",children:[M," conversion"," ",M===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:a.warnings.map((s,w)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:s.macro})," — ",s.action==="replace"||s.action==="rewrite"?`replaced with \`${s.replacement}\``:s.message??s.action,s.occurrences>1?` (×${s.occurrences})`:null]},w))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),ae&&!i?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Import mode"}),e.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"converted",checked:L==="converted",onChange:()=>n("converted"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Convert to PreTeXt"}),e.jsx("span",{className:"block text-slate-500",children:"Use the converted PreTeXt output. Recommended for new PreTeXt projects."})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"native",checked:L==="native",onChange:()=>n("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Keep as ",q]}),e.jsxs("span",{className:"block text-slate-500",children:["Preserve the original ",q," source. The conversion will not be applied."]})]})]})]})]}):null,be.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Divisions to import"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("button",{type:"button",onClick:()=>te([]),className:"rounded border border-slate-300 px-3 py-1 text-slate-700 hover:bg-slate-50",children:"Everything"}),e.jsx("span",{className:"text-slate-500",children:A.length===0?"The whole document":`${A.length} of ${Fe(be)} divisions`})]}),e.jsx("div",{className:"mt-3 max-h-56 overflow-auto",children:e.jsx(De,{items:be,selection:A,onToggle:s=>te(w=>w.includes(s)?w.filter(ee=>ee!==s):[...w,s].sort(Je))})}),A.length>0?e.jsxs("p",{className:"mt-2 text-sm text-slate-500",children:["A selected division is imported whole, with everything inside it. Divisions above one you selected are kept as structure.",K.hasNativeImportMode(y.result)?" Selecting divisions imports the converted PreTeXt; keeping the original source imports the document whole.":""]}):null]}):null,$&&h?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsxs("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:["Attach to ",h.documentLabel]}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:$e.map(s=>e.jsxs("button",{type:"button",onClick:()=>R(s),"aria-pressed":me===s,className:me===s?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:["<",s,">"]},s))}),e.jsxs("p",{className:"mt-3 text-sm text-slate-600",children:[$.includes.length===1?`One <${me}> is added to ${h.documentLabel}, `:`${$.includes.length} <${me}> divisions are added to ${h.documentLabel}, `,$.includes.length===1?"included from a new file beside it.":"each included from a new file beside it."]}),$.renamed.length>0?e.jsxs("p",{className:"mt-2 text-sm text-amber-700",children:[$.renamed.length," id",$.renamed.length===1?"":"s"," already used in this project"," ",$.renamed.length===1?"was":"were"," renamed:"," ",e.jsx("span",{className:"font-mono text-xs",children:$.renamed.map(s=>`${s.from} → ${s.to}`).join(", ")})]}):null]}):null,!u&&a.cleanChunks.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Split into files"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Array.from({length:D.MAX_SUGGESTED_SPLIT_LEVEL+1},(s,w)=>e.jsx("button",{type:"button",onClick:()=>B(w),"aria-pressed":S===w,className:S===w?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:w===0?"One file":`${w} level${w===1?"":"s"}`},w)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[xe.length," file",xe.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:xe.map(s=>e.jsxs("li",{className:"truncate py-0.5",children:[s,z.get(s)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[z.get(s).fixCount," change",z.get(s).fixCount===1?"":"s"]}):null]},s))})]}):null,W?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:xe.map(s=>{const w=se.has(s);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Le(s),className:"flex w-full items-center gap-2 bg-slate-100 px-4 py-2 text-left font-mono text-xs text-slate-700 hover:bg-slate-200",children:[e.jsx("span",{className:"shrink-0 text-slate-400",children:w?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:s}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(ve[s].length/1024).toFixed(1)," KB"]})]}),w?e.jsxs("div",{className:"bg-white",children:[z.get(s)?.hunks.length?e.jsxs("div",{className:"flex gap-2 border-b border-slate-200 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>d(s),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:ce.has(s)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",z.get(s).stats.added," −",z.get(s).stats.removed," in the LaTeX source"]})]}):null,ce.has(s)&&z.has(s)?e.jsx(He,{hunks:z.get(s).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:ve[s]})]}):null]},s)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:c??je,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:c?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[H?e.jsx("button",{type:"button",onClick:()=>v({name:"sources",prepared:H}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{W||Ee(a,L),de(s=>!s)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:W?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:U,onClick:async()=>{Z(!0);try{await r(a,L)}finally{Z(!1)}},className:"flex items-center gap-2 rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600 disabled:opacity-60",children:[U?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"}):null,U?h?"Inserting…":"Importing…":h?"Confirm Insert":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[T.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Converter"}),e.jsx("div",{className:"mt-2 flex flex-col gap-3",children:T.map(n=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-engine",value:n.id,checked:V===n.id,onChange:()=>he(n.id),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:n.label}),n.description?e.jsx("span",{className:"block text-slate-500",children:n.description}):null]})]},n.id))})]}):null,u?null:e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Document kind"}),e.jsxs("select",{value:I,onChange:n=>Y(n.currentTarget.value),className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:n=>n.key==="Enter"&&E.current?.click(),onClick:()=>E.current?.click(),onDragOver:n=>{n.preventDefault(),P(!0)},onDragLeave:()=>P(!1),onDrop:n=>{n.preventDefault(),P(!1);const d=n.dataTransfer.files?.[0];d&&Se(d)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${F?"border-blue-500 bg-blue-50":"border-slate-300 bg-slate-50 hover:border-slate-400"}`,children:[e.jsx("p",{className:"text-slate-600",children:"Drop a file here, or click to select."}),e.jsx("button",{type:"button",onClick:n=>{n.stopPropagation(),E.current?.click()},className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Select File"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Supports ",Q.join(", ")]}),e.jsx("input",{ref:E,type:"file",hidden:!0,accept:Q.join(","),onChange:n=>{const d=n.currentTarget.files?.[0];d&&Se(d),n.currentTarget.value=""}})]})]})}function Fe(r){return r.reduce((c,u)=>c+1+Fe(u.children),0)}function Je(r,c){const u=r.split(".").map(Number),m=c.split(".").map(Number);for(let p=0;p<Math.max(u.length,m.length);p++){const i=(u[p]??-1)-(m[p]??-1);if(i!==0)return i}return 0}function De({items:r,selection:c,onToggle:u}){return e.jsx("ul",{className:"space-y-0.5 text-sm",children:r.map(m=>{const p=c.includes(m.path),i=c.some(N=>m.path.startsWith(`${N}.`));return e.jsxs("li",{children:[e.jsxs("label",{className:"flex items-baseline gap-2",children:[e.jsx("input",{type:"checkbox",checked:p||i,disabled:i,onChange:()=>u(m.path)}),e.jsxs("span",{className:i?"text-slate-400":"text-slate-700",children:[m.title||e.jsx("em",{children:"Untitled"}),e.jsxs("span",{className:"ml-2 font-mono text-xs text-slate-400",children:["<",m.tag,">"]})]})]}),m.children.length>0?e.jsx("div",{className:"ml-5 border-l border-slate-200 pl-3",children:e.jsx(De,{items:m.children,selection:c,onToggle:u})}):null]},m.path)})})}function He({hunks:r}){return r.length===0?e.jsx("p",{className:"m-0 px-4 py-3 text-xs text-slate-500",children:"Nothing was changed in this file."}):e.jsx("div",{className:"max-h-72 overflow-auto bg-white font-mono text-xs leading-relaxed",children:r.map((c,u)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[u>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,c.lines.map((m,p)=>e.jsxs("div",{className:m.op==="add"?"bg-green-50 px-4 text-green-900":m.op==="remove"?"bg-red-50 px-4 text-red-900":"px-4 text-slate-600",children:[e.jsx("span",{className:"mr-2 select-none text-slate-400",children:m.op==="add"?"+":m.op==="remove"?"−":" "}),m.text||" "]},p))]},u))})}const Ze={title:"Import Source Content",description:"Paste LaTeX, Markdown, or PreTeXt source to convert into PreTeXt.",sourceLabel:"Source",sourcePlaceholder:"Paste source content here...",formatLabel:"Source format",convertButton:"Convert to PreTeXt",detectedFormatPrefix:"Detected",successPrefix:"Ready",errorPrefix:"Error"};function Qe({initialSource:r="",initialSourceFormat:c,labels:u,disabled:m=!1,onImport:p}){const i=o.useMemo(()=>({...Ze,...u??{}}),[u]),[N,C]=o.useState(r),[h,T]=o.useState(c??"auto"),[E,y]=o.useState(null),v=o.useMemo(()=>D.detectSourceFormat(N),[N]),F=m||!N.trim();return e.jsx("form",{onSubmit:P=>{P.preventDefault();const I=D.convertSourceToPretext(N,h==="auto"?void 0:h);y(I),p(I)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:m,children:[e.jsx("legend",{children:i.title}),e.jsx("p",{children:i.description}),e.jsxs("label",{children:[i.sourceLabel,e.jsx("textarea",{value:N,onChange:P=>C(P.currentTarget.value),placeholder:i.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[i.formatLabel,e.jsxs("select",{value:h,onChange:P=>T(P.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"latex",children:"LaTeX"}),e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"pretext",children:"PreTeXt"})]})]}),e.jsxs("p",{children:[i.detectedFormatPrefix,": ",e.jsx("strong",{children:v})]}),e.jsx("button",{type:"submit",disabled:F,children:i.convertButton}),E?"pretextError"in E?e.jsxs("p",{role:"alert",children:[i.errorPrefix,": ",E.pretextError]}):e.jsxs("p",{children:[i.successPrefix,": ",E.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const et={title:"Upload Source File",hint:"Supports .tex, .md, .ptx, .xml, .zip, and .tar.gz files.",selectButton:"Select File",dropHint:"Drop a file here, or click Select File.",documentKindLabel:"Document kind",splitSectionsLabel:"Split each chapter into sections"};function tt({labels:r,disabled:c=!1,defaultDocumentKind:u="auto",importOptions:m,onImport:p}){const i=o.useMemo(()=>({...et,...r??{}}),[r]),N=o.useRef(null),[C,h]=o.useState(!1),[T,E]=o.useState(!1),[y,v]=o.useState([]),[F,P]=o.useState(u),[I,Y]=o.useState(!1),_=c||T,B=async j=>{E(!0);try{const R=m??{documentKind:F==="auto"?void 0:F,splitSections:I},A=await D.handleImportUploadFile(j,R);v(A.statusMessages),p(A)}finally{E(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:i.title}),e.jsx("p",{children:i.hint}),m?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[i.documentKindLabel,e.jsxs("select",{value:F,disabled:_,onChange:j=>P(j.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]}),e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:I,disabled:_,onChange:j=>Y(j.currentTarget.checked)}),i.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:j=>{j.preventDefault(),_||h(!0)},onDragLeave:()=>h(!1),onDrop:j=>{if(j.preventDefault(),h(!1),_)return;const R=j.dataTransfer.files?.[0];R&&B(R)},children:[e.jsx("p",{children:i.dropHint}),e.jsxs("button",{type:"button",disabled:_,onClick:()=>N.current?.click(),className:"inline-flex items-center gap-2",children:[T?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent","aria-hidden":"true"}):null,T?"Processing…":i.selectButton]}),e.jsx("input",{ref:N,type:"file",hidden:!0,disabled:_,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:j=>{const R=j.currentTarget.files?.[0];R&&B(R),j.currentTarget.value=""}})]}),T?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,y.length>0?e.jsx("ul",{"aria-live":"polite",children:y.map((j,R)=>e.jsx("li",{children:j.message},`${j.type}-${R}`))}):null,C&&!_?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=Qe;exports.ImportUploadPanel=tt;exports.ImportWizard=Ge;exports.ProcessingPanel=_e;
|
|
6
|
+
<%s key={someKey} {...props} />`,g,v,L,v),te[v+g]=!0)}if(v=null,f!==void 0&&(u(f),v=""+f),y(l)&&(u(l.key),v=""+l.key),"key"in l){f={};for(var $ in l)$!=="key"&&(f[$]=l[$])}else f=l;return v&&R(f,typeof t=="function"?t.displayName||t.name||"Unknown":t),k(t,v,f,p(),B,O)}function w(t){j(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===ae&&(t._payload.status==="fulfilled"?j(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function j(t){return typeof t=="object"&&t!==null&&t.$$typeof===T}var F=o,T=Symbol.for("react.transitional.element"),D=Symbol.for("react.portal"),K=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),b=Symbol.for("react.consumer"),P=Symbol.for("react.context"),_=Symbol.for("react.forward_ref"),ne=Symbol.for("react.suspense"),ie=Symbol.for("react.suspense_list"),de=Symbol.for("react.memo"),ae=Symbol.for("react.lazy"),ve=Symbol.for("react.activity"),G=Symbol.for("react.client.reference"),J=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ue=Object.prototype.hasOwnProperty,me=Array.isArray,z=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(t){return t()}};var le,xe={},Q=F.react_stack_bottom_frame.bind(F,d)(),ee=z(m(d)),te={};ce.Fragment=K,ce.jsx=function(t,l,f){var g=1e4>J.recentlyCreatedOwnerStacks++;return E(t,l,f,!1,g?Error("react-stack-top-frame"):Q,g?z(m(t)):ee)},ce.jsxs=function(t,l,f){var g=1e4>J.recentlyCreatedOwnerStacks++;return E(t,l,f,!0,g?Error("react-stack-top-frame"):Q,g?z(m(t)):ee)}})()),ce}var Oe;function Ge(){return Oe||(Oe=1,process.env.NODE_ENV==="production"?ge.exports=Ke():ge.exports=Ve()),ge.exports}var e=Ge();function Je(){const[r,i]=o.useState(0),u=o.useRef(Date.now());return o.useEffect(()=>{const m=setInterval(()=>{i(Math.floor((Date.now()-u.current)/1e3))},1e3);return()=>clearInterval(m)},[]),r}function He(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function $e({message:r="Processing your file…",onCancel:i}){const u=Je();return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16 text-slate-600",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-700 border-t-transparent"}),e.jsx("p",{className:"text-sm",children:r}),e.jsx("p",{className:"text-xs tabular-nums text-slate-500",children:He(u)}),u>=10?e.jsx("p",{className:"max-w-xs text-center text-xs text-slate-500",children:"Large documents can take a while. You can keep working in other tabs."}):null,i?e.jsx("button",{type:"button",onClick:i,className:"mt-2 rounded border border-slate-300 px-3 py-1.5 text-xs font-medium text-slate-700 hover:bg-slate-50",children:"Cancel"}):null]})}const Ze={id:"builtin",label:"Built-in converter",description:"Converts LaTeX, Markdown, and PreTeXt without any other tools.",acceptExtensions:A.DEFAULT_ACCEPT_EXTENSIONS,convertFile:I.handleImportUploadFile,prepare:async r=>{const{files:i,assets:u}=await I.extractUpload(r);return{fileName:r.name,files:i,assets:u,analysis:I.analyzeImportSources(i)}},convertPrepared:(r,i)=>I.importProjectFromFiles(r.files,{...i,assets:r.assets})};function ke(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const Le={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function Qe(r){const i=r.reason==="manifest-target"?`project.ptx target “${r.targetName}”`:r.reason==="latex-root"?"LaTeX document":r.reason==="pretext-root"?"PreTeXt document":r.reason==="markdown-root"?"Markdown document":"possible document";return r.title?`${r.title} — ${i}`:i}function et(r){return r.candidates.filter(u=>u.reason==="manifest-target").length>1?!0:r.manifest&&r.primary?.reason==="manifest-target"?!1:r.formats.length>1||r.candidates.length>1||r.extraRoots.length>0}function tt({onConfirm:r,onCancel:i,importOptions:u,defaultDocumentKind:m="auto",defaultImportMode:p=A.DEFAULT_IMPORT_MODE,lockImportMode:d=!1,onImportModeChange:y,engines:R,insertTarget:h}){const k=R&&R.length>0?R:[Ze],E=o.useRef(null),[w,j]=o.useState({name:"upload"}),[F,T]=o.useState(!1),[D,K]=o.useState(m),[C,V]=o.useState(null),[b,P]=o.useState(null),[_,ne]=o.useState([]),[ie,de]=o.useState(new Set),[ae,ve]=o.useState(k[0].id),[G,J]=o.useState(null),[ue,me]=o.useState(p),[z,le]=o.useState(!1),[xe,Q]=o.useState(new Set),[ee,te]=o.useState(null),[t,l]=o.useState("auto"),[f,g]=o.useState(null),[B,O]=o.useState({}),[v,L]=o.useState(!1),$=o.useRef(!1),se=k.find(n=>n.id===ae)??k[0],Ee=A.allAcceptExtensions(k),W=G?A.alternateFor(k,G.name):void 0,Te=W?se.id===W.id:!1,pe=W?Te?A.routeEngine(k,G.name)??null:W:null,H=w.name==="review"?w.result:null,he=o.useMemo(()=>H&&(C!==null||b!==null||_.length>0)?I.rebuildImport(H,{splitLevel:C??void 0,targetTag:b??void 0,selection:_}):H,[H,C,b,_]),je=o.useMemo(()=>H?I.outlineDivisions(H.pretextSource):[],[H]),q=o.useMemo(()=>new Map(he?A.fileChangesForImport(he).map(n=>[n.path,n]):[]),[he]),Pe=o.useMemo(()=>h?{kind:"insert",targetTag:b??h.defaultTargetTag,takenIds:new Set(h.takenIds),hrefBase:h.hrefBase}:void 0,[h,b]),Ne=()=>({...u??{documentKind:D==="auto"?void 0:D},...Pe?{destination:Pe}:{},...h?.externalDir?{externalDir:h.externalDir}:{}}),Re=n=>I.analyzeImportSources(n.files,{sourceFormat:t==="auto"?void 0:t,mainFile:f??void 0}),Ue=n=>{$.current=!0,se.cancel?.(),j(n?{name:"sources",prepared:n}:{name:"upload"})},Ye=async n=>{$.current=!1,j({name:"processing"}),await ke();try{const a=Re(n).extraRoots.map(c=>({path:c.path,include:B[c.path]?.include??!0,level:B[c.path]?.level})),N=await se.convertPrepared(n,{...Ne(),sourceFormat:t==="auto"?void 0:t,mainFile:f??void 0,attachRoots:a});"pretextError"in N?j({name:"error",message:N.pretextError}):j({name:"review",result:N})}catch(x){if($.current)return;j({name:"error",message:x instanceof Error?x.message:"An unexpected error occurred."})}},ye=async(n,x)=>{const a=x??A.routeEngine(k,n.name);if(!a){J(n),j({name:"error",message:A.unsupportedFileMessage(n.name,k)});return}J(n),ve(a.id),Ce(),$.current=!1,j({name:"processing"}),await ke();try{if(a.prepare&&a.convertPrepared){const c=await a.prepare(n);if(te(c),l("auto"),g(null),O({}),et(c.analysis)){j({name:"sources",prepared:c});return}await ke();const M=await a.convertPrepared(c,Ne());j("pretextError"in M?{name:"error",message:M.pretextError}:{name:"review",result:M});return}te(null);const N=await a.convertFile(n,Ne());"pretextError"in N?j({name:"error",message:N.pretextError}):j({name:"review",result:N})}catch(N){if($.current)return;j({name:"error",message:N instanceof Error?N.message:"An unexpected error occurred."})}},Ce=()=>{me(p),le(!1),Q(new Set),de(new Set),V(null),P(null),ne([])},we=()=>{j({name:"upload"}),Ce(),te(null),J(null)},_e=()=>{G&&pe&&ye(G,pe)};function Ae(n,x){return[...n].sort((a,N)=>a===x?-1:N===x?1:a.localeCompare(N))}function Fe(n,x){const a=A.filesForImportMode(n,x),N=x==="converted"?n.projectLayout.mainSourcePath:n.sourcePath,c=Ae(Object.keys(a),N)[0];Q(c?new Set([c]):new Set)}function ze(n){Q(x=>{const a=new Set(x);return a.has(n)?a.delete(n):a.add(n),a})}if(w.name==="processing")return e.jsx($e,{onCancel:se.cancel?()=>Ue(ee):void 0});if(w.name==="error")return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800",children:[e.jsx("p",{className:"font-semibold",children:"Import failed"}),e.jsx("p",{className:"mt-1",children:w.message})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[pe?e.jsxs("button",{type:"button",onClick:_e,className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:["Try ",pe.label," Instead"]}):null,e.jsx("button",{type:"button",onClick:we,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})]})]});if(w.name==="sources"){const n=w.prepared,x=Re(n),a=x.manifest,N=x.primary?.path??"";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:"Choose what to import"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[n.fileName," contains more than one possible starting point."]})]}),a?e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm text-blue-900",children:[e.jsxs("p",{className:"font-medium",children:["Found ",a.manifestPath," — an existing PreTeXt project."]}),e.jsxs("p",{className:"mt-1 text-blue-800",children:["Its publication file, assets, and directory layout will be kept as they are. Targets:"," ",a.targets.map(c=>c.name).join(", "),"."]})]}):null,e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Source format"}),e.jsxs("select",{value:t,onChange:c=>{l(c.currentTarget.value),g(null),O({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",x.primary?` (${Le[x.primary.format]})`:""]}),x.formats.map(c=>e.jsx("option",{value:c,children:Le[c]},c))]})]})}),x.candidates.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Main document"}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:x.candidates.map(c=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:c.path,checked:N===c.path,onChange:()=>{g(c.path),O({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:c.path}),e.jsx("span",{className:"block text-slate-500",children:Qe(c)})]})]},c.path))})]}):null,x.extraRoots.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Other documents"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"These files also stand on their own. Attach them to the main document, or leave them out."}),e.jsx("div",{className:"mt-3 flex flex-col gap-2",children:x.extraRoots.map(c=>{const M=B[c.path],X=M?.include??!0;return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm",children:[e.jsxs("label",{className:"flex flex-1 cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:X,onChange:Z=>O(U=>({...U,[c.path]:{...U[c.path],include:Z.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:c.path}),c.title?e.jsxs("span",{className:"text-slate-500",children:["— ",c.title]}):null]}),e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Attach as"}),e.jsxs("select",{value:M?.level??"auto",disabled:!X,onChange:Z=>O(U=>({...U,[c.path]:{include:U[c.path]?.include??!0,level:Z.currentTarget.value==="auto"?void 0:Z.currentTarget.value}})),className:"rounded border border-slate-300 px-2 py-1 text-sm disabled:opacity-50",children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"chapter",children:"Chapter"}),e.jsx("option",{value:"section",children:"Section"})]})]})]},c.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:we,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Ye(n),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(w.name==="review"){let n=function(s){me(s),y?.(s),z&&Fe(a,s)},x=function(s){de(S=>{const re=new Set(S);return re.has(s)?re.delete(s):re.add(s),re})};const a=he??w.result,N=a.splitLevel,c=_.length>0,M=A.hasNativeImportMode(a)&&!c,X=M?A.resolveImportMode(a,ue):"converted",Z=a.detectedSourceFormat==="markdown"?"Markdown":"LaTeX",U=a.warnings.length,Be=Object.keys(a.outputFiles).length,Y=a.insert,fe=a.destination.kind==="insert"?a.destination.targetTag:void 0,We=h?.targetTags??[...I.DIVISION_LADDER],Se=A.filesForImportMode(a,X),qe=X==="converted"?a.projectLayout.mainSourcePath:a.sourcePath,be=Ae(Object.keys(Se),qe);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-slate-700",children:"Import Summary"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsx("dt",{className:"text-slate-500",children:"Source"}),e.jsx("dd",{className:"font-medium text-slate-900",children:a.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:Be}),h?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Destination"}),e.jsxs("dd",{className:"font-medium text-slate-900",children:["Inserted into ",h.documentLabel]})]}):null,a.projectLayout.preserved?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Existing project"}),e.jsx("dd",{className:"font-medium text-slate-900",children:"Kept publication file, assets, and layout"})]}):null,a.attachedRoots.length>0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Attached"}),e.jsx("dd",{className:"font-medium text-slate-900",children:a.attachedRoots.map(s=>`${s.title} (${s.level})`).join(", ")})]}):null]})]}),W?e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-lg border border-slate-200 p-4 text-sm",children:[e.jsx("input",{type:"checkbox",checked:Te,onChange:_e,className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Convert with ",W.label," instead"]}),e.jsx("span",{className:"block text-slate-500",children:W.description??`Runs ${a.sourceName} through ${W.label} and rebuilds this preview.`})]})]}):null,U>0?e.jsxs("details",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-amber-800",children:[U," conversion"," ",U===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:a.warnings.map((s,S)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:s.macro})," — ",s.action==="replace"||s.action==="rewrite"?`replaced with \`${s.replacement}\``:s.message??s.action,s.occurrences>1?` (×${s.occurrences})`:null]},S))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),M&&!d?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Import mode"}),e.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"converted",checked:X==="converted",onChange:()=>n("converted"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Convert to PreTeXt"}),e.jsx("span",{className:"block text-slate-500",children:"Use the converted PreTeXt output. Recommended for new PreTeXt projects."})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"native",checked:X==="native",onChange:()=>n("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Keep as ",Z]}),e.jsxs("span",{className:"block text-slate-500",children:["Preserve the original ",Z," source. The conversion will not be applied."]})]})]})]})]}):null,je.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Divisions to import"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("button",{type:"button",onClick:()=>ne([]),className:"rounded border border-slate-300 px-3 py-1 text-slate-700 hover:bg-slate-50",children:"Everything"}),e.jsx("span",{className:"text-slate-500",children:_.length===0?"The whole document":`${_.length} of ${Me(je)} divisions`})]}),e.jsx("div",{className:"mt-3 max-h-56 overflow-auto",children:e.jsx(Xe,{items:je,selection:_,onToggle:s=>ne(S=>S.includes(s)?S.filter(re=>re!==s):[...S,s].sort(st))})}),_.length>0?e.jsxs("p",{className:"mt-2 text-sm text-slate-500",children:["A selected division is imported whole, with everything inside it. Divisions above one you selected are kept as structure.",A.hasNativeImportMode(w.result)?" Selecting divisions imports the converted PreTeXt; keeping the original source imports the document whole.":""]}):null]}):null,Y&&h?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsxs("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:["Attach to ",h.documentLabel]}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:We.map(s=>e.jsxs("button",{type:"button",onClick:()=>P(s),"aria-pressed":fe===s,className:fe===s?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:["<",s,">"]},s))}),e.jsxs("p",{className:"mt-3 text-sm text-slate-600",children:[Y.includes.length===1?`One <${fe}> is added to ${h.documentLabel}, `:`${Y.includes.length} <${fe}> divisions are added to ${h.documentLabel}, `,Y.includes.length===1?"included from a new file beside it.":"each included from a new file beside it."]}),Y.renamed.length>0?e.jsxs("p",{className:"mt-2 text-sm text-amber-700",children:[Y.renamed.length," id",Y.renamed.length===1?"":"s"," already used in this project"," ",Y.renamed.length===1?"was":"were"," renamed:"," ",e.jsx("span",{className:"font-mono text-xs",children:Y.renamed.map(s=>`${s.from} → ${s.to}`).join(", ")})]}):null]}):null,!u&&a.cleanChunks.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Split into files"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Array.from({length:I.MAX_SUGGESTED_SPLIT_LEVEL+1},(s,S)=>e.jsx("button",{type:"button",onClick:()=>V(S),"aria-pressed":N===S,className:N===S?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:S===0?"One file":`${S} level${S===1?"":"s"}`},S)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[be.length," file",be.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:be.map(s=>e.jsxs("li",{className:"truncate py-0.5",children:[s,q.get(s)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[q.get(s).fixCount," change",q.get(s).fixCount===1?"":"s"]}):null]},s))})]}):null,z?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:be.map(s=>{const S=xe.has(s);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>ze(s),className:"flex w-full items-center gap-2 bg-slate-100 px-4 py-2 text-left font-mono text-xs text-slate-700 hover:bg-slate-200",children:[e.jsx("span",{className:"shrink-0 text-slate-400",children:S?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:s}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(Se[s].length/1024).toFixed(1)," KB"]})]}),S?e.jsxs("div",{className:"bg-white",children:[q.get(s)?.hunks.length?e.jsxs("div",{className:"flex gap-2 border-b border-slate-200 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>x(s),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:ie.has(s)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",q.get(s).stats.added," −",q.get(s).stats.removed," in the LaTeX source"]})]}):null,ie.has(s)&&q.has(s)?e.jsx(rt,{hunks:q.get(s).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:Se[s]})]}):null]},s)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:i??we,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:i?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[ee?e.jsx("button",{type:"button",onClick:()=>j({name:"sources",prepared:ee}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{z||Fe(a,X),le(s=>!s)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:z?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:v,onClick:async()=>{L(!0);try{await r(a,X)}finally{L(!1)}},className:"flex items-center gap-2 rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600 disabled:opacity-60",children:[v?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"}):null,v?h?"Inserting…":"Importing…":h?"Confirm Insert":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[u?null:e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Document kind"}),e.jsxs("select",{value:D,onChange:n=>K(n.currentTarget.value),className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:n=>n.key==="Enter"&&E.current?.click(),onClick:()=>E.current?.click(),onDragOver:n=>{n.preventDefault(),T(!0)},onDragLeave:()=>T(!1),onDrop:n=>{n.preventDefault(),T(!1);const x=n.dataTransfer.files?.[0];x&&ye(x)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${F?"border-blue-500 bg-blue-50":"border-slate-300 bg-slate-50 hover:border-slate-400"}`,children:[e.jsx("p",{className:"text-slate-600",children:"Drop a file here, or click to select."}),e.jsx("button",{type:"button",onClick:n=>{n.stopPropagation(),E.current?.click()},className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Select File"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Supports ",Ee.join(", ")]}),e.jsx("input",{ref:E,type:"file",hidden:!0,accept:Ee.join(","),onChange:n=>{const x=n.currentTarget.files?.[0];x&&ye(x),n.currentTarget.value=""}})]})]})}function Me(r){return r.reduce((i,u)=>i+1+Me(u.children),0)}function st(r,i){const u=r.split(".").map(Number),m=i.split(".").map(Number);for(let p=0;p<Math.max(u.length,m.length);p++){const d=(u[p]??-1)-(m[p]??-1);if(d!==0)return d}return 0}function Xe({items:r,selection:i,onToggle:u}){return e.jsx("ul",{className:"space-y-0.5 text-sm",children:r.map(m=>{const p=i.includes(m.path),d=i.some(y=>m.path.startsWith(`${y}.`));return e.jsxs("li",{children:[e.jsxs("label",{className:"flex items-baseline gap-2",children:[e.jsx("input",{type:"checkbox",checked:p||d,disabled:d,onChange:()=>u(m.path)}),e.jsxs("span",{className:d?"text-slate-400":"text-slate-700",children:[m.title||e.jsx("em",{children:"Untitled"}),e.jsxs("span",{className:"ml-2 font-mono text-xs text-slate-400",children:["<",m.tag,">"]})]})]}),m.children.length>0?e.jsx("div",{className:"ml-5 border-l border-slate-200 pl-3",children:e.jsx(Xe,{items:m.children,selection:i,onToggle:u})}):null]},m.path)})})}function rt({hunks:r}){return r.length===0?e.jsx("p",{className:"m-0 px-4 py-3 text-xs text-slate-500",children:"Nothing was changed in this file."}):e.jsx("div",{className:"max-h-72 overflow-auto bg-white font-mono text-xs leading-relaxed",children:r.map((i,u)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[u>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,i.lines.map((m,p)=>e.jsxs("div",{className:m.op==="add"?"bg-green-50 px-4 text-green-900":m.op==="remove"?"bg-red-50 px-4 text-red-900":"px-4 text-slate-600",children:[e.jsx("span",{className:"mr-2 select-none text-slate-400",children:m.op==="add"?"+":m.op==="remove"?"−":" "}),m.text||" "]},p))]},u))})}const nt={title:"Import Source Content",description:"Paste LaTeX, Markdown, or PreTeXt source to convert into PreTeXt.",sourceLabel:"Source",sourcePlaceholder:"Paste source content here...",formatLabel:"Source format",convertButton:"Convert to PreTeXt",detectedFormatPrefix:"Detected",successPrefix:"Ready",errorPrefix:"Error"};function at({initialSource:r="",initialSourceFormat:i,labels:u,disabled:m=!1,onImport:p}){const d=o.useMemo(()=>({...nt,...u??{}}),[u]),[y,R]=o.useState(r),[h,k]=o.useState(i??"auto"),[E,w]=o.useState(null),j=o.useMemo(()=>I.detectSourceFormat(y),[y]),F=m||!y.trim();return e.jsx("form",{onSubmit:T=>{T.preventDefault();const D=I.convertSourceToPretext(y,h==="auto"?void 0:h);w(D),p(D)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:m,children:[e.jsx("legend",{children:d.title}),e.jsx("p",{children:d.description}),e.jsxs("label",{children:[d.sourceLabel,e.jsx("textarea",{value:y,onChange:T=>R(T.currentTarget.value),placeholder:d.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[d.formatLabel,e.jsxs("select",{value:h,onChange:T=>k(T.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"latex",children:"LaTeX"}),e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"pretext",children:"PreTeXt"})]})]}),e.jsxs("p",{children:[d.detectedFormatPrefix,": ",e.jsx("strong",{children:j})]}),e.jsx("button",{type:"submit",disabled:F,children:d.convertButton}),E?"pretextError"in E?e.jsxs("p",{role:"alert",children:[d.errorPrefix,": ",E.pretextError]}):e.jsxs("p",{children:[d.successPrefix,": ",E.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const lt={title:"Upload Source File",hint:"Supports .tex, .md, .ptx, .xml, .zip, and .tar.gz files.",selectButton:"Select File",dropHint:"Drop a file here, or click Select File.",documentKindLabel:"Document kind",splitSectionsLabel:"Split each chapter into sections"};function ot({labels:r,disabled:i=!1,defaultDocumentKind:u="auto",importOptions:m,onImport:p}){const d=o.useMemo(()=>({...lt,...r??{}}),[r]),y=o.useRef(null),[R,h]=o.useState(!1),[k,E]=o.useState(!1),[w,j]=o.useState([]),[F,T]=o.useState(u),[D,K]=o.useState(!1),C=i||k,V=async b=>{E(!0);try{const P=m??{documentKind:F==="auto"?void 0:F,splitSections:D},_=await I.handleImportUploadFile(b,P);j(_.statusMessages),p(_)}finally{E(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:d.title}),e.jsx("p",{children:d.hint}),m?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[d.documentKindLabel,e.jsxs("select",{value:F,disabled:C,onChange:b=>T(b.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]}),e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:D,disabled:C,onChange:b=>K(b.currentTarget.checked)}),d.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:b=>{b.preventDefault(),C||h(!0)},onDragLeave:()=>h(!1),onDrop:b=>{if(b.preventDefault(),h(!1),C)return;const P=b.dataTransfer.files?.[0];P&&V(P)},children:[e.jsx("p",{children:d.dropHint}),e.jsxs("button",{type:"button",disabled:C,onClick:()=>y.current?.click(),className:"inline-flex items-center gap-2",children:[k?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent","aria-hidden":"true"}):null,k?"Processing…":d.selectButton]}),e.jsx("input",{ref:y,type:"file",hidden:!0,disabled:C,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:b=>{const P=b.currentTarget.files?.[0];P&&V(P),b.currentTarget.value=""}})]}),k?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,w.length>0?e.jsx("ul",{"aria-live":"polite",children:w.map((b,P)=>e.jsx("li",{children:b.message},`${b.type}-${P}`))}):null,R&&!C?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=at;exports.ImportUploadPanel=ot;exports.ImportWizard=tt;exports.ProcessingPanel=$e;
|