@pretextbook/import 0.0.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 +121 -0
- package/dist/import-mode-CSZlmUxw.cjs +66 -0
- package/dist/import-mode-iBDd9oQY.js +3862 -0
- package/dist/import.css +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +164 -0
- package/dist/lib/clean/clean-latex.d.ts +6 -0
- package/dist/lib/clean/latex-clean.d.ts +10 -0
- package/dist/lib/clean/latex-data.d.ts +38 -0
- package/dist/lib/clean/latex-preamble.d.ts +27 -0
- package/dist/lib/clean/latex-scan.d.ts +11 -0
- package/dist/lib/clean/latex-utils.d.ts +4 -0
- package/dist/lib/clean/pretext-includes.d.ts +7 -0
- package/dist/lib/clean/warnings.d.ts +13 -0
- package/dist/lib/convert.d.ts +16 -0
- package/dist/lib/detect-source-format.d.ts +4 -0
- package/dist/lib/import-mode.d.ts +13 -0
- package/dist/lib/layout/build-project-files.d.ts +17 -0
- package/dist/lib/layout/document-kind.d.ts +2 -0
- package/dist/lib/layout/index.d.ts +4 -0
- package/dist/lib/layout/shared.d.ts +12 -0
- package/dist/lib/layout/templates.d.ts +8 -0
- package/dist/lib/layout/xml-scan.d.ts +13 -0
- package/dist/lib/pool/division-pool.d.ts +34 -0
- package/dist/lib/pool/index.d.ts +3 -0
- package/dist/lib/pool/serialize-files.d.ts +19 -0
- package/dist/lib/pool/serialize-plus.d.ts +10 -0
- package/dist/lib/types.d.ts +124 -0
- package/dist/lib/upload.d.ts +10 -0
- package/dist/react/import-source-form.d.ts +20 -0
- package/dist/react/import-upload-panel.d.ts +21 -0
- package/dist/react/import-wizard.d.ts +15 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react.cjs +6 -0
- package/dist/react.js +735 -0
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BuildProjectFilesOptions } from './layout';
|
|
2
|
+
import { ImportedProjectResult } from './types';
|
|
3
|
+
export interface ImportProjectOptions extends BuildProjectFilesOptions {
|
|
4
|
+
/** When true (default), the layout splitter runs and outputFiles is populated. */
|
|
5
|
+
buildLayout?: boolean;
|
|
6
|
+
/** Raw binary assets keyed by their source path (e.g. images, PDFs). */
|
|
7
|
+
assets?: Record<string, Uint8Array>;
|
|
8
|
+
}
|
|
9
|
+
export declare function importProjectFromFiles(files: Record<string, string>, options?: ImportProjectOptions): ImportedProjectResult;
|
|
10
|
+
export declare function handleImportUploadFile(file: File, options?: ImportProjectOptions): Promise<ImportedProjectResult>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConvertedPretextResult, SourceFormat } from '../lib/types';
|
|
2
|
+
export interface ImportSourceFormLabels {
|
|
3
|
+
title?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
sourceLabel?: string;
|
|
6
|
+
sourcePlaceholder?: string;
|
|
7
|
+
formatLabel?: string;
|
|
8
|
+
convertButton?: string;
|
|
9
|
+
detectedFormatPrefix?: string;
|
|
10
|
+
successPrefix?: string;
|
|
11
|
+
errorPrefix?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ImportSourceFormProps {
|
|
14
|
+
initialSource?: string;
|
|
15
|
+
initialSourceFormat?: SourceFormat;
|
|
16
|
+
labels?: ImportSourceFormLabels;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
onImport: (result: ConvertedPretextResult) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare function ImportSourceForm({ initialSource, initialSourceFormat, labels, disabled, onImport, }: ImportSourceFormProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ImportProjectOptions } from '../lib/upload';
|
|
2
|
+
import { DocumentKind } from '../lib/layout/document-kind';
|
|
3
|
+
import { ImportedProjectResult } from '../lib/types';
|
|
4
|
+
export interface ImportUploadPanelLabels {
|
|
5
|
+
title?: string;
|
|
6
|
+
hint?: string;
|
|
7
|
+
selectButton?: string;
|
|
8
|
+
dropHint?: string;
|
|
9
|
+
documentKindLabel?: string;
|
|
10
|
+
splitSectionsLabel?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ImportUploadPanelProps {
|
|
13
|
+
labels?: ImportUploadPanelLabels;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** Default document-kind option presented to the user; user can override. */
|
|
16
|
+
defaultDocumentKind?: DocumentKind | "auto";
|
|
17
|
+
/** When provided, takes precedence — UI controls hidden. */
|
|
18
|
+
importOptions?: ImportProjectOptions;
|
|
19
|
+
onImport: (result: ImportedProjectResult) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare function ImportUploadPanel({ labels, disabled, defaultDocumentKind, importOptions, onImport, }: ImportUploadPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ImportProjectOptions } from '../lib/upload';
|
|
2
|
+
import { ImportMode } from '../lib/import-mode';
|
|
3
|
+
import { DocumentKind } from '../lib/layout/document-kind';
|
|
4
|
+
import { ImportedProjectSuccess } from '../lib/types';
|
|
5
|
+
export type { ImportMode };
|
|
6
|
+
export interface ImportWizardProps {
|
|
7
|
+
/** Called when the user confirms the import. */
|
|
8
|
+
onConfirm: (result: ImportedProjectSuccess, mode: ImportMode) => void;
|
|
9
|
+
/** Called when the user cancels at the review step. */
|
|
10
|
+
onCancel?: () => void;
|
|
11
|
+
/** Pass fixed options to skip the document-kind / split-sections controls. */
|
|
12
|
+
importOptions?: ImportProjectOptions;
|
|
13
|
+
defaultDocumentKind?: DocumentKind | "auto";
|
|
14
|
+
}
|
|
15
|
+
export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, }: ImportWizardProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ImportWizard } from './import-wizard';
|
|
2
|
+
export type { ImportWizardProps, ImportMode } from './import-wizard';
|
|
3
|
+
export { ImportSourceForm } from './import-source-form';
|
|
4
|
+
export { ImportUploadPanel } from './import-upload-panel';
|
|
5
|
+
export type { ImportSourceFormProps, ImportSourceFormLabels, } from './import-source-form';
|
|
6
|
+
export type { ImportUploadPanelProps, ImportUploadPanelLabels, } from './import-upload-panel';
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),M=require("./import-mode-CSZlmUxw.cjs");var W={exports:{}},$={};var Z;function re(){if(Z)return $;Z=1;var h=Symbol.for("react.transitional.element"),E=Symbol.for("react.fragment");function v(g,u,n){var d=null;if(n!==void 0&&(d=""+n),u.key!==void 0&&(d=""+u.key),"key"in u){n={};for(var T in u)T!=="key"&&(n[T]=u[T])}else n=u;return u=n.ref,{$$typeof:h,type:g,key:d,ref:u!==void 0?u:null,props:n}}return $.Fragment=E,$.jsx=v,$.jsxs=v,$}var Y={};var Q;function se(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&(function(){function h(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===P?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case A:return"Fragment";case C:return"Profiler";case y:return"StrictMode";case U:return"Suspense";case B:return"SuspenseList";case p: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 k:return"Portal";case b:return t.displayName||"Context";case c:return(t._context.displayName||"Context")+".Consumer";case F:var r=t.render;return t=t.displayName,t||(t=r.displayName||r.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case a:return r=t.displayName||null,r!==null?r:h(t.type)||"Memo";case s:r=t._payload,t=t._init;try{return h(t(r))}catch{}}return null}function E(t){return""+t}function v(t){try{E(t);var r=!1}catch{r=!0}if(r){r=console;var l=r.error,m=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return l.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",m),E(t)}}function g(t){if(t===A)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===s)return"<...>";try{var r=h(t);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function u(){var t=O.A;return t===null?null:t.getOwner()}function n(){return Error("react-stack-top-frame")}function d(t){if(I.call(t,"key")){var r=Object.getOwnPropertyDescriptor(t,"key").get;if(r&&r.isReactWarning)return!1}return t.key!==void 0}function T(t,r){function l(){o||(o=!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)",r))}l.isReactWarning=!0,Object.defineProperty(t,"key",{get:l,configurable:!0})}function j(){var t=h(this.type);return D[t]||(D[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 _(t,r,l,m,X,K){var x=l.ref;return t={$$typeof:S,type:t,key:r,props:l,_owner:m},(x!==void 0?x:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:j}):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:X}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:K}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function N(t,r,l,m,X,K){var x=r.children;if(x!==void 0)if(m)if(q(x)){for(m=0;m<x.length;m++)R(x[m]);Object.freeze&&Object.freeze(x)}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 R(x);if(I.call(r,"key")){x=h(t);var L=Object.keys(r).filter(function(te){return te!=="key"});m=0<L.length?"{key: someKey, "+L.join(": ..., ")+": ...}":"{key: someKey}",H[x+m]||(L=0<L.length?"{"+L.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,m,x,L,x),H[x+m]=!0)}if(x=null,l!==void 0&&(v(l),x=""+l),d(r)&&(v(r.key),x=""+r.key),"key"in r){l={};for(var J in r)J!=="key"&&(l[J]=r[J])}else l=r;return x&&T(l,typeof t=="function"?t.displayName||t.name||"Unknown":t),_(t,x,l,u(),X,K)}function R(t){w(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===s&&(t._payload.status==="fulfilled"?w(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function w(t){return typeof t=="object"&&t!==null&&t.$$typeof===S}var f=i,S=Symbol.for("react.transitional.element"),k=Symbol.for("react.portal"),A=Symbol.for("react.fragment"),y=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),b=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),U=Symbol.for("react.suspense"),B=Symbol.for("react.suspense_list"),a=Symbol.for("react.memo"),s=Symbol.for("react.lazy"),p=Symbol.for("react.activity"),P=Symbol.for("react.client.reference"),O=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=Object.prototype.hasOwnProperty,q=Array.isArray,z=console.createTask?console.createTask:function(){return null};f={react_stack_bottom_frame:function(t){return t()}};var o,D={},V=f.react_stack_bottom_frame.bind(f,n)(),G=z(g(n)),H={};Y.Fragment=A,Y.jsx=function(t,r,l){var m=1e4>O.recentlyCreatedOwnerStacks++;return N(t,r,l,!1,m?Error("react-stack-top-frame"):V,m?z(g(t)):G)},Y.jsxs=function(t,r,l){var m=1e4>O.recentlyCreatedOwnerStacks++;return N(t,r,l,!0,m?Error("react-stack-top-frame"):V,m?z(g(t)):G)}})()),Y}var ee;function ne(){return ee||(ee=1,process.env.NODE_ENV==="production"?W.exports=re():W.exports=se()),W.exports}var e=ne();function ae({onConfirm:h,onCancel:E,importOptions:v,defaultDocumentKind:g="auto"}){const u=i.useRef(null),[n,d]=i.useState({name:"upload"}),[T,j]=i.useState(!1),[_,N]=i.useState(g),[R,w]=i.useState(!1),[f,S]=i.useState("converted"),[k,A]=i.useState(!1),[y,C]=i.useState(new Set),c=async a=>{d({name:"processing"});try{const s=v??{documentKind:_==="auto"?void 0:_,splitSections:R},p=await M.handleImportUploadFile(a,s);"pretextError"in p?d({name:"error",message:p.pretextError}):d({name:"review",result:p})}catch(s){d({name:"error",message:s instanceof Error?s.message:"An unexpected error occurred."})}},b=()=>{d({name:"upload"}),S("converted"),A(!1),C(new Set)};function F(a,s){return[...a].sort((p,P)=>p===s?-1:P===s?1:p.localeCompare(P))}function U(a,s){const p=M.filesForImportMode(a,s),P=s==="converted"?"source/main.ptx":a.sourcePath,O=F(Object.keys(p),P)[0];C(O?new Set([O]):new Set)}function B(a){C(s=>{const p=new Set(s);return p.has(a)?p.delete(a):p.add(a),p})}if(n.name==="processing")return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16 text-slate-600",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:"Processing your file…"})]});if(n.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:n.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:b,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(n.name==="review"){let a=function(o){S(o),k&&U(s,o)};const{result:s}=n,p=s.detectedSourceFormat==="latex",P=s.warnings.length,O=Object.keys(s.outputFiles).length,I=M.filesForImportMode(s,f),q=f==="converted"?"source/main.ptx":s.sourcePath,z=F(Object.keys(I),q);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:s.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:s.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:s.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:O})]})]}),P>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:[P," conversion ",P===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:s.warnings.map((o,D)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:o.macro})," — ",o.action==="replace"||o.action==="rewrite"?`replaced with \`${o.replacement}\``:o.message??o.action,o.occurrences>1?` (×${o.occurrences})`:null]},D))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),p?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:f==="converted",onChange:()=>a("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:f==="native",onChange:()=>a("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Keep as LaTeX"}),e.jsx("span",{className:"block text-slate-500",children:"Preserve the original LaTeX source. The conversion will not be applied."})]})]})]})]}):null,k?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:z.map(o=>{const D=y.has(o);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>B(o),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:D?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:o}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(I[o].length/1024).toFixed(1)," KB"]})]}),D?e.jsx("pre",{className:"m-0 max-h-72 overflow-auto bg-white p-4 font-mono text-xs leading-relaxed text-slate-800",children:I[o]}):null]},o)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:E??b,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:E?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{k||U(s,f),A(o=>!o)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:k?"Hide Preview":"Preview"}),e.jsx("button",{type:"button",onClick:()=>h(s,f),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Confirm Import"})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[v?null:e.jsxs("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:a=>N(a.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("label",{className:"flex items-center gap-2 text-sm text-slate-700",children:[e.jsx("input",{type:"checkbox",checked:R,onChange:a=>w(a.currentTarget.checked)}),"Split sections into separate files"]})]}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:a=>a.key==="Enter"&&u.current?.click(),onClick:()=>u.current?.click(),onDragOver:a=>{a.preventDefault(),j(!0)},onDragLeave:()=>j(!1),onDrop:a=>{a.preventDefault(),j(!1);const s=a.dataTransfer.files?.[0];s&&c(s)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${T?"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:a=>{a.stopPropagation(),u.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.jsx("p",{className:"text-xs text-slate-400",children:"Supports .tex, .md, .ptx, .xml, .zip, .tar.gz"}),e.jsx("input",{ref:u,type:"file",hidden:!0,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:a=>{const s=a.currentTarget.files?.[0];s&&c(s),a.currentTarget.value=""}})]})]})}const oe={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 le({initialSource:h="",initialSourceFormat:E,labels:v,disabled:g=!1,onImport:u}){const n=i.useMemo(()=>({...oe,...v??{}}),[v]),[d,T]=i.useState(h),[j,_]=i.useState(E??"auto"),[N,R]=i.useState(null),w=i.useMemo(()=>M.detectSourceFormat(d),[d]),f=g||!d.trim();return e.jsx("form",{onSubmit:S=>{S.preventDefault();const k=M.convertSourceToPretext(d,j==="auto"?void 0:j);R(k),u(k)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:g,children:[e.jsx("legend",{children:n.title}),e.jsx("p",{children:n.description}),e.jsxs("label",{children:[n.sourceLabel,e.jsx("textarea",{value:d,onChange:S=>T(S.currentTarget.value),placeholder:n.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[n.formatLabel,e.jsxs("select",{value:j,onChange:S=>_(S.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:[n.detectedFormatPrefix,": ",e.jsx("strong",{children:w})]}),e.jsx("button",{type:"submit",disabled:f,children:n.convertButton}),N?"pretextError"in N?e.jsxs("p",{role:"alert",children:[n.errorPrefix,": ",N.pretextError]}):e.jsxs("p",{children:[n.successPrefix,": ",N.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const ce={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 ie({labels:h,disabled:E=!1,defaultDocumentKind:v="auto",importOptions:g,onImport:u}){const n=i.useMemo(()=>({...ce,...h??{}}),[h]),d=i.useRef(null),[T,j]=i.useState(!1),[_,N]=i.useState(!1),[R,w]=i.useState([]),[f,S]=i.useState(v),[k,A]=i.useState(!1),y=E||_,C=async c=>{N(!0);try{const b=g??{documentKind:f==="auto"?void 0:f,splitSections:k},F=await M.handleImportUploadFile(c,b);w(F.statusMessages),u(F)}finally{N(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:n.title}),e.jsx("p",{children:n.hint}),g?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[n.documentKindLabel,e.jsxs("select",{value:f,disabled:y,onChange:c=>S(c.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:k,disabled:y,onChange:c=>A(c.currentTarget.checked)}),n.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:c=>{c.preventDefault(),y||j(!0)},onDragLeave:()=>j(!1),onDrop:c=>{if(c.preventDefault(),j(!1),y)return;const b=c.dataTransfer.files?.[0];b&&C(b)},children:[e.jsx("p",{children:n.dropHint}),e.jsx("button",{type:"button",disabled:y,onClick:()=>d.current?.click(),children:_?"Processing...":n.selectButton}),e.jsx("input",{ref:d,type:"file",hidden:!0,disabled:y,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:c=>{const b=c.currentTarget.files?.[0];b&&C(b),c.currentTarget.value=""}})]}),R.length>0?e.jsx("ul",{"aria-live":"polite",children:R.map((c,b)=>e.jsx("li",{children:c.message},`${c.type}-${b}`))}):null,T&&!y?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=le;exports.ImportUploadPanel=ie;exports.ImportWizard=ae;
|