@pretextbook/import 0.16.0 → 0.17.1
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/README.md +39 -0
- package/dist/convert-worker.cjs +1 -1
- package/dist/convert-worker.js +1 -1
- package/dist/engine-routing-DV5mlLcQ.cjs +3 -0
- package/dist/{engine-routing-DorSgyrU.js → engine-routing-DdzZ92BA.js} +52 -43
- package/dist/import.css +1 -1
- package/dist/index.cjs +12 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1711 -109
- package/dist/lib/engine-routing.d.ts +13 -0
- package/dist/react/import-wizard.d.ts +46 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react.cjs +2 -2
- package/dist/react.js +628 -534
- package/dist/{upload-COaS_4pG.cjs → upload-C2iB-crt.cjs} +4 -2
- package/dist/{upload-Df7DMau_.js → upload-CQcSMuy_.js} +12 -1
- package/package.json +4 -4
- package/dist/engine-routing-3ULYdLy2.cjs +0 -3
|
@@ -21,6 +21,8 @@ export interface RoutableEngine {
|
|
|
21
21
|
description?: string;
|
|
22
22
|
/** Extensions this engine accepts, with leading dots. */
|
|
23
23
|
acceptExtensions?: string[];
|
|
24
|
+
/** Set when the engine is experimental; see `ImportEngine.experimentalNotice`. */
|
|
25
|
+
experimentalNotice?: string;
|
|
24
26
|
}
|
|
25
27
|
/** File extensions accepted by the built-in converter. */
|
|
26
28
|
export declare const DEFAULT_ACCEPT_EXTENSIONS: string[];
|
|
@@ -61,5 +63,16 @@ export declare function routeEngine<T extends RoutableEngine>(engines: T[], file
|
|
|
61
63
|
* to be told which is which.
|
|
62
64
|
*/
|
|
63
65
|
export declare function alternateFor<T extends RoutableEngine>(engines: T[], fileName: string): T | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* The engines the host marked experimental, in list order. Their notices are
|
|
68
|
+
* worth showing before any file is chosen, since a file converts the moment
|
|
69
|
+
* it is dropped.
|
|
70
|
+
*/
|
|
71
|
+
export declare function experimentalEngines<T extends RoutableEngine>(engines: T[]): T[];
|
|
72
|
+
/**
|
|
73
|
+
* The engine an upload goes to, when that engine is experimental, or
|
|
74
|
+
* `undefined` when it goes to a dependable one or to none at all.
|
|
75
|
+
*/
|
|
76
|
+
export declare function experimentalEngineFor<T extends RoutableEngine>(engines: T[], fileName: string): T | undefined;
|
|
64
77
|
/** The message shown when no engine can read the file the author chose. */
|
|
65
78
|
export declare function unsupportedFileMessage(fileName: string, engines: RoutableEngine[]): string;
|
|
@@ -42,6 +42,14 @@ export interface ImportEngine {
|
|
|
42
42
|
description?: string;
|
|
43
43
|
/** Extensions this engine accepts (with leading dot). Defaults to the built-in set. */
|
|
44
44
|
acceptExtensions?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Marks a converter whose results are not yet dependable, in the host's own
|
|
47
|
+
* words — say, "Conversion from Word uses pandoc and is still experimental."
|
|
48
|
+
* The wizard shows it on the upload step, since a file converts the moment
|
|
49
|
+
* it is dropped, and again beside any result or failure this engine
|
|
50
|
+
* produces, where it also offers the host's `shareConversion`.
|
|
51
|
+
*/
|
|
52
|
+
experimentalNotice?: string;
|
|
45
53
|
/** Convert an uploaded file into an import result. */
|
|
46
54
|
convertFile: (file: File, options: ImportProjectOptions) => Promise<ImportedProjectResult>;
|
|
47
55
|
/** Unpack and survey an upload without converting it. */
|
|
@@ -62,6 +70,35 @@ export interface ImportEngine {
|
|
|
62
70
|
*/
|
|
63
71
|
cancel?: () => void;
|
|
64
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* A conversion by an experimental engine, handed to the host when the author
|
|
75
|
+
* chooses to share it (see `ImportWizardProps.shareConversion`).
|
|
76
|
+
*/
|
|
77
|
+
export interface ConversionShare {
|
|
78
|
+
/** The upload exactly as the author chose it. */
|
|
79
|
+
file: File;
|
|
80
|
+
/** `id` of the engine that converted it. */
|
|
81
|
+
engineId: string;
|
|
82
|
+
/** `label` of the engine that converted it. */
|
|
83
|
+
engineLabel: string;
|
|
84
|
+
/** The converted PreTeXt (`pretextSource`), before any re-layout. Absent on failure. */
|
|
85
|
+
pretext?: string;
|
|
86
|
+
/** Why the conversion failed. Absent on success. */
|
|
87
|
+
error?: string;
|
|
88
|
+
}
|
|
89
|
+
/** The host's offer to receive conversions an author chooses to share. */
|
|
90
|
+
export interface ShareConversionOffer {
|
|
91
|
+
/** Text of the share button. Defaults to "Share this conversion". */
|
|
92
|
+
label?: string;
|
|
93
|
+
/** A line before the button saying where the conversion goes and why. */
|
|
94
|
+
description?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Receives the conversion. The wizard waits on it to show "Sharing…" and
|
|
97
|
+
* then "Shared"; a rejection is shown beside the button, which stays
|
|
98
|
+
* available so the author can try again.
|
|
99
|
+
*/
|
|
100
|
+
onShare: (share: ConversionShare) => void | Promise<void>;
|
|
101
|
+
}
|
|
65
102
|
export interface ImportWizardProps {
|
|
66
103
|
/**
|
|
67
104
|
* Called when the user confirms the import. May return a promise — writing
|
|
@@ -102,6 +139,14 @@ export interface ImportWizardProps {
|
|
|
102
139
|
* lets the author move the attach level and see the result before confirming.
|
|
103
140
|
*/
|
|
104
141
|
insertTarget?: InsertTargetOffer;
|
|
142
|
+
/**
|
|
143
|
+
* Let the author send a conversion by an experimental engine (one with an
|
|
144
|
+
* `experimentalNotice`) to the host — its developers, say — so they can see
|
|
145
|
+
* where that converter falls short. Offered after the fact, beside the result
|
|
146
|
+
* or the failure, so the author decides having seen what came out. Omit it
|
|
147
|
+
* and the notice is shown without the offer.
|
|
148
|
+
*/
|
|
149
|
+
shareConversion?: ShareConversionOffer;
|
|
105
150
|
}
|
|
106
151
|
/** What the host knows about the document an import is being inserted into. */
|
|
107
152
|
export interface InsertTargetOffer {
|
|
@@ -124,4 +169,4 @@ export interface InsertTargetOffer {
|
|
|
124
169
|
*/
|
|
125
170
|
externalDir?: string;
|
|
126
171
|
}
|
|
127
|
-
export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, defaultImportMode, lockImportMode, onImportModeChange, engines, insertTarget, }: ImportWizardProps): import("react").JSX.Element;
|
|
172
|
+
export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, defaultImportMode, lockImportMode, onImportModeChange, engines, insertTarget, shareConversion, }: ImportWizardProps): import("react").JSX.Element;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ImportWizard } from './import-wizard';
|
|
2
|
-
export type { ImportWizardProps, ImportMode, ImportEngine, InsertTargetOffer, PreparedUpload, } from './import-wizard';
|
|
2
|
+
export type { ImportWizardProps, ImportMode, ImportEngine, ConversionShare, ShareConversionOffer, InsertTargetOffer, PreparedUpload, } from './import-wizard';
|
|
3
3
|
export { ProcessingPanel } from './processing-panel';
|
|
4
4
|
export type { ProcessingPanelProps } from './processing-panel';
|
|
5
5
|
export { ImportSourceForm } from './import-source-form';
|
package/dist/react.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),A=require("./upload-C2iB-crt.cjs"),T=require("./engine-routing-DV5mlLcQ.cjs");var ve={exports:{}},ce={};var Me;function tt(){if(Me)return ce;Me=1;var r=Symbol.for("react.transitional.element"),l=Symbol.for("react.fragment");function m(x,p,d){var w=null;if(d!==void 0&&(w=""+d),p.key!==void 0&&(w=""+p.key),"key"in p){d={};for(var P in p)P!=="key"&&(d[P]=p[P])}else d=p;return p=d.ref,{$$typeof:r,type:x,key:w,ref:p!==void 0?p:null,props:d}}return ce.Fragment=l,ce.jsx=m,ce.jsxs=m,ce}var de={};var Xe;function st(){return Xe||(Xe=1,process.env.NODE_ENV!=="production"&&(function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===Ne?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case $:return"Fragment";case z:return"Profiler";case I:return"StrictMode";case O:return"Suspense";case oe:return"SuspenseList";case je: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 F:return"Portal";case E:return t.displayName||"Context";case y:return(t._context.displayName||"Context")+".Consumer";case K:var o=t.render;return t=t.displayName,t||(t=o.displayName||o.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case ue:return o=t.displayName||null,o!==null?o:r(t.type)||"Memo";case ee:o=t._payload,t=t._init;try{return r(t(o))}catch{}}return null}function l(t){return""+t}function m(t){try{l(t);var o=!1}catch{o=!0}if(o){o=console;var b=o.error,j=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return b.call(o,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",j),l(t)}}function x(t){if(t===$)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===ee)return"<...>";try{var o=r(t);return o?"<"+o+">":"<...>"}catch{return"<...>"}}function p(){var t=D.A;return t===null?null:t.getOwner()}function d(){return Error("react-stack-top-frame")}function w(t){if(te.call(t,"key")){var o=Object.getOwnPropertyDescriptor(t,"key").get;if(o&&o.isReactWarning)return!1}return t.key!==void 0}function P(t,o){function b(){V||(V=!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)",o))}b.isReactWarning=!0,Object.defineProperty(t,"key",{get:b,configurable:!0})}function h(){var t=r(this.type);return ie[t]||(ie[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 R(t,o,b,j,B,G){var g=b.ref;return t={$$typeof:_,type:t,key:o,props:b,_owner:j},(g!==void 0?g: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:G}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function N(t,o,b,j,B,G){var g=o.children;if(g!==void 0)if(j)if(ye(g)){for(j=0;j<g.length;j++)C(g[j]);Object.freeze&&Object.freeze(g)}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 C(g);if(te.call(o,"key")){g=r(t);var L=Object.keys(o).filter(function(J){return J!=="key"});j=0<L.length?"{key: someKey, "+L.join(": ..., ")+": ...}":"{key: someKey}",ne[g+j]||(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} />`,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.jsx("option",{value:"slideshow",children:"Slides"})]})]})}),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;
|
|
6
|
+
<%s key={someKey} {...props} />`,j,g,L,g),ne[g+j]=!0)}if(g=null,b!==void 0&&(m(b),g=""+b),w(o)&&(m(o.key),g=""+o.key),"key"in o){b={};for(var ae in o)ae!=="key"&&(b[ae]=o[ae])}else b=o;return g&&P(b,typeof t=="function"?t.displayName||t.name||"Unknown":t),R(t,g,b,p(),B,G)}function C(t){S(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===ee&&(t._payload.status==="fulfilled"?S(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function S(t){return typeof t=="object"&&t!==null&&t.$$typeof===_}var f=i,_=Symbol.for("react.transitional.element"),F=Symbol.for("react.portal"),$=Symbol.for("react.fragment"),I=Symbol.for("react.strict_mode"),z=Symbol.for("react.profiler"),y=Symbol.for("react.consumer"),E=Symbol.for("react.context"),K=Symbol.for("react.forward_ref"),O=Symbol.for("react.suspense"),oe=Symbol.for("react.suspense_list"),ue=Symbol.for("react.memo"),ee=Symbol.for("react.lazy"),je=Symbol.for("react.activity"),Ne=Symbol.for("react.client.reference"),D=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,te=Object.prototype.hasOwnProperty,ye=Array.isArray,se=console.createTask?console.createTask:function(){return null};f={react_stack_bottom_frame:function(t){return t()}};var V,ie={},me=f.react_stack_bottom_frame.bind(f,d)(),re=se(x(d)),ne={};de.Fragment=$,de.jsx=function(t,o,b){var j=1e4>D.recentlyCreatedOwnerStacks++;return N(t,o,b,!1,j?Error("react-stack-top-frame"):me,j?se(x(t)):re)},de.jsxs=function(t,o,b){var j=1e4>D.recentlyCreatedOwnerStacks++;return N(t,o,b,!0,j?Error("react-stack-top-frame"):me,j?se(x(t)):re)}})()),de}var Ue;function rt(){return Ue||(Ue=1,process.env.NODE_ENV==="production"?ve.exports=tt():ve.exports=st()),ve.exports}var e=rt();function nt(){const[r,l]=i.useState(0),m=i.useRef(Date.now());return i.useEffect(()=>{const x=setInterval(()=>{l(Math.floor((Date.now()-m.current)/1e3))},1e3);return()=>clearInterval(x)},[]),r}function at(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function Be({message:r="Processing your file…",onCancel:l}){const m=nt();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:at(m)}),m>=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,l?e.jsx("button",{type:"button",onClick:l,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 lt={id:"builtin",label:"Built-in converter",description:"Converts LaTeX, Markdown, and PreTeXt without any other tools.",acceptExtensions:T.DEFAULT_ACCEPT_EXTENSIONS,convertFile:A.handleImportUploadFile,prepare:async r=>{const{files:l,assets:m}=await A.extractUpload(r);return{fileName:r.name,files:l,assets:m,analysis:A.analyzeImportSources(l)}},convertPrepared:(r,l)=>A.importProjectFromFiles(r.files,{...l,assets:r.assets})};function Pe(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const Ye={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function ot(r){const l=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} — ${l}`:l}function it(r){return r.candidates.filter(m=>m.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 ct({onConfirm:r,onCancel:l,importOptions:m,defaultDocumentKind:x="auto",defaultImportMode:p=T.DEFAULT_IMPORT_MODE,lockImportMode:d=!1,onImportModeChange:w,engines:P,insertTarget:h,shareConversion:R}){const N=P&&P.length>0?P:[lt],C=i.useRef(null),[S,f]=i.useState({name:"upload"}),[_,F]=i.useState(!1),[$,I]=i.useState(x),[z,y]=i.useState(null),[E,K]=i.useState(null),[O,oe]=i.useState([]),[ue,ee]=i.useState(new Set),[je,Ne]=i.useState(N[0].id),[D,te]=i.useState(null),[ye,se]=i.useState(p),[V,ie]=i.useState(!1),[me,re]=i.useState(new Set),[ne,t]=i.useState(null),[o,b]=i.useState("auto"),[j,B]=i.useState(null),[G,g]=i.useState({}),[L,ae]=i.useState(!1),J=i.useRef(!1),[Ke,xe]=i.useState({state:"idle"}),pe=i.useRef(0),H=N.find(s=>s.id===je)??N[0],Re=T.allAcceptExtensions(N),q=D?T.alternateFor(N,D.name):void 0,Ce=q?H.id===q.id:!1,he=q?Ce?T.routeEngine(N,D.name)??null:q:null,Z=S.name==="review"?S.result:null,fe=i.useMemo(()=>Z&&(z!==null||E!==null||O.length>0)?A.rebuildImport(Z,{splitLevel:z??void 0,targetTag:E??void 0,selection:O}):Z,[Z,z,E,O]),Se=i.useMemo(()=>Z?A.outlineDivisions(Z.pretextSource):[],[Z]),W=i.useMemo(()=>new Map(fe?T.fileChangesForImport(fe).map(s=>[s.path,s]):[]),[fe]),_e=i.useMemo(()=>h?{kind:"insert",targetTag:E??h.defaultTargetTag,takenIds:new Set(h.takenIds),hrefBase:h.hrefBase}:void 0,[h,E]),we=()=>({...m??{documentKind:$==="auto"?void 0:$},..._e?{destination:_e}:{},...h?.externalDir?{externalDir:h.externalDir}:{}}),Ae=()=>{pe.current+=1,xe({state:"idle"})},Ve=async(s,u)=>{if(!R||!D)return;const a=++pe.current;xe({state:"sharing"});try{await R.onShare({file:D,engineId:s.id,engineLabel:s.label,...u}),a===pe.current&&xe({state:"shared"})}catch(v){a===pe.current&&xe({state:"failed",message:v instanceof Error&&v.message?v.message:"Could not share this conversion."})}},Fe=(s,u)=>s?.experimentalNotice?e.jsx(ze,{notice:s.experimentalNotice,share:R?{offer:R,status:Ke,onShare:()=>{Ve(s,u)}}:void 0}):null,Ie=s=>A.analyzeImportSources(s.files,{sourceFormat:o==="auto"?void 0:o,mainFile:j??void 0}),Ge=s=>{J.current=!0,H.cancel?.(),f(s?{name:"sources",prepared:s}:{name:"upload"})},Je=async s=>{J.current=!1,Ae(),f({name:"processing"}),await Pe();try{const a=Ie(s).extraRoots.map(c=>({path:c.path,include:G[c.path]?.include??!0,level:G[c.path]?.level})),v=await H.convertPrepared(s,{...we(),sourceFormat:o==="auto"?void 0:o,mainFile:j??void 0,attachRoots:a});"pretextError"in v?f({name:"error",message:v.pretextError,engineId:H.id}):f({name:"review",result:v})}catch(u){if(J.current)return;f({name:"error",message:u instanceof Error?u.message:"An unexpected error occurred.",engineId:H.id})}},ke=async(s,u)=>{const a=u??T.routeEngine(N,s.name);if(!a){te(s),f({name:"error",message:T.unsupportedFileMessage(s.name,N)});return}te(s),Ne(a.id),De(),Ae(),J.current=!1,f({name:"processing"}),await Pe();try{if(a.prepare&&a.convertPrepared){const c=await a.prepare(s);if(t(c),b("auto"),B(null),g({}),it(c.analysis)){f({name:"sources",prepared:c});return}await Pe();const M=await a.convertPrepared(c,we());f("pretextError"in M?{name:"error",message:M.pretextError,engineId:a.id}:{name:"review",result:M});return}t(null);const v=await a.convertFile(s,we());"pretextError"in v?f({name:"error",message:v.pretextError,engineId:a.id}):f({name:"review",result:v})}catch(v){if(J.current)return;f({name:"error",message:v instanceof Error?v.message:"An unexpected error occurred.",engineId:a.id})}},De=()=>{se(p),ie(!1),re(new Set),ee(new Set),y(null),K(null),oe([])},Ee=()=>{f({name:"upload"}),De(),t(null),te(null)},Oe=()=>{D&&he&&ke(D,he)};function Le(s,u){return[...s].sort((a,v)=>a===u?-1:v===u?1:a.localeCompare(v))}function $e(s,u){const a=T.filesForImportMode(s,u),v=u==="converted"?s.projectLayout.mainSourcePath:s.sourcePath,c=Le(Object.keys(a),v)[0];re(c?new Set([c]):new Set)}function He(s){re(u=>{const a=new Set(u);return a.has(s)?a.delete(s):a.add(s),a})}if(S.name==="processing")return e.jsx(Be,{onCancel:H.cancel?()=>Ge(ne):void 0});if(S.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:S.message})]}),Fe(N.find(s=>s.id===S.engineId),{error:S.message}),e.jsxs("div",{className:"flex justify-end gap-2",children:[he?e.jsxs("button",{type:"button",onClick:Oe,className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:["Try ",he.label," Instead"]}):null,e.jsx("button",{type:"button",onClick:Ee,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})]})]});if(S.name==="sources"){const s=S.prepared,u=Ie(s),a=u.manifest,v=u.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:[s.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:o,onChange:c=>{b(c.currentTarget.value),B(null),g({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",u.primary?` (${Ye[u.primary.format]})`:""]}),u.formats.map(c=>e.jsx("option",{value:c,children:Ye[c]},c))]})]})}),u.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:u.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:v===c.path,onChange:()=>{B(c.path),g({})},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:ot(c)})]})]},c.path))})]}):null,u.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:u.extraRoots.map(c=>{const M=G[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:Q=>g(U=>({...U,[c.path]:{...U[c.path],include:Q.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:Q=>g(U=>({...U,[c.path]:{include:U[c.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"})]})]})]},c.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:Ee,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Je(s),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(S.name==="review"){let s=function(n){se(n),w?.(n),V&&$e(a,n)},u=function(n){ee(k=>{const le=new Set(k);return le.has(n)?le.delete(n):le.add(n),le})};const a=fe??S.result,v=a.splitLevel,c=O.length>0,M=T.hasNativeImportMode(a)&&!c,X=M?T.resolveImportMode(a,ye):"converted",Q=a.detectedSourceFormat==="markdown"?"Markdown":"LaTeX",U=a.warnings.length,Ze=Object.keys(a.outputFiles).length,Y=a.insert,be=a.destination.kind==="insert"?a.destination.targetTag:void 0,Qe=h?.targetTags??[...A.DIVISION_LADDER],Te=T.filesForImportMode(a,X),et=X==="converted"?a.projectLayout.mainSourcePath:a.sourcePath,ge=Le(Object.keys(Te),et);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:Ze}),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(n=>`${n.title} (${n.level})`).join(", ")})]}):null]})]}),Fe(H,{pretext:S.result.pretextSource}),q?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:Ce,onChange:Oe,className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Convert with ",q.label," instead"]}),e.jsx("span",{className:"block text-slate-500",children:q.description??`Runs ${a.sourceName} through ${q.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((n,k)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:n.macro})," — ",n.action==="replace"||n.action==="rewrite"?`replaced with \`${n.replacement}\``:n.message??n.action,n.occurrences>1?` (×${n.occurrences})`:null]},k))})]}):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:()=>s("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:()=>s("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,Se.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:()=>oe([]),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:O.length===0?"The whole document":`${O.length} of ${qe(Se)} divisions`})]}),e.jsx("div",{className:"mt-3 max-h-56 overflow-auto",children:e.jsx(We,{items:Se,selection:O,onToggle:n=>oe(k=>k.includes(n)?k.filter(le=>le!==n):[...k,n].sort(dt))})}),O.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.",T.hasNativeImportMode(S.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:Qe.map(n=>e.jsxs("button",{type:"button",onClick:()=>K(n),"aria-pressed":be===n,className:be===n?"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:["<",n,">"]},n))}),e.jsxs("p",{className:"mt-3 text-sm text-slate-600",children:[Y.includes.length===1?`One <${be}> is added to ${h.documentLabel}, `:`${Y.includes.length} <${be}> 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(n=>`${n.from} → ${n.to}`).join(", ")})]}):null]}):null,!m&&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:A.MAX_SUGGESTED_SPLIT_LEVEL+1},(n,k)=>e.jsx("button",{type:"button",onClick:()=>y(k),"aria-pressed":v===k,className:v===k?"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:k===0?"One file":`${k} level${k===1?"":"s"}`},k)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[ge.length," file",ge.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:ge.map(n=>e.jsxs("li",{className:"truncate py-0.5",children:[n,W.get(n)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[W.get(n).fixCount," change",W.get(n).fixCount===1?"":"s"]}):null]},n))})]}):null,V?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:ge.map(n=>{const k=me.has(n);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>He(n),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:k?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:n}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(Te[n].length/1024).toFixed(1)," KB"]})]}),k?e.jsxs("div",{className:"bg-white",children:[W.get(n)?.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:()=>u(n),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:ue.has(n)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",W.get(n).stats.added," −",W.get(n).stats.removed," in the LaTeX source"]})]}):null,ue.has(n)&&W.has(n)?e.jsx(ut,{hunks:W.get(n).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:Te[n]})]}):null]},n)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:l??Ee,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:l?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[ne?e.jsx("button",{type:"button",onClick:()=>f({name:"sources",prepared:ne}),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:()=>{V||$e(a,X),ie(n=>!n)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:V?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:L,onClick:async()=>{ae(!0);try{await r(a,X)}finally{ae(!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:[L?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"}):null,L?h?"Inserting…":"Importing…":h?"Confirm Insert":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[m?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:$,onChange:s=>I(s.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.jsx("option",{value:"slideshow",children:"Slides"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&C.current?.click(),onClick:()=>C.current?.click(),onDragOver:s=>{s.preventDefault(),F(!0)},onDragLeave:()=>F(!1),onDrop:s=>{s.preventDefault(),F(!1);const u=s.dataTransfer.files?.[0];u&&ke(u)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${_?"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:s=>{s.stopPropagation(),C.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 ",Re.join(", ")]}),e.jsx("input",{ref:C,type:"file",hidden:!0,accept:Re.join(","),onChange:s=>{const u=s.currentTarget.files?.[0];u&&ke(u),s.currentTarget.value=""}})]}),[...new Set(T.experimentalEngines(N).map(s=>s.experimentalNotice))].map(s=>e.jsx(ze,{notice:s},s))]})}function ze({notice:r,share:l}){return e.jsxs("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-800","data-testid":"experimental-notice",children:[e.jsx("p",{children:r}),l?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[l.offer.description?e.jsx("p",{className:"text-amber-700",children:l.offer.description}):null,l.status.state==="shared"?e.jsx("p",{role:"status",className:"font-medium",children:"Shared. Thank you!"}):e.jsx("button",{type:"button",onClick:l.onShare,disabled:l.status.state==="sharing",className:"rounded border border-amber-200 px-3 py-1.5 font-medium text-amber-800 hover:bg-amber-100 disabled:opacity-60",children:l.status.state==="sharing"?"Sharing…":l.offer.label??"Share this conversion"}),l.status.state==="failed"?e.jsxs("p",{role:"alert",className:"text-red-800",children:["Could not share: ",l.status.message]}):null]}):null]})}function qe(r){return r.reduce((l,m)=>l+1+qe(m.children),0)}function dt(r,l){const m=r.split(".").map(Number),x=l.split(".").map(Number);for(let p=0;p<Math.max(m.length,x.length);p++){const d=(m[p]??-1)-(x[p]??-1);if(d!==0)return d}return 0}function We({items:r,selection:l,onToggle:m}){return e.jsx("ul",{className:"space-y-0.5 text-sm",children:r.map(x=>{const p=l.includes(x.path),d=l.some(w=>x.path.startsWith(`${w}.`));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:()=>m(x.path)}),e.jsxs("span",{className:d?"text-slate-400":"text-slate-700",children:[x.title||e.jsx("em",{children:"Untitled"}),e.jsxs("span",{className:"ml-2 font-mono text-xs text-slate-400",children:["<",x.tag,">"]})]})]}),x.children.length>0?e.jsx("div",{className:"ml-5 border-l border-slate-200 pl-3",children:e.jsx(We,{items:x.children,selection:l,onToggle:m})}):null]},x.path)})})}function ut({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((l,m)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[m>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,l.lines.map((x,p)=>e.jsxs("div",{className:x.op==="add"?"bg-green-50 px-4 text-green-900":x.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:x.op==="add"?"+":x.op==="remove"?"−":" "}),x.text||" "]},p))]},m))})}const mt={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 xt({initialSource:r="",initialSourceFormat:l,labels:m,disabled:x=!1,onImport:p}){const d=i.useMemo(()=>({...mt,...m??{}}),[m]),[w,P]=i.useState(r),[h,R]=i.useState(l??"auto"),[N,C]=i.useState(null),S=i.useMemo(()=>A.detectSourceFormat(w),[w]),f=x||!w.trim();return e.jsx("form",{onSubmit:_=>{_.preventDefault();const F=A.convertSourceToPretext(w,h==="auto"?void 0:h);C(F),p(F)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:x,children:[e.jsx("legend",{children:d.title}),e.jsx("p",{children:d.description}),e.jsxs("label",{children:[d.sourceLabel,e.jsx("textarea",{value:w,onChange:_=>P(_.currentTarget.value),placeholder:d.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[d.formatLabel,e.jsxs("select",{value:h,onChange:_=>R(_.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:S})]}),e.jsx("button",{type:"submit",disabled:f,children:d.convertButton}),N?"pretextError"in N?e.jsxs("p",{role:"alert",children:[d.errorPrefix,": ",N.pretextError]}):e.jsxs("p",{children:[d.successPrefix,": ",N.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const pt={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 ht({labels:r,disabled:l=!1,defaultDocumentKind:m="auto",importOptions:x,onImport:p}){const d=i.useMemo(()=>({...pt,...r??{}}),[r]),w=i.useRef(null),[P,h]=i.useState(!1),[R,N]=i.useState(!1),[C,S]=i.useState([]),[f,_]=i.useState(m),[F,$]=i.useState(!1),I=l||R,z=async y=>{N(!0);try{const E=x??{documentKind:f==="auto"?void 0:f,splitSections:F},K=await A.handleImportUploadFile(y,E);S(K.statusMessages),p(K)}finally{N(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:d.title}),e.jsx("p",{children:d.hint}),x?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[d.documentKindLabel,e.jsxs("select",{value:f,disabled:I,onChange:y=>_(y.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:F,disabled:I,onChange:y=>$(y.currentTarget.checked)}),d.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:y=>{y.preventDefault(),I||h(!0)},onDragLeave:()=>h(!1),onDrop:y=>{if(y.preventDefault(),h(!1),I)return;const E=y.dataTransfer.files?.[0];E&&z(E)},children:[e.jsx("p",{children:d.dropHint}),e.jsxs("button",{type:"button",disabled:I,onClick:()=>w.current?.click(),className:"inline-flex items-center gap-2",children:[R?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,R?"Processing…":d.selectButton]}),e.jsx("input",{ref:w,type:"file",hidden:!0,disabled:I,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:y=>{const E=y.currentTarget.files?.[0];E&&z(E),y.currentTarget.value=""}})]}),R?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,C.length>0?e.jsx("ul",{"aria-live":"polite",children:C.map((y,E)=>e.jsx("li",{children:y.message},`${y.type}-${E}`))}):null,P&&!I?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=xt;exports.ImportUploadPanel=ht;exports.ImportWizard=ct;exports.ProcessingPanel=Be;
|