@pretextbook/import 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/convert-worker.cjs +1 -1
- package/dist/convert-worker.js +1 -1
- package/dist/{import-mode-DuPFMu97.cjs → import-mode-CV7gCDzF.cjs} +1 -1
- package/dist/{import-mode-BaaBvzcy.js → import-mode-DQ8g5P8P.js} +1 -1
- package/dist/import.css +1 -1
- package/dist/index.cjs +5 -3
- package/dist/index.d.ts +10 -5
- package/dist/index.js +562 -219
- package/dist/lib/assets/images.d.ts +49 -0
- package/dist/lib/detect-snippet-format.d.ts +32 -0
- package/dist/lib/insert/dedupe-ids.d.ts +36 -0
- package/dist/lib/insert/destination.d.ts +21 -0
- package/dist/lib/insert/index.d.ts +4 -0
- package/dist/lib/insert/prepare.d.ts +44 -0
- package/dist/lib/insert/retarget.d.ts +35 -0
- package/dist/lib/layout/xml-scan.d.ts +28 -0
- package/dist/lib/pandoc/formats.d.ts +40 -0
- package/dist/lib/pandoc/index.d.ts +3 -0
- package/dist/lib/pandoc/pandoc-engine.d.ts +24 -0
- package/dist/lib/pandoc/remote-pandoc.d.ts +74 -0
- package/dist/lib/paste/place-markup.d.ts +41 -0
- package/dist/lib/pool/division-pool.d.ts +5 -0
- package/dist/lib/pool/index.d.ts +5 -1
- package/dist/lib/pool/place-divisions.d.ts +25 -0
- package/dist/lib/pool/placeholders.d.ts +4 -0
- package/dist/lib/pool/refs.d.ts +8 -0
- package/dist/lib/pool/serialize-destination.d.ts +24 -0
- package/dist/lib/pool/serialize-files.d.ts +1 -2
- package/dist/lib/pool/serialize-insert-records.d.ts +22 -0
- package/dist/lib/pool/serialize-insert.d.ts +44 -0
- package/dist/lib/pool/serialize-plus.d.ts +4 -4
- package/dist/lib/pool/serialize-records.d.ts +11 -0
- package/dist/lib/pretext-divisions.d.ts +25 -0
- package/dist/lib/select/divisions.d.ts +44 -0
- package/dist/lib/types.d.ts +82 -2
- package/dist/lib/upload.d.ts +56 -4
- package/dist/react/import-wizard.d.ts +30 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react.cjs +2 -2
- package/dist/react.js +658 -511
- package/dist/upload-BnRj1gU1.cjs +135 -0
- package/dist/upload-H_OCZBBn.js +7648 -0
- package/package.json +5 -5
- package/dist/upload-BmErkg8I.js +0 -7140
- package/dist/upload-BtS22hIH.cjs +0 -135
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AssetRecord, DivisionRecord, ImportedAsset, ImportedProject, ProjectRecords } from '../types';
|
|
2
|
+
export declare function guessContentType(fileName: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Base64-encode bytes without `btoa`/`Buffer`, so it runs identically in the
|
|
5
|
+
* browser and the VS Code extension host.
|
|
6
|
+
*/
|
|
7
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
8
|
+
export declare function assetToRecord(asset: ImportedAsset): AssetRecord;
|
|
9
|
+
export declare function divisionToRecord(division: ImportedProject["divisions"][number]): DivisionRecord;
|
|
10
|
+
/** Serialize the whole division pool as records. */
|
|
11
|
+
export declare function serializeProjectToRecords(project: ImportedProject): ProjectRecords;
|
|
@@ -7,3 +7,28 @@ export type PretextDivisionTag = (typeof PRETEXT_DIVISION_TAGS)[number];
|
|
|
7
7
|
export declare function isDivisionTag(name: string): name is PretextDivisionTag;
|
|
8
8
|
export declare function filePrefixForDivision(type: string): string;
|
|
9
9
|
export declare function isSingletonDivision(type: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The depth-indexed divisions, outermost first (SPEC §9.3). Retargeting an
|
|
12
|
+
* imported fragment onto a chosen level shifts tags along this ladder. Every
|
|
13
|
+
* other division tag names a *role* rather than a depth — an `<exercises>` is
|
|
14
|
+
* an exercises wherever it sits — so retargeting leaves them alone.
|
|
15
|
+
*
|
|
16
|
+
* Matches `LATEX_DIVISION_COMMANDS` (latex-split.ts) rung for rung, since the
|
|
17
|
+
* LaTeX sectioning commands are where most imported hierarchies come from.
|
|
18
|
+
*/
|
|
19
|
+
export declare const DIVISION_LADDER: readonly ["part", "chapter", "section", "subsection", "subsubsection"];
|
|
20
|
+
export type LadderTag = (typeof DIVISION_LADDER)[number];
|
|
21
|
+
/**
|
|
22
|
+
* Where content pushed past the bottom of the ladder lands. `<paragraphs>` is
|
|
23
|
+
* deliberately absent from `PRETEXT_DIVISION_TAGS`, so overflow stays inline
|
|
24
|
+
* and can never be split into a file of its own — the overflow rule and the
|
|
25
|
+
* splitter agree without either referring to the other (SPEC §9.3).
|
|
26
|
+
*/
|
|
27
|
+
export declare const LADDER_OVERFLOW_TAG = "paragraphs";
|
|
28
|
+
/** Rung index of a tag on the ladder, or `-1` when it is off the ladder. */
|
|
29
|
+
export declare function ladderDepth(name: string): number;
|
|
30
|
+
/**
|
|
31
|
+
* Shift a tag `delta` rungs down the ladder. Off-ladder tags pass through
|
|
32
|
+
* untouched; anything pushed past the last rung becomes `<paragraphs>`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function shiftLadderTag(name: string, delta: number): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A division's address within a document: its index among its siblings, joined
|
|
3
|
+
* by dots (`"2"`, `"2.0"`).
|
|
4
|
+
*
|
|
5
|
+
* Positional rather than by `xml:id` because most converted documents have no
|
|
6
|
+
* ids yet — the pool mints them downstream — and an address that only works for
|
|
7
|
+
* documents that were already well-labelled would be no use on exactly the
|
|
8
|
+
* imports that need it. Stable for a given source, which is all a selection has
|
|
9
|
+
* to outlive.
|
|
10
|
+
*/
|
|
11
|
+
export type DivisionPath = string;
|
|
12
|
+
export interface DivisionOutlineItem {
|
|
13
|
+
path: DivisionPath;
|
|
14
|
+
/** Element name (`section`, `exercises`, …). */
|
|
15
|
+
tag: string;
|
|
16
|
+
/** The division's own `<title>`, or `""`. */
|
|
17
|
+
title: string;
|
|
18
|
+
/** Its `xml:id`, when the source already carried one. */
|
|
19
|
+
xmlId?: string;
|
|
20
|
+
children: DivisionOutlineItem[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The document's divisions as a tree, addressed by `DivisionPath` — what a host
|
|
24
|
+
* renders its picker from.
|
|
25
|
+
*/
|
|
26
|
+
export declare function outlineDivisions(pretextSource: string): DivisionOutlineItem[];
|
|
27
|
+
export interface PruneDivisionsResult {
|
|
28
|
+
source: string;
|
|
29
|
+
/** Paths of the divisions removed, in document order. */
|
|
30
|
+
removed: DivisionPath[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Remove every division the selection does not reach.
|
|
34
|
+
*
|
|
35
|
+
* A selected division comes whole — its own subdivisions travel with it — and
|
|
36
|
+
* the divisions containing it are kept as the structure it hangs from. Content
|
|
37
|
+
* that belongs to a kept division but to none of its subdivisions (a chapter's
|
|
38
|
+
* introductory prose, say) stays: it is the parent's own, and dropping it would
|
|
39
|
+
* lose material the author never deselected.
|
|
40
|
+
*
|
|
41
|
+
* An empty or absent selection expresses no narrowing, so nothing is pruned —
|
|
42
|
+
* a host that wants "import nothing" should not run an import.
|
|
43
|
+
*/
|
|
44
|
+
export declare function pruneDivisions(pretextSource: string, selection: readonly DivisionPath[] | undefined): PruneDivisionsResult;
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { CleanedChunk } from './clean/clean-chunks';
|
|
2
|
+
import { ImportDestination } from './insert/destination';
|
|
3
|
+
import { XmlIdRename } from './insert/dedupe-ids';
|
|
4
|
+
import { DivisionPath } from './select/divisions';
|
|
2
5
|
import { CleaningWarning } from './clean/warnings';
|
|
3
6
|
import { DocumentKind } from './layout/document-kind';
|
|
4
7
|
import { PretextDivisionTag, PretextRootTag } from './pretext-divisions';
|
|
@@ -64,8 +67,9 @@ export interface ImportedAsset {
|
|
|
64
67
|
}
|
|
65
68
|
/**
|
|
66
69
|
* The host-independent intermediate model of an imported project
|
|
67
|
-
* (SPEC §4.1). Serialize with `serializeProjectToFiles` (
|
|
68
|
-
*
|
|
70
|
+
* (SPEC §4.1). Serialize with `serializeProjectToFiles` (a file tree) or
|
|
71
|
+
* `serializeProjectToRecords` (a flat, ref-addressed projection for a host that
|
|
72
|
+
* stores divisions rather than files).
|
|
69
73
|
*/
|
|
70
74
|
export interface ImportedProject {
|
|
71
75
|
title: string;
|
|
@@ -76,6 +80,40 @@ export interface ImportedProject {
|
|
|
76
80
|
divisions: ImportedDivision[];
|
|
77
81
|
assets: ImportedAsset[];
|
|
78
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* One division of the flat, ref-addressed projection (SPEC §4.3) — the shape a
|
|
85
|
+
* host that stores divisions in a database wants, as against the file tree
|
|
86
|
+
* `serializeProjectToFiles` produces. Hierarchy lives in the `<plus:TYPE
|
|
87
|
+
* ref="…"/>` placeholders inside `source`, not in the record.
|
|
88
|
+
*/
|
|
89
|
+
export interface DivisionRecord {
|
|
90
|
+
/** The division's `xml:id`. */
|
|
91
|
+
ref: string;
|
|
92
|
+
source: string;
|
|
93
|
+
sourceFormat: SourceFormat;
|
|
94
|
+
isRoot: boolean;
|
|
95
|
+
}
|
|
96
|
+
/** One asset of the record projection, its bytes base64-encoded. */
|
|
97
|
+
export interface AssetRecord {
|
|
98
|
+
ref: string;
|
|
99
|
+
fileName: string;
|
|
100
|
+
contentType: string;
|
|
101
|
+
/** Base64-encoded bytes, so the projection travels as JSON. */
|
|
102
|
+
data: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The record projection of an imported project (SPEC §4.3). Consumer-neutral:
|
|
106
|
+
* `recordsToPlusPayload` renames these fields for pretext-plus's endpoint, and
|
|
107
|
+
* another hosted consumer would write its own adapter rather than inherit
|
|
108
|
+
* someone else's field names.
|
|
109
|
+
*/
|
|
110
|
+
export interface ProjectRecords {
|
|
111
|
+
title: string;
|
|
112
|
+
docinfo: string;
|
|
113
|
+
documentKind: DocumentKind;
|
|
114
|
+
divisions: DivisionRecord[];
|
|
115
|
+
assets: AssetRecord[];
|
|
116
|
+
}
|
|
79
117
|
/**
|
|
80
118
|
* One division row of the pretext-plus import payload (`divisions_attributes`
|
|
81
119
|
* on `POST /projects/import`). New rows only — `ProjectsController#import_params`
|
|
@@ -134,6 +172,27 @@ export interface ProjectLayout {
|
|
|
134
172
|
/** True when an existing project's layout and publication file were kept. */
|
|
135
173
|
preserved: boolean;
|
|
136
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* What an `insert` destination did to the document on its way into the host
|
|
177
|
+
* project (SPEC §9.2). Absent for a new-project import.
|
|
178
|
+
*/
|
|
179
|
+
export interface InsertRecord {
|
|
180
|
+
/** True when the document wrapper was dropped in favour of its children. */
|
|
181
|
+
unwrapRoot: boolean;
|
|
182
|
+
/** `<xi:include>` elements for the host to splice in at the cursor. */
|
|
183
|
+
includes: string[];
|
|
184
|
+
/** `xml:id`s renamed because the host project already used them. */
|
|
185
|
+
renamed: XmlIdRename[];
|
|
186
|
+
/** Rungs the document's divisions were shifted down the ladder. */
|
|
187
|
+
retargetDelta: number;
|
|
188
|
+
/**
|
|
189
|
+
* `pretextSource` after retargeting and de-colliding — what was actually
|
|
190
|
+
* split and written. `pretextSource` itself stays the raw conversion, so the
|
|
191
|
+
* attach level can be changed later without re-converting (and without
|
|
192
|
+
* shifting an already-shifted document a second time).
|
|
193
|
+
*/
|
|
194
|
+
preparedSource: string;
|
|
195
|
+
}
|
|
137
196
|
export interface ImportedProjectSuccess extends ConversionContext {
|
|
138
197
|
pretextSource: string;
|
|
139
198
|
/** Cleaned but unconverted source, when the input was LaTeX or Markdown. */
|
|
@@ -177,6 +236,27 @@ export interface ImportedProjectSuccess extends ConversionContext {
|
|
|
177
236
|
cleanChunks: CleanedChunk[];
|
|
178
237
|
/** The split depth this result was laid out at. */
|
|
179
238
|
splitLevel: number;
|
|
239
|
+
/**
|
|
240
|
+
* Which divisions this import kept, by `DivisionPath` (SPEC §9, step 6).
|
|
241
|
+
* Absent when the whole document was imported.
|
|
242
|
+
*/
|
|
243
|
+
selection?: DivisionPath[];
|
|
244
|
+
/**
|
|
245
|
+
* Warnings from the stages a rebuild redoes — the selection prune and the
|
|
246
|
+
* insert preparation. Also present in `warnings`; held separately so
|
|
247
|
+
* `rebuildImport` can replace exactly these rather than accumulate a set per
|
|
248
|
+
* attempt, since an author trying three attach levels should be left with one
|
|
249
|
+
* overflow notice, not three.
|
|
250
|
+
*/
|
|
251
|
+
rebuiltWarnings: CleaningWarning[];
|
|
252
|
+
/**
|
|
253
|
+
* Where this import went. Carried on the result so `relayoutImport` cannot
|
|
254
|
+
* silently regenerate a project scaffold the moment an author changes the
|
|
255
|
+
* split level during an insertion (SPEC §9.2).
|
|
256
|
+
*/
|
|
257
|
+
destination: ImportDestination;
|
|
258
|
+
/** Present only for an `insert` destination. */
|
|
259
|
+
insert?: InsertRecord;
|
|
180
260
|
statusMessages: UploadStatusMessage[];
|
|
181
261
|
warnings: CleaningWarning[];
|
|
182
262
|
}
|
package/dist/lib/upload.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { BuildProjectFilesOptions } from './layout';
|
|
2
|
+
import { ImportDestination } from './insert/destination';
|
|
2
3
|
import { RootAttachment } from './project/attach-roots';
|
|
4
|
+
import { PretextDivisionTag } from './pretext-divisions';
|
|
5
|
+
import { DivisionPath } from './select/divisions';
|
|
3
6
|
import { DocumentKind } from './layout/document-kind';
|
|
4
7
|
import { ImportedProjectResult, ImportedProjectSuccess, SourceFormat } from './types';
|
|
5
8
|
export interface ImportProjectOptions extends BuildProjectFilesOptions {
|
|
@@ -32,6 +35,26 @@ export interface ImportProjectOptions extends BuildProjectFilesOptions {
|
|
|
32
35
|
* loose source into this package's standard layout instead.
|
|
33
36
|
*/
|
|
34
37
|
preserveProjectLayout?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Where the import is going (SPEC §9.2). Defaults to a project of its own;
|
|
40
|
+
* an `insert` destination retargets the document onto a chosen division
|
|
41
|
+
* level in a project that already exists and emits `<xi:include>` elements
|
|
42
|
+
* instead of a scaffold.
|
|
43
|
+
*/
|
|
44
|
+
destination?: ImportDestination;
|
|
45
|
+
/**
|
|
46
|
+
* Import only these divisions of the document, by `DivisionPath` (SPEC §9,
|
|
47
|
+
* step 6). Absent — or empty — imports the whole document.
|
|
48
|
+
*/
|
|
49
|
+
selection?: DivisionPath[];
|
|
50
|
+
/**
|
|
51
|
+
* The publication file's `<directories external="…"/>` — where author-supplied
|
|
52
|
+
* images go, relative to the main source file (SPEC §3.9). Defaults to
|
|
53
|
+
* `external`, which is what this package's generated publication file
|
|
54
|
+
* declares; a host inserting into a project it already has should pass that
|
|
55
|
+
* project's own.
|
|
56
|
+
*/
|
|
57
|
+
externalDir?: string;
|
|
35
58
|
}
|
|
36
59
|
export interface ExtractedUpload {
|
|
37
60
|
files: Record<string, string>;
|
|
@@ -63,13 +86,42 @@ export interface SplitLevelContext {
|
|
|
63
86
|
documentKind?: DocumentKind;
|
|
64
87
|
}
|
|
65
88
|
export declare function resolveImportSplitLevel(options: ImportProjectOptions, context: SplitLevelContext): number;
|
|
89
|
+
export interface RebuildImportOptions {
|
|
90
|
+
/** New split depth; defaults to the one the result was laid out at. */
|
|
91
|
+
splitLevel?: number;
|
|
92
|
+
/**
|
|
93
|
+
* New attach level for an `insert` destination. Ignored for a new-project
|
|
94
|
+
* import, which has no attach level.
|
|
95
|
+
*/
|
|
96
|
+
targetTag?: PretextDivisionTag;
|
|
97
|
+
/**
|
|
98
|
+
* New division selection (SPEC §9, step 6). Pass `[]` to go back to importing
|
|
99
|
+
* the whole document.
|
|
100
|
+
*/
|
|
101
|
+
selection?: DivisionPath[];
|
|
102
|
+
}
|
|
66
103
|
/**
|
|
67
|
-
* Re-derive an import's file layout
|
|
104
|
+
* Re-derive an import's file layout without re-importing.
|
|
68
105
|
*
|
|
69
106
|
* Everything expensive — extraction, include expansion, cleaning, and the
|
|
70
107
|
* unified-latex conversion — already happened and is carried on `result`. This
|
|
71
|
-
* only
|
|
72
|
-
*
|
|
73
|
-
*
|
|
108
|
+
* redoes only what the two live controls affect: the split depth, and (for an
|
|
109
|
+
* insert) the attach level. Both restart from `result.pretextSource`, the raw
|
|
110
|
+
* conversion, so changing the attach level re-prepares from scratch rather than
|
|
111
|
+
* shifting an already-shifted document a second time. Pure: same input, same
|
|
112
|
+
* output, no closures, safe to call across a webview boundary.
|
|
74
113
|
*/
|
|
114
|
+
export declare function rebuildImport(result: ImportedProjectSuccess, options?: RebuildImportOptions): ImportedProjectSuccess;
|
|
115
|
+
/**
|
|
116
|
+
* Re-derive an import keeping only the named divisions — the wizard's
|
|
117
|
+
* cherry-picking control (SPEC §9, step 6). An empty selection restores the
|
|
118
|
+
* whole document.
|
|
119
|
+
*/
|
|
120
|
+
export declare function reselectImport(result: ImportedProjectSuccess, selection: DivisionPath[]): ImportedProjectSuccess;
|
|
121
|
+
/** Re-derive an import's file layout at a different split depth. */
|
|
75
122
|
export declare function relayoutImport(result: ImportedProjectSuccess, splitLevel: number): ImportedProjectSuccess;
|
|
123
|
+
/**
|
|
124
|
+
* Re-derive an insert at a different attach level — the wizard's attach-point
|
|
125
|
+
* control (SPEC §9.4). A no-op for a new-project import.
|
|
126
|
+
*/
|
|
127
|
+
export declare function retargetImport(result: ImportedProjectSuccess, targetTag: PretextDivisionTag): ImportedProjectSuccess;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ImportProjectOptions } from '../lib/upload';
|
|
2
|
+
import { PretextDivisionTag } from '../lib/pretext-divisions';
|
|
2
3
|
import { ImportMode } from '../lib/import-mode';
|
|
3
4
|
import { DocumentKind } from '../lib/layout/document-kind';
|
|
4
5
|
import { UploadAnalysis } from '../lib/project/analyze';
|
|
@@ -88,5 +89,33 @@ export interface ImportWizardProps {
|
|
|
88
89
|
* selector is shown on the upload step. Defaults to a single built-in engine.
|
|
89
90
|
*/
|
|
90
91
|
engines?: ImportEngine[];
|
|
92
|
+
/**
|
|
93
|
+
* Import into a document that already exists rather than creating a project
|
|
94
|
+
* (SPEC §9). Only the host knows where the cursor is and what the project
|
|
95
|
+
* already contains, so it supplies both; the wizard adds the control that
|
|
96
|
+
* lets the author move the attach level and see the result before confirming.
|
|
97
|
+
*/
|
|
98
|
+
insertTarget?: InsertTargetOffer;
|
|
99
|
+
}
|
|
100
|
+
/** What the host knows about the document an import is being inserted into. */
|
|
101
|
+
export interface InsertTargetOffer {
|
|
102
|
+
/** How to name that document to the author, e.g. `ch-intro.ptx`. */
|
|
103
|
+
documentLabel: string;
|
|
104
|
+
/** The level derived from the cursor; the control starts here. */
|
|
105
|
+
defaultTargetTag: PretextDivisionTag;
|
|
106
|
+
/** Levels on offer, outermost first. Defaults to the whole division ladder. */
|
|
107
|
+
targetTags?: PretextDivisionTag[];
|
|
108
|
+
/**
|
|
109
|
+
* Every `xml:id` live in the host project. An array rather than a `Set`
|
|
110
|
+
* because this crosses a webview `postMessage` boundary.
|
|
111
|
+
*/
|
|
112
|
+
takenIds: string[];
|
|
113
|
+
/** Directory of the file receiving the include, with a trailing slash. */
|
|
114
|
+
hrefBase: string;
|
|
115
|
+
/**
|
|
116
|
+
* The host project's `<directories external="…"/>`, so imported images land
|
|
117
|
+
* where that project keeps its own rather than in this package's default.
|
|
118
|
+
*/
|
|
119
|
+
externalDir?: string;
|
|
91
120
|
}
|
|
92
|
-
export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, defaultImportMode, lockImportMode, onImportModeChange, engines, }: ImportWizardProps): import("react").JSX.Element;
|
|
121
|
+
export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, defaultImportMode, lockImportMode, onImportModeChange, engines, insertTarget, }: 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, PreparedUpload, } from './import-wizard';
|
|
2
|
+
export type { ImportWizardProps, ImportMode, ImportEngine, 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 o=require("react"),D=require("./upload-BnRj1gU1.cjs"),K=require("./import-mode-CV7gCDzF.cjs");var pe={exports:{}},le={};var Te;function Ue(){if(Te)return le;Te=1;var r=Symbol.for("react.transitional.element"),c=Symbol.for("react.fragment");function u(m,p,i){var N=null;if(i!==void 0&&(N=""+i),p.key!==void 0&&(N=""+p.key),"key"in p){i={};for(var C in p)C!=="key"&&(i[C]=p[C])}else i=p;return p=i.ref,{$$typeof:r,type:m,key:N,ref:p!==void 0?p:null,props:i}}return le.Fragment=c,le.jsx=u,le.jsxs=u,le}var oe={};var Pe;function ze(){return Pe||(Pe=1,process.env.NODE_ENV!=="production"&&(function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===fe?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case Y:return"Fragment";case B:return"Profiler";case _:return"StrictMode";case te:return"Suspense";case ce:return"SuspenseList";case he: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 I:return"Portal";case R:return t.displayName||"Context";case j:return(t._context.displayName||"Context")+".Consumer";case A:var l=t.render;return t=t.displayName,t||(t=l.displayName||l.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case ie:return l=t.displayName||null,l!==null?l:r(t.type)||"Memo";case V:l=t._payload,t=t._init;try{return r(t(l))}catch{}}return null}function c(t){return""+t}function u(t){try{c(t);var l=!1}catch{l=!0}if(l){l=console;var f=l.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return f.call(l,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),c(t)}}function m(t){if(t===Y)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===V)return"<...>";try{var l=r(t);return l?"<"+l+">":"<...>"}catch{return"<...>"}}function p(){var t=G.A;return t===null?null:t.getOwner()}function i(){return Error("react-stack-top-frame")}function N(t){if(W.call(t,"key")){var l=Object.getOwnPropertyDescriptor(t,"key").get;if(l&&l.isReactWarning)return!1}return t.key!==void 0}function C(t,l){function f(){J||(J=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",l))}f.isReactWarning=!0,Object.defineProperty(t,"key",{get:f,configurable:!0})}function h(){var t=r(this.type);return H[t]||(H[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(t,l,f,b,U,Z){var g=f.ref;return t={$$typeof:P,type:t,key:l,props:f,_owner:b},(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:U}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Z}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function E(t,l,f,b,U,Z){var g=l.children;if(g!==void 0)if(b)if(de(g)){for(b=0;b<g.length;b++)y(g[b]);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 y(g);if(W.call(l,"key")){g=r(t);var k=Object.keys(l).filter(function(O){return O!=="key"});b=0<k.length?"{key: someKey, "+k.join(": ..., ")+": ...}":"{key: someKey}",ne[g+b]||(k=0<k.length?"{"+k.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} />`,f,x,C,x),H[x+f]=!0)}if(x=null,d!==void 0&&(p(d),x=""+d),y(a)&&(p(a.key),x=""+a.key),"key"in a){d={};for(var Z in a)Z!=="key"&&(d[Z]=a[Z])}else d=a;return x&&P(d,typeof t=="function"?t.displayName||t.name||"Unknown":t),R(t,x,d,j(),I,$)}function b(t){D(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===K&&(t._payload.status==="fulfilled"?D(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function D(t){return typeof t=="object"&&t!==null&&t.$$typeof===E}var w=c,E=Symbol.for("react.transitional.element"),F=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),z=Symbol.for("react.profiler"),g=Symbol.for("react.consumer"),k=Symbol.for("react.context"),q=Symbol.for("react.forward_ref"),de=Symbol.for("react.suspense"),le=Symbol.for("react.suspense_list"),W=Symbol.for("react.memo"),K=Symbol.for("react.lazy"),ue=Symbol.for("react.activity"),ee=Symbol.for("react.client.reference"),U=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,te=Object.prototype.hasOwnProperty,Y=Array.isArray,V=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(t){return t()}};var se,G={},J=w.react_stack_bottom_frame.bind(w,u)(),M=V(h(u)),H={};ne.Fragment=O,ne.jsx=function(t,a,d){var f=1e4>U.recentlyCreatedOwnerStacks++;return v(t,a,d,!1,f?Error("react-stack-top-frame"):J,f?V(h(t)):M)},ne.jsxs=function(t,a,d){var f=1e4>U.recentlyCreatedOwnerStacks++;return v(t,a,d,!0,f?Error("react-stack-top-frame"):J,f?V(h(t)):M)}})()),ne}var Ne;function _e(){return Ne||(Ne=1,process.env.NODE_ENV==="production"?ie.exports=Pe():ie.exports=Re()),ie.exports}var e=_e();function Ce(){const[r,m]=c.useState(0),p=c.useRef(Date.now());return c.useEffect(()=>{const h=setInterval(()=>{m(Math.floor((Date.now()-p.current)/1e3))},1e3);return()=>clearInterval(h)},[]),r}function Ae(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function Se({message:r="Processing your file…",onCancel:m}){const p=Ce();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:Ae(p)}),p>=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,m?e.jsx("button",{type:"button",onClick:m,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 we=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],Fe={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:we,convertFile:A.handleImportUploadFile,prepare:async r=>{const{files:m,assets:p}=await A.extractUpload(r);return{fileName:r.name,files:m,assets:p,analysis:A.analyzeImportSources(m)}},convertPrepared:(r,m)=>A.importProjectFromFiles(r.files,{...m,assets:r.assets})};function fe(){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 Oe(r){const m=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} — ${m}`:m}function Ie(r){return r.candidates.filter(p=>p.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 Le({onConfirm:r,onCancel:m,importOptions:p,defaultDocumentKind:h="auto",defaultImportMode:j=Q.DEFAULT_IMPORT_MODE,lockImportMode:u=!1,onImportModeChange:y,engines:P}){const S=P&&P.length>0?P:[Fe],R=c.useRef(null),[v,b]=c.useState({name:"upload"}),[D,w]=c.useState(!1),[E,F]=c.useState(h),[O,_]=c.useState(null),[z,g]=c.useState(new Set),[k,q]=c.useState(S[0].id),[de,le]=c.useState(j),[W,K]=c.useState(!1),[ue,ee]=c.useState(new Set),[U,te]=c.useState(null),[Y,V]=c.useState("auto"),[se,G]=c.useState(null),[J,M]=c.useState({}),[H,t]=c.useState(!1),a=c.useRef(!1),d=S.find(s=>s.id===k)??S[0],f=d.acceptExtensions??we,I=v.name==="review"?v.result:null,$=c.useMemo(()=>I&&O!==null?A.relayoutImport(I,O):I,[I,O]),x=c.useMemo(()=>new Map($?Q.fileChangesForImport($).map(s=>[s.path,s]):[]),[$]),C=()=>p??{documentKind:E==="auto"?void 0:E},Z=s=>A.analyzeImportSources(s.files,{sourceFormat:Y==="auto"?void 0:Y,mainFile:se??void 0}),me=s=>{a.current=!0,d.cancel?.(),b(s?{name:"sources",prepared:s}:{name:"upload"})},Ee=async s=>{a.current=!1,b({name:"processing"}),await fe();try{const l=Z(s).extraRoots.map(i=>({path:i.path,include:J[i.path]?.include??!0,level:J[i.path]?.level})),N=await d.convertPrepared(s,{...C(),sourceFormat:Y==="auto"?void 0:Y,mainFile:se??void 0,attachRoots:l});"pretextError"in N?b({name:"error",message:N.pretextError}):b({name:"review",result:N})}catch(o){if(a.current)return;b({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},he=async s=>{a.current=!1,b({name:"processing"}),await fe();try{if(d.prepare&&d.convertPrepared){const l=await d.prepare(s);if(te(l),V("auto"),G(null),M({}),Ie(l.analysis)){b({name:"sources",prepared:l});return}await fe();const N=await d.convertPrepared(l,C());b("pretextError"in N?{name:"error",message:N.pretextError}:{name:"review",result:N});return}const o=await d.convertFile(s,C());"pretextError"in o?b({name:"error",message:o.pretextError}):b({name:"review",result:o})}catch(o){if(a.current)return;b({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},xe=()=>{b({name:"upload"}),le(j),K(!1),ee(new Set),g(new Set),_(null),te(null)};function be(s,o){return[...s].sort((l,N)=>l===o?-1:N===o?1:l.localeCompare(N))}function ge(s,o){const l=Q.filesForImportMode(s,o),N=o==="converted"?s.projectLayout.mainSourcePath:s.sourcePath,i=be(Object.keys(l),N)[0];ee(i?new Set([i]):new Set)}function ke(s){ee(o=>{const l=new Set(o);return l.has(s)?l.delete(s):l.add(s),l})}if(v.name==="processing")return e.jsx(Se,{onCancel:d.cancel?()=>me(U):void 0});if(v.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:v.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:xe,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(v.name==="sources"){const s=v.prepared,o=Z(s),l=o.manifest,N=o.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."]})]}),l?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 ",l.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:"," ",l.targets.map(i=>i.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:Y,onChange:i=>{V(i.currentTarget.value),G(null),M({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",o.primary?` (${ye[o.primary.format]})`:""]}),o.formats.map(i=>e.jsx("option",{value:i,children:ye[i]},i))]})]})}),o.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:o.candidates.map(i=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:i.path,checked:N===i.path,onChange:()=>{G(i.path),M({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:i.path}),e.jsx("span",{className:"block text-slate-500",children:Oe(i)})]})]},i.path))})]}):null,o.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:o.extraRoots.map(i=>{const L=J[i.path],re=L?.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:re,onChange:X=>M(B=>({...B,[i.path]:{...B[i.path],include:X.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:i.path}),i.title?e.jsxs("span",{className:"text-slate-500",children:["— ",i.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:L?.level??"auto",disabled:!re,onChange:X=>M(B=>({...B,[i.path]:{include:B[i.path]?.include??!0,level:X.currentTarget.value==="auto"?void 0:X.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"})]})]})]},i.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:xe,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Ee(s),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(v.name==="review"){let s=function(n){le(n),y?.(n),W&&ge(l,n)},o=function(n){g(T=>{const ce=new Set(T);return ce.has(n)?ce.delete(n):ce.add(n),ce})};const l=$??v.result,N=l.splitLevel,i=Q.hasNativeImportMode(l),L=Q.resolveImportMode(l,de),re=l.detectedSourceFormat==="markdown"?"Markdown":"LaTeX",X=l.warnings.length,B=Object.keys(l.outputFiles).length,pe=Q.filesForImportMode(l,L),Te=L==="converted"?l.projectLayout.mainSourcePath:l.sourcePath,oe=be(Object.keys(pe),Te);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:l.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:l.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:l.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:B}),l.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,l.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:l.attachedRoots.map(n=>`${n.title} (${n.level})`).join(", ")})]}):null]})]}),X>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:[X," conversion"," ",X===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:l.warnings.map((n,T)=>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]},T))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),i&&!u?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Import mode"}),e.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"converted",checked:L==="converted",onChange:()=>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:L==="native",onChange:()=>s("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Keep as ",re]}),e.jsxs("span",{className:"block text-slate-500",children:["Preserve the original ",re," source. The conversion will not be applied."]})]})]})]})]}):null,!p&&l.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,T)=>e.jsx("button",{type:"button",onClick:()=>_(T),"aria-pressed":N===T,className:N===T?"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:T===0?"One file":`${T} level${T===1?"":"s"}`},T)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[oe.length," file",oe.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:oe.map(n=>e.jsxs("li",{className:"truncate py-0.5",children:[n,x.get(n)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[x.get(n).fixCount," change",x.get(n).fixCount===1?"":"s"]}):null]},n))})]}):null,W?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:oe.map(n=>{const T=ue.has(n);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>ke(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:T?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:n}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(pe[n].length/1024).toFixed(1)," KB"]})]}),T?e.jsxs("div",{className:"bg-white",children:[x.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:()=>o(n),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:z.has(n)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",x.get(n).stats.added," −",x.get(n).stats.removed," in the LaTeX source"]})]}):null,z.has(n)&&x.has(n)?e.jsx(De,{hunks:x.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:pe[n]})]}):null]},n)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:m??xe,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:m?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[U?e.jsx("button",{type:"button",onClick:()=>b({name:"sources",prepared:U}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{W||ge(l,L),K(n=>!n)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:W?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:H,onClick:async()=>{t(!0);try{await r(l,L)}finally{t(!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:[H?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"}):null,H?"Importing…":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[S.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Converter"}),e.jsx("div",{className:"mt-2 flex flex-col gap-3",children:S.map(s=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-engine",value:s.id,checked:k===s.id,onChange:()=>q(s.id),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:s.label}),s.description?e.jsx("span",{className:"block text-slate-500",children:s.description}):null]})]},s.id))})]}):null,p?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:E,onChange:s=>F(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.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&R.current?.click(),onClick:()=>R.current?.click(),onDragOver:s=>{s.preventDefault(),w(!0)},onDragLeave:()=>w(!1),onDrop:s=>{s.preventDefault(),w(!1);const o=s.dataTransfer.files?.[0];o&&he(o)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${D?"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(),R.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 ",f.join(", ")]}),e.jsx("input",{ref:R,type:"file",hidden:!0,accept:f.join(","),onChange:s=>{const o=s.currentTarget.files?.[0];o&&he(o),s.currentTarget.value=""}})]})]})}function De({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((m,p)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[p>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,m.lines.map((h,j)=>e.jsxs("div",{className:h.op==="add"?"bg-green-50 px-4 text-green-900":h.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:h.op==="add"?"+":h.op==="remove"?"−":" "}),h.text||" "]},j))]},p))})}const Me={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 $e({initialSource:r="",initialSourceFormat:m,labels:p,disabled:h=!1,onImport:j}){const u=c.useMemo(()=>({...Me,...p??{}}),[p]),[y,P]=c.useState(r),[S,R]=c.useState(m??"auto"),[v,b]=c.useState(null),D=c.useMemo(()=>A.detectSourceFormat(y),[y]),w=h||!y.trim();return e.jsx("form",{onSubmit:E=>{E.preventDefault();const F=A.convertSourceToPretext(y,S==="auto"?void 0:S);b(F),j(F)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:h,children:[e.jsx("legend",{children:u.title}),e.jsx("p",{children:u.description}),e.jsxs("label",{children:[u.sourceLabel,e.jsx("textarea",{value:y,onChange:E=>P(E.currentTarget.value),placeholder:u.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[u.formatLabel,e.jsxs("select",{value:S,onChange:E=>R(E.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:[u.detectedFormatPrefix,": ",e.jsx("strong",{children:D})]}),e.jsx("button",{type:"submit",disabled:w,children:u.convertButton}),v?"pretextError"in v?e.jsxs("p",{role:"alert",children:[u.errorPrefix,": ",v.pretextError]}):e.jsxs("p",{children:[u.successPrefix,": ",v.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const Xe={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 ze({labels:r,disabled:m=!1,defaultDocumentKind:p="auto",importOptions:h,onImport:j}){const u=c.useMemo(()=>({...Xe,...r??{}}),[r]),y=c.useRef(null),[P,S]=c.useState(!1),[R,v]=c.useState(!1),[b,D]=c.useState([]),[w,E]=c.useState(p),[F,O]=c.useState(!1),_=m||R,z=async g=>{v(!0);try{const k=h??{documentKind:w==="auto"?void 0:w,splitSections:F},q=await A.handleImportUploadFile(g,k);D(q.statusMessages),j(q)}finally{v(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:u.title}),e.jsx("p",{children:u.hint}),h?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[u.documentKindLabel,e.jsxs("select",{value:w,disabled:_,onChange:g=>E(g.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:_,onChange:g=>O(g.currentTarget.checked)}),u.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:g=>{g.preventDefault(),_||S(!0)},onDragLeave:()=>S(!1),onDrop:g=>{if(g.preventDefault(),S(!1),_)return;const k=g.dataTransfer.files?.[0];k&&z(k)},children:[e.jsx("p",{children:u.dropHint}),e.jsxs("button",{type:"button",disabled:_,onClick:()=>y.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…":u.selectButton]}),e.jsx("input",{ref:y,type:"file",hidden:!0,disabled:_,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:g=>{const k=g.currentTarget.files?.[0];k&&z(k),g.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,b.length>0?e.jsx("ul",{"aria-live":"polite",children:b.map((g,k)=>e.jsx("li",{children:g.message},`${g.type}-${k}`))}):null,P&&!_?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=$e;exports.ImportUploadPanel=ze;exports.ImportWizard=Le;exports.ProcessingPanel=Se;
|
|
6
|
+
<%s key={someKey} {...props} />`,b,g,k,g),ne[g+b]=!0)}if(g=null,f!==void 0&&(u(f),g=""+f),N(l)&&(u(l.key),g=""+l.key),"key"in l){f={};for(var Q in l)Q!=="key"&&(f[Q]=l[Q])}else f=l;return g&&C(f,typeof t=="function"?t.displayName||t.name||"Unknown":t),T(t,g,f,p(),U,Z)}function y(t){v(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===V&&(t._payload.status==="fulfilled"?v(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function v(t){return typeof t=="object"&&t!==null&&t.$$typeof===P}var F=o,P=Symbol.for("react.transitional.element"),I=Symbol.for("react.portal"),Y=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),B=Symbol.for("react.profiler"),j=Symbol.for("react.consumer"),R=Symbol.for("react.context"),A=Symbol.for("react.forward_ref"),te=Symbol.for("react.suspense"),ce=Symbol.for("react.suspense_list"),ie=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),he=Symbol.for("react.activity"),fe=Symbol.for("react.client.reference"),G=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W=Object.prototype.hasOwnProperty,de=Array.isArray,se=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(t){return t()}};var J,H={},re=F.react_stack_bottom_frame.bind(F,i)(),X=se(m(i)),ne={};oe.Fragment=Y,oe.jsx=function(t,l,f){var b=1e4>G.recentlyCreatedOwnerStacks++;return E(t,l,f,!1,b?Error("react-stack-top-frame"):re,b?se(m(t)):X)},oe.jsxs=function(t,l,f){var b=1e4>G.recentlyCreatedOwnerStacks++;return E(t,l,f,!0,b?Error("react-stack-top-frame"):re,b?se(m(t)):X)}})()),oe}var Re;function Ye(){return Re||(Re=1,process.env.NODE_ENV==="production"?pe.exports=Ue():pe.exports=ze()),pe.exports}var e=Ye();function Be(){const[r,c]=o.useState(0),u=o.useRef(Date.now());return o.useEffect(()=>{const m=setInterval(()=>{c(Math.floor((Date.now()-u.current)/1e3))},1e3);return()=>clearInterval(m)},[]),r}function We(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function _e({message:r="Processing your file…",onCancel:c}){const u=Be();return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16 text-slate-600",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-700 border-t-transparent"}),e.jsx("p",{className:"text-sm",children:r}),e.jsx("p",{className:"text-xs tabular-nums text-slate-500",children:We(u)}),u>=10?e.jsx("p",{className:"max-w-xs text-center text-xs text-slate-500",children:"Large documents can take a while. You can keep working in other tabs."}):null,c?e.jsx("button",{type:"button",onClick:c,className:"mt-2 rounded border border-slate-300 px-3 py-1.5 text-xs font-medium text-slate-700 hover:bg-slate-50",children:"Cancel"}):null]})}const Ae=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],qe={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:Ae,convertFile:D.handleImportUploadFile,prepare:async r=>{const{files:c,assets:u}=await D.extractUpload(r);return{fileName:r.name,files:c,assets:u,analysis:D.analyzeImportSources(c)}},convertPrepared:(r,c)=>D.importProjectFromFiles(r.files,{...c,assets:r.assets})};function Ne(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const Ce={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function Ke(r){const c=r.reason==="manifest-target"?`project.ptx target “${r.targetName}”`:r.reason==="latex-root"?"LaTeX document":r.reason==="pretext-root"?"PreTeXt document":r.reason==="markdown-root"?"Markdown document":"possible document";return r.title?`${r.title} — ${c}`:c}function Ve(r){return r.candidates.filter(u=>u.reason==="manifest-target").length>1?!0:r.manifest&&r.primary?.reason==="manifest-target"?!1:r.formats.length>1||r.candidates.length>1||r.extraRoots.length>0}function Ge({onConfirm:r,onCancel:c,importOptions:u,defaultDocumentKind:m="auto",defaultImportMode:p=K.DEFAULT_IMPORT_MODE,lockImportMode:i=!1,onImportModeChange:N,engines:C,insertTarget:h}){const T=C&&C.length>0?C:[qe],E=o.useRef(null),[y,v]=o.useState({name:"upload"}),[F,P]=o.useState(!1),[I,Y]=o.useState(m),[_,B]=o.useState(null),[j,R]=o.useState(null),[A,te]=o.useState([]),[ce,ie]=o.useState(new Set),[V,he]=o.useState(T[0].id),[fe,G]=o.useState(p),[W,de]=o.useState(!1),[se,J]=o.useState(new Set),[H,re]=o.useState(null),[X,ne]=o.useState("auto"),[t,l]=o.useState(null),[f,b]=o.useState({}),[U,Z]=o.useState(!1),g=o.useRef(!1),k=T.find(n=>n.id===V)??T[0],Q=k.acceptExtensions??Ae,O=y.name==="review"?y.result:null,ue=o.useMemo(()=>O&&(_!==null||j!==null||A.length>0)?D.rebuildImport(O,{splitLevel:_??void 0,targetTag:j??void 0,selection:A}):O,[O,_,j,A]),be=o.useMemo(()=>O?D.outlineDivisions(O.pretextSource):[],[O]),z=o.useMemo(()=>new Map(ue?K.fileChangesForImport(ue).map(n=>[n.path,n]):[]),[ue]),ye=o.useMemo(()=>h?{kind:"insert",targetTag:j??h.defaultTargetTag,takenIds:new Set(h.takenIds),hrefBase:h.hrefBase}:void 0,[h,j]),ge=()=>({...u??{documentKind:I==="auto"?void 0:I},...ye?{destination:ye}:{},...h?.externalDir?{externalDir:h.externalDir}:{}}),we=n=>D.analyzeImportSources(n.files,{sourceFormat:X==="auto"?void 0:X,mainFile:t??void 0}),Ie=n=>{g.current=!0,k.cancel?.(),v(n?{name:"sources",prepared:n}:{name:"upload"})},Oe=async n=>{g.current=!1,v({name:"processing"}),await Ne();try{const a=we(n).extraRoots.map(x=>({path:x.path,include:f[x.path]?.include??!0,level:f[x.path]?.level})),S=await k.convertPrepared(n,{...ge(),sourceFormat:X==="auto"?void 0:X,mainFile:t??void 0,attachRoots:a});"pretextError"in S?v({name:"error",message:S.pretextError}):v({name:"review",result:S})}catch(d){if(g.current)return;v({name:"error",message:d instanceof Error?d.message:"An unexpected error occurred."})}},Se=async n=>{g.current=!1,v({name:"processing"}),await Ne();try{if(k.prepare&&k.convertPrepared){const a=await k.prepare(n);if(re(a),ne("auto"),l(null),b({}),Ve(a.analysis)){v({name:"sources",prepared:a});return}await Ne();const S=await k.convertPrepared(a,ge());v("pretextError"in S?{name:"error",message:S.pretextError}:{name:"review",result:S});return}const d=await k.convertFile(n,ge());"pretextError"in d?v({name:"error",message:d.pretextError}):v({name:"review",result:d})}catch(d){if(g.current)return;v({name:"error",message:d instanceof Error?d.message:"An unexpected error occurred."})}},je=()=>{v({name:"upload"}),G(p),de(!1),J(new Set),ie(new Set),B(null),R(null),te([]),re(null)};function ke(n,d){return[...n].sort((a,S)=>a===d?-1:S===d?1:a.localeCompare(S))}function Ee(n,d){const a=K.filesForImportMode(n,d),S=d==="converted"?n.projectLayout.mainSourcePath:n.sourcePath,x=ke(Object.keys(a),S)[0];J(x?new Set([x]):new Set)}function Le(n){J(d=>{const a=new Set(d);return a.has(n)?a.delete(n):a.add(n),a})}if(y.name==="processing")return e.jsx(_e,{onCancel:k.cancel?()=>Ie(H):void 0});if(y.name==="error")return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800",children:[e.jsx("p",{className:"font-semibold",children:"Import failed"}),e.jsx("p",{className:"mt-1",children:y.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:je,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(y.name==="sources"){const n=y.prepared,d=we(n),a=d.manifest,S=d.primary?.path??"";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:"Choose what to import"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[n.fileName," contains more than one possible starting point."]})]}),a?e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm text-blue-900",children:[e.jsxs("p",{className:"font-medium",children:["Found ",a.manifestPath," — an existing PreTeXt project."]}),e.jsxs("p",{className:"mt-1 text-blue-800",children:["Its publication file, assets, and directory layout will be kept as they are. Targets:"," ",a.targets.map(x=>x.name).join(", "),"."]})]}):null,e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Source format"}),e.jsxs("select",{value:X,onChange:x=>{ne(x.currentTarget.value),l(null),b({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",d.primary?` (${Ce[d.primary.format]})`:""]}),d.formats.map(x=>e.jsx("option",{value:x,children:Ce[x]},x))]})]})}),d.candidates.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Main document"}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:d.candidates.map(x=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:x.path,checked:S===x.path,onChange:()=>{l(x.path),b({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:x.path}),e.jsx("span",{className:"block text-slate-500",children:Ke(x)})]})]},x.path))})]}):null,d.extraRoots.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Other documents"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"These files also stand on their own. Attach them to the main document, or leave them out."}),e.jsx("div",{className:"mt-3 flex flex-col gap-2",children:d.extraRoots.map(x=>{const ae=f[x.path],L=ae?.include??!0;return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm",children:[e.jsxs("label",{className:"flex flex-1 cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:L,onChange:q=>b(M=>({...M,[x.path]:{...M[x.path],include:q.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:x.path}),x.title?e.jsxs("span",{className:"text-slate-500",children:["— ",x.title]}):null]}),e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Attach as"}),e.jsxs("select",{value:ae?.level??"auto",disabled:!L,onChange:q=>b(M=>({...M,[x.path]:{include:M[x.path]?.include??!0,level:q.currentTarget.value==="auto"?void 0:q.currentTarget.value}})),className:"rounded border border-slate-300 px-2 py-1 text-sm disabled:opacity-50",children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"chapter",children:"Chapter"}),e.jsx("option",{value:"section",children:"Section"})]})]})]},x.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:je,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Oe(n),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(y.name==="review"){let n=function(s){G(s),N?.(s),W&&Ee(a,s)},d=function(s){ie(w=>{const ee=new Set(w);return ee.has(s)?ee.delete(s):ee.add(s),ee})};const a=ue??y.result,S=a.splitLevel,x=A.length>0,ae=K.hasNativeImportMode(a)&&!x,L=ae?K.resolveImportMode(a,fe):"converted",q=a.detectedSourceFormat==="markdown"?"Markdown":"LaTeX",M=a.warnings.length,Me=Object.keys(a.outputFiles).length,$=a.insert,me=a.destination.kind==="insert"?a.destination.targetTag:void 0,$e=h?.targetTags??[...D.DIVISION_LADDER],ve=K.filesForImportMode(a,L),Xe=L==="converted"?a.projectLayout.mainSourcePath:a.sourcePath,xe=ke(Object.keys(ve),Xe);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-slate-700",children:"Import Summary"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsx("dt",{className:"text-slate-500",children:"Source"}),e.jsx("dd",{className:"font-medium text-slate-900",children:a.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:Me}),h?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Destination"}),e.jsxs("dd",{className:"font-medium text-slate-900",children:["Inserted into ",h.documentLabel]})]}):null,a.projectLayout.preserved?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Existing project"}),e.jsx("dd",{className:"font-medium text-slate-900",children:"Kept publication file, assets, and layout"})]}):null,a.attachedRoots.length>0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Attached"}),e.jsx("dd",{className:"font-medium text-slate-900",children:a.attachedRoots.map(s=>`${s.title} (${s.level})`).join(", ")})]}):null]})]}),M>0?e.jsxs("details",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-amber-800",children:[M," conversion"," ",M===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:a.warnings.map((s,w)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:s.macro})," — ",s.action==="replace"||s.action==="rewrite"?`replaced with \`${s.replacement}\``:s.message??s.action,s.occurrences>1?` (×${s.occurrences})`:null]},w))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),ae&&!i?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Import mode"}),e.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"converted",checked:L==="converted",onChange:()=>n("converted"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Convert to PreTeXt"}),e.jsx("span",{className:"block text-slate-500",children:"Use the converted PreTeXt output. Recommended for new PreTeXt projects."})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"native",checked:L==="native",onChange:()=>n("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Keep as ",q]}),e.jsxs("span",{className:"block text-slate-500",children:["Preserve the original ",q," source. The conversion will not be applied."]})]})]})]})]}):null,be.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Divisions to import"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("button",{type:"button",onClick:()=>te([]),className:"rounded border border-slate-300 px-3 py-1 text-slate-700 hover:bg-slate-50",children:"Everything"}),e.jsx("span",{className:"text-slate-500",children:A.length===0?"The whole document":`${A.length} of ${Fe(be)} divisions`})]}),e.jsx("div",{className:"mt-3 max-h-56 overflow-auto",children:e.jsx(De,{items:be,selection:A,onToggle:s=>te(w=>w.includes(s)?w.filter(ee=>ee!==s):[...w,s].sort(Je))})}),A.length>0?e.jsxs("p",{className:"mt-2 text-sm text-slate-500",children:["A selected division is imported whole, with everything inside it. Divisions above one you selected are kept as structure.",K.hasNativeImportMode(y.result)?" Selecting divisions imports the converted PreTeXt; keeping the original source imports the document whole.":""]}):null]}):null,$&&h?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsxs("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:["Attach to ",h.documentLabel]}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:$e.map(s=>e.jsxs("button",{type:"button",onClick:()=>R(s),"aria-pressed":me===s,className:me===s?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:["<",s,">"]},s))}),e.jsxs("p",{className:"mt-3 text-sm text-slate-600",children:[$.includes.length===1?`One <${me}> is added to ${h.documentLabel}, `:`${$.includes.length} <${me}> divisions are added to ${h.documentLabel}, `,$.includes.length===1?"included from a new file beside it.":"each included from a new file beside it."]}),$.renamed.length>0?e.jsxs("p",{className:"mt-2 text-sm text-amber-700",children:[$.renamed.length," id",$.renamed.length===1?"":"s"," already used in this project"," ",$.renamed.length===1?"was":"were"," renamed:"," ",e.jsx("span",{className:"font-mono text-xs",children:$.renamed.map(s=>`${s.from} → ${s.to}`).join(", ")})]}):null]}):null,!u&&a.cleanChunks.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Split into files"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Array.from({length:D.MAX_SUGGESTED_SPLIT_LEVEL+1},(s,w)=>e.jsx("button",{type:"button",onClick:()=>B(w),"aria-pressed":S===w,className:S===w?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:w===0?"One file":`${w} level${w===1?"":"s"}`},w)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[xe.length," file",xe.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:xe.map(s=>e.jsxs("li",{className:"truncate py-0.5",children:[s,z.get(s)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[z.get(s).fixCount," change",z.get(s).fixCount===1?"":"s"]}):null]},s))})]}):null,W?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:xe.map(s=>{const w=se.has(s);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Le(s),className:"flex w-full items-center gap-2 bg-slate-100 px-4 py-2 text-left font-mono text-xs text-slate-700 hover:bg-slate-200",children:[e.jsx("span",{className:"shrink-0 text-slate-400",children:w?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:s}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(ve[s].length/1024).toFixed(1)," KB"]})]}),w?e.jsxs("div",{className:"bg-white",children:[z.get(s)?.hunks.length?e.jsxs("div",{className:"flex gap-2 border-b border-slate-200 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>d(s),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:ce.has(s)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",z.get(s).stats.added," −",z.get(s).stats.removed," in the LaTeX source"]})]}):null,ce.has(s)&&z.has(s)?e.jsx(He,{hunks:z.get(s).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:ve[s]})]}):null]},s)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:c??je,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:c?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[H?e.jsx("button",{type:"button",onClick:()=>v({name:"sources",prepared:H}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{W||Ee(a,L),de(s=>!s)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:W?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:U,onClick:async()=>{Z(!0);try{await r(a,L)}finally{Z(!1)}},className:"flex items-center gap-2 rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600 disabled:opacity-60",children:[U?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"}):null,U?h?"Inserting…":"Importing…":h?"Confirm Insert":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[T.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Converter"}),e.jsx("div",{className:"mt-2 flex flex-col gap-3",children:T.map(n=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-engine",value:n.id,checked:V===n.id,onChange:()=>he(n.id),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:n.label}),n.description?e.jsx("span",{className:"block text-slate-500",children:n.description}):null]})]},n.id))})]}):null,u?null:e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Document kind"}),e.jsxs("select",{value:I,onChange:n=>Y(n.currentTarget.value),className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:n=>n.key==="Enter"&&E.current?.click(),onClick:()=>E.current?.click(),onDragOver:n=>{n.preventDefault(),P(!0)},onDragLeave:()=>P(!1),onDrop:n=>{n.preventDefault(),P(!1);const d=n.dataTransfer.files?.[0];d&&Se(d)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${F?"border-blue-500 bg-blue-50":"border-slate-300 bg-slate-50 hover:border-slate-400"}`,children:[e.jsx("p",{className:"text-slate-600",children:"Drop a file here, or click to select."}),e.jsx("button",{type:"button",onClick:n=>{n.stopPropagation(),E.current?.click()},className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Select File"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Supports ",Q.join(", ")]}),e.jsx("input",{ref:E,type:"file",hidden:!0,accept:Q.join(","),onChange:n=>{const d=n.currentTarget.files?.[0];d&&Se(d),n.currentTarget.value=""}})]})]})}function Fe(r){return r.reduce((c,u)=>c+1+Fe(u.children),0)}function Je(r,c){const u=r.split(".").map(Number),m=c.split(".").map(Number);for(let p=0;p<Math.max(u.length,m.length);p++){const i=(u[p]??-1)-(m[p]??-1);if(i!==0)return i}return 0}function De({items:r,selection:c,onToggle:u}){return e.jsx("ul",{className:"space-y-0.5 text-sm",children:r.map(m=>{const p=c.includes(m.path),i=c.some(N=>m.path.startsWith(`${N}.`));return e.jsxs("li",{children:[e.jsxs("label",{className:"flex items-baseline gap-2",children:[e.jsx("input",{type:"checkbox",checked:p||i,disabled:i,onChange:()=>u(m.path)}),e.jsxs("span",{className:i?"text-slate-400":"text-slate-700",children:[m.title||e.jsx("em",{children:"Untitled"}),e.jsxs("span",{className:"ml-2 font-mono text-xs text-slate-400",children:["<",m.tag,">"]})]})]}),m.children.length>0?e.jsx("div",{className:"ml-5 border-l border-slate-200 pl-3",children:e.jsx(De,{items:m.children,selection:c,onToggle:u})}):null]},m.path)})})}function He({hunks:r}){return r.length===0?e.jsx("p",{className:"m-0 px-4 py-3 text-xs text-slate-500",children:"Nothing was changed in this file."}):e.jsx("div",{className:"max-h-72 overflow-auto bg-white font-mono text-xs leading-relaxed",children:r.map((c,u)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[u>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,c.lines.map((m,p)=>e.jsxs("div",{className:m.op==="add"?"bg-green-50 px-4 text-green-900":m.op==="remove"?"bg-red-50 px-4 text-red-900":"px-4 text-slate-600",children:[e.jsx("span",{className:"mr-2 select-none text-slate-400",children:m.op==="add"?"+":m.op==="remove"?"−":" "}),m.text||" "]},p))]},u))})}const Ze={title:"Import Source Content",description:"Paste LaTeX, Markdown, or PreTeXt source to convert into PreTeXt.",sourceLabel:"Source",sourcePlaceholder:"Paste source content here...",formatLabel:"Source format",convertButton:"Convert to PreTeXt",detectedFormatPrefix:"Detected",successPrefix:"Ready",errorPrefix:"Error"};function Qe({initialSource:r="",initialSourceFormat:c,labels:u,disabled:m=!1,onImport:p}){const i=o.useMemo(()=>({...Ze,...u??{}}),[u]),[N,C]=o.useState(r),[h,T]=o.useState(c??"auto"),[E,y]=o.useState(null),v=o.useMemo(()=>D.detectSourceFormat(N),[N]),F=m||!N.trim();return e.jsx("form",{onSubmit:P=>{P.preventDefault();const I=D.convertSourceToPretext(N,h==="auto"?void 0:h);y(I),p(I)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:m,children:[e.jsx("legend",{children:i.title}),e.jsx("p",{children:i.description}),e.jsxs("label",{children:[i.sourceLabel,e.jsx("textarea",{value:N,onChange:P=>C(P.currentTarget.value),placeholder:i.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[i.formatLabel,e.jsxs("select",{value:h,onChange:P=>T(P.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"latex",children:"LaTeX"}),e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"pretext",children:"PreTeXt"})]})]}),e.jsxs("p",{children:[i.detectedFormatPrefix,": ",e.jsx("strong",{children:v})]}),e.jsx("button",{type:"submit",disabled:F,children:i.convertButton}),E?"pretextError"in E?e.jsxs("p",{role:"alert",children:[i.errorPrefix,": ",E.pretextError]}):e.jsxs("p",{children:[i.successPrefix,": ",E.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const et={title:"Upload Source File",hint:"Supports .tex, .md, .ptx, .xml, .zip, and .tar.gz files.",selectButton:"Select File",dropHint:"Drop a file here, or click Select File.",documentKindLabel:"Document kind",splitSectionsLabel:"Split each chapter into sections"};function tt({labels:r,disabled:c=!1,defaultDocumentKind:u="auto",importOptions:m,onImport:p}){const i=o.useMemo(()=>({...et,...r??{}}),[r]),N=o.useRef(null),[C,h]=o.useState(!1),[T,E]=o.useState(!1),[y,v]=o.useState([]),[F,P]=o.useState(u),[I,Y]=o.useState(!1),_=c||T,B=async j=>{E(!0);try{const R=m??{documentKind:F==="auto"?void 0:F,splitSections:I},A=await D.handleImportUploadFile(j,R);v(A.statusMessages),p(A)}finally{E(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:i.title}),e.jsx("p",{children:i.hint}),m?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[i.documentKindLabel,e.jsxs("select",{value:F,disabled:_,onChange:j=>P(j.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]}),e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:I,disabled:_,onChange:j=>Y(j.currentTarget.checked)}),i.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:j=>{j.preventDefault(),_||h(!0)},onDragLeave:()=>h(!1),onDrop:j=>{if(j.preventDefault(),h(!1),_)return;const R=j.dataTransfer.files?.[0];R&&B(R)},children:[e.jsx("p",{children:i.dropHint}),e.jsxs("button",{type:"button",disabled:_,onClick:()=>N.current?.click(),className:"inline-flex items-center gap-2",children:[T?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent","aria-hidden":"true"}):null,T?"Processing…":i.selectButton]}),e.jsx("input",{ref:N,type:"file",hidden:!0,disabled:_,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:j=>{const R=j.currentTarget.files?.[0];R&&B(R),j.currentTarget.value=""}})]}),T?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,y.length>0?e.jsx("ul",{"aria-live":"polite",children:y.map((j,R)=>e.jsx("li",{children:j.message},`${j.type}-${R}`))}):null,C&&!_?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=Qe;exports.ImportUploadPanel=tt;exports.ImportWizard=Ge;exports.ProcessingPanel=_e;
|