document-cli 1.0.1 → 1.1.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/README.md +4 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +5 -2
- package/dist/index.js +5 -2
- package/dist/{io-Cl3MaB0L.js → io-CKOE9Xda.js} +3 -0
- package/dist/{tui-CucYgqmL.js → tui-Dywpifqx.js} +184 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,16 +12,19 @@ graph TD
|
|
|
12
12
|
ooxml("ooxml.js")
|
|
13
13
|
odf("odf.js")
|
|
14
14
|
pdfcodec("pdf-codec")
|
|
15
|
+
mdcodec("markdown-codec")
|
|
15
16
|
documents("documents.js")
|
|
16
17
|
cli("document-cli")
|
|
17
18
|
|
|
18
19
|
schema --> ooxml
|
|
19
20
|
schema --> odf
|
|
20
21
|
schema --> pdfcodec
|
|
22
|
+
schema --> mdcodec
|
|
21
23
|
schema --> documents
|
|
22
24
|
ooxml --> documents
|
|
23
25
|
odf --> documents
|
|
24
26
|
pdfcodec --> documents
|
|
27
|
+
mdcodec --> documents
|
|
25
28
|
documents --> cli
|
|
26
29
|
odf --> cli
|
|
27
30
|
|
|
@@ -29,6 +32,7 @@ graph TD
|
|
|
29
32
|
click ooxml "https://github.com/ExaDev/ooxml.js" "ooxml.js"
|
|
30
33
|
click odf "https://github.com/ExaDev/odf.js" "odf.js"
|
|
31
34
|
click pdfcodec "https://github.com/ExaDev/pdf-codec" "pdf-codec"
|
|
35
|
+
click mdcodec "https://github.com/ExaDev/markdown-codec" "markdown-codec"
|
|
32
36
|
click documents "https://github.com/ExaDev/documents.js" "documents.js"
|
|
33
37
|
click cli "https://github.com/ExaDev/document-cli" "document-cli"
|
|
34
38
|
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as inferFormatFromExtension, n as resolveDefaultOutputPath, o as isDocumentFormat, r as writeOutput, t as readInput } from "./io-
|
|
2
|
+
import { a as inferFormatFromExtension, n as resolveDefaultOutputPath, o as isDocumentFormat, r as writeOutput, t as readInput } from "./io-CKOE9Xda.js";
|
|
3
3
|
import { Command, CommanderError, InvalidArgumentError } from "commander";
|
|
4
4
|
import { writeFile } from "node:fs/promises";
|
|
5
5
|
import { OdbNoEmbeddedDataSourceError, OdbTableNotFoundError, OdbTableNotSpecifiedError, OdbUnsupportedFormatError, OdmUnresolvedSectionError, PdfEncryptedError, PdfParseError, createLocalDocumentConverter, odbToCsv, odbToXlsx, odmToPdf, readOdbTables, readPdf } from "documents.js";
|
|
@@ -181,7 +181,7 @@ function toConversionCommandOptions(options) {
|
|
|
181
181
|
dumpPackage: options.dumpPackage
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
|
-
const KNOWN_FORMATS = "docx, pptx, xlsx, odt, odp, ods, odg, odf, pdf";
|
|
184
|
+
const KNOWN_FORMATS = "docx, pptx, xlsx, odt, odp, ods, odg, odf, markdown, pdf";
|
|
185
185
|
function resolveGenericTarget(output, options) {
|
|
186
186
|
if (options.to !== void 0) {
|
|
187
187
|
if (!isDocumentFormat(options.to)) return { errorMessage: `unknown --to format '${options.to}'; expected one of ${KNOWN_FORMATS}` };
|
|
@@ -546,7 +546,7 @@ function registerPdfInspectCommand(program) {
|
|
|
546
546
|
}
|
|
547
547
|
//#endregion
|
|
548
548
|
//#region package.json
|
|
549
|
-
var version = "1.0
|
|
549
|
+
var version = "1.1.0";
|
|
550
550
|
//#endregion
|
|
551
551
|
//#region src/program.ts
|
|
552
552
|
function createProgram() {
|
|
@@ -568,7 +568,7 @@ function createProgram() {
|
|
|
568
568
|
//#region src/cli.ts
|
|
569
569
|
async function launchTui(startPath, signal) {
|
|
570
570
|
try {
|
|
571
|
-
const { runTui } = await import("./tui-
|
|
571
|
+
const { runTui } = await import("./tui-Dywpifqx.js");
|
|
572
572
|
await runTui({
|
|
573
573
|
startPath,
|
|
574
574
|
signal
|
package/dist/index.cjs
CHANGED
|
@@ -15,6 +15,8 @@ const EXTENSION_TO_FORMAT = {
|
|
|
15
15
|
ods: "ods",
|
|
16
16
|
odg: "odg",
|
|
17
17
|
odf: "odf",
|
|
18
|
+
markdown: "markdown",
|
|
19
|
+
md: "markdown",
|
|
18
20
|
pdf: "pdf"
|
|
19
21
|
};
|
|
20
22
|
const FORMAT_TO_EXTENSION = {
|
|
@@ -26,6 +28,7 @@ const FORMAT_TO_EXTENSION = {
|
|
|
26
28
|
ods: "ods",
|
|
27
29
|
odg: "odg",
|
|
28
30
|
odf: "odf",
|
|
31
|
+
markdown: "md",
|
|
29
32
|
pdf: "pdf"
|
|
30
33
|
};
|
|
31
34
|
function isDocumentFormat(value) {
|
|
@@ -265,7 +268,7 @@ function toConversionCommandOptions(options) {
|
|
|
265
268
|
dumpPackage: options.dumpPackage
|
|
266
269
|
};
|
|
267
270
|
}
|
|
268
|
-
const KNOWN_FORMATS = "docx, pptx, xlsx, odt, odp, ods, odg, odf, pdf";
|
|
271
|
+
const KNOWN_FORMATS = "docx, pptx, xlsx, odt, odp, ods, odg, odf, markdown, pdf";
|
|
269
272
|
function resolveGenericTarget(output, options) {
|
|
270
273
|
if (options.to !== void 0) {
|
|
271
274
|
if (!isDocumentFormat(options.to)) return { errorMessage: `unknown --to format '${options.to}'; expected one of ${KNOWN_FORMATS}` };
|
|
@@ -630,7 +633,7 @@ function registerPdfInspectCommand(program) {
|
|
|
630
633
|
}
|
|
631
634
|
//#endregion
|
|
632
635
|
//#region package.json
|
|
633
|
-
var version = "1.0
|
|
636
|
+
var version = "1.1.0";
|
|
634
637
|
//#endregion
|
|
635
638
|
//#region src/program.ts
|
|
636
639
|
function createProgram() {
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,8 @@ const EXTENSION_TO_FORMAT = {
|
|
|
14
14
|
ods: "ods",
|
|
15
15
|
odg: "odg",
|
|
16
16
|
odf: "odf",
|
|
17
|
+
markdown: "markdown",
|
|
18
|
+
md: "markdown",
|
|
17
19
|
pdf: "pdf"
|
|
18
20
|
};
|
|
19
21
|
const FORMAT_TO_EXTENSION = {
|
|
@@ -25,6 +27,7 @@ const FORMAT_TO_EXTENSION = {
|
|
|
25
27
|
ods: "ods",
|
|
26
28
|
odg: "odg",
|
|
27
29
|
odf: "odf",
|
|
30
|
+
markdown: "md",
|
|
28
31
|
pdf: "pdf"
|
|
29
32
|
};
|
|
30
33
|
function isDocumentFormat(value) {
|
|
@@ -264,7 +267,7 @@ function toConversionCommandOptions(options) {
|
|
|
264
267
|
dumpPackage: options.dumpPackage
|
|
265
268
|
};
|
|
266
269
|
}
|
|
267
|
-
const KNOWN_FORMATS = "docx, pptx, xlsx, odt, odp, ods, odg, odf, pdf";
|
|
270
|
+
const KNOWN_FORMATS = "docx, pptx, xlsx, odt, odp, ods, odg, odf, markdown, pdf";
|
|
268
271
|
function resolveGenericTarget(output, options) {
|
|
269
272
|
if (options.to !== void 0) {
|
|
270
273
|
if (!isDocumentFormat(options.to)) return { errorMessage: `unknown --to format '${options.to}'; expected one of ${KNOWN_FORMATS}` };
|
|
@@ -629,7 +632,7 @@ function registerPdfInspectCommand(program) {
|
|
|
629
632
|
}
|
|
630
633
|
//#endregion
|
|
631
634
|
//#region package.json
|
|
632
|
-
var version = "1.0
|
|
635
|
+
var version = "1.1.0";
|
|
633
636
|
//#endregion
|
|
634
637
|
//#region src/program.ts
|
|
635
638
|
function createProgram() {
|
|
@@ -11,6 +11,8 @@ const EXTENSION_TO_FORMAT = {
|
|
|
11
11
|
ods: "ods",
|
|
12
12
|
odg: "odg",
|
|
13
13
|
odf: "odf",
|
|
14
|
+
markdown: "markdown",
|
|
15
|
+
md: "markdown",
|
|
14
16
|
pdf: "pdf"
|
|
15
17
|
};
|
|
16
18
|
const FORMAT_TO_EXTENSION = {
|
|
@@ -22,6 +24,7 @@ const FORMAT_TO_EXTENSION = {
|
|
|
22
24
|
ods: "ods",
|
|
23
25
|
odg: "odg",
|
|
24
26
|
odf: "odf",
|
|
27
|
+
markdown: "md",
|
|
25
28
|
pdf: "pdf"
|
|
26
29
|
};
|
|
27
30
|
function isDocumentFormat(value) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as inferFormatFromExtension, i as formatToExtension, t as readInput } from "./io-
|
|
1
|
+
import { a as inferFormatFromExtension, i as formatToExtension, t as readInput } from "./io-CKOE9Xda.js";
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import { createDocx, createOdg, createOdp, createOds, createOdt, createPptx, docxToPdf, hsqldbCellDisplayText, odgToPdf, odpToPdf, odsToPdf, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, pptxToPdf, readOdbTables, readOdgContent, readOdsContent, readPdf, rgbHexToColor } from "documents.js";
|
|
3
|
+
import { createDocx, createOdg, createOdp, createOds, createOdt, createPptx, decodeMarkdownText, docxToPdf, encodeMarkdownText, hsqldbCellDisplayText, markdownToPdf, odgToPdf, odpToPdf, odsToPdf, odtToPdf, openDocx, openOdg, openOdp, openOds, openOdt, openPptx, pptxToPdf, readOdbTables, readOdgContent, readOdsContent, readPdf, rgbHexToColor } from "documents.js";
|
|
4
4
|
import { basename, dirname, extname, join } from "node:path";
|
|
5
5
|
import { cellReference, columnIndexToLetters, decodePackage } from "odf.js";
|
|
6
6
|
import { readdirSync } from "node:fs";
|
|
@@ -29,8 +29,13 @@ function toPdfOptions(options) {
|
|
|
29
29
|
}
|
|
30
30
|
async function exportToPdf(openDocument, destinationPath, options) {
|
|
31
31
|
if (openDocument.format === "odb" || openDocument.format === "pdf") throw new Error(`A ${openDocument.format} document is already a read-only source; there is no export-to-PDF path for it`);
|
|
32
|
-
const bytes = openDocument.editor.toBytes();
|
|
33
32
|
const pdfOptions = toPdfOptions(options);
|
|
33
|
+
if (openDocument.format === "markdown") {
|
|
34
|
+
const pdfBytes = markdownToPdf(encodeMarkdownText(openDocument.source), pdfOptions);
|
|
35
|
+
await writeFile(destinationPath, pdfBytes);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const bytes = openDocument.editor.toBytes();
|
|
34
39
|
const pdfBytes = convert(openDocument.format, bytes, pdfOptions);
|
|
35
40
|
await writeFile(destinationPath, pdfBytes);
|
|
36
41
|
}
|
|
@@ -102,6 +107,11 @@ async function openDocumentAtPath(path) {
|
|
|
102
107
|
layout: readPdf(bytes),
|
|
103
108
|
path
|
|
104
109
|
};
|
|
110
|
+
case "markdown": return {
|
|
111
|
+
format,
|
|
112
|
+
source: decodeMarkdownText(bytes),
|
|
113
|
+
path
|
|
114
|
+
};
|
|
105
115
|
case "xlsx": throw new Error("documents.js has no xlsx editor; convert the workbook to ods first (xlsxToOds) and open that");
|
|
106
116
|
case "odf": throw new Error("A standalone .odf formula document has no editor; convert it to PDF (odfToPdf) instead");
|
|
107
117
|
}
|
|
@@ -142,6 +152,10 @@ function createNewDocument(format) {
|
|
|
142
152
|
}
|
|
143
153
|
async function saveDocumentTo(openDocument, path) {
|
|
144
154
|
if (openDocument.format === "odb" || openDocument.format === "pdf") throw new Error(`A ${openDocument.format} document is opened read-only and cannot be written back`);
|
|
155
|
+
if (openDocument.format === "markdown") {
|
|
156
|
+
await writeFile(path, encodeMarkdownText(openDocument.source));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
145
159
|
await writeFile(path, openDocument.editor.toBytes());
|
|
146
160
|
}
|
|
147
161
|
//#endregion
|
|
@@ -154,11 +168,18 @@ const EDITABLE_FORMATS = {
|
|
|
154
168
|
ods: true,
|
|
155
169
|
odg: true
|
|
156
170
|
};
|
|
171
|
+
const WRITABLE_FORMATS = {
|
|
172
|
+
...EDITABLE_FORMATS,
|
|
173
|
+
markdown: true
|
|
174
|
+
};
|
|
157
175
|
function isEditableFormat(value) {
|
|
158
176
|
return value in EDITABLE_FORMATS;
|
|
159
177
|
}
|
|
160
|
-
function
|
|
161
|
-
return
|
|
178
|
+
function isWritableFormat(value) {
|
|
179
|
+
return value in WRITABLE_FORMATS;
|
|
180
|
+
}
|
|
181
|
+
function isWritableDocument(document) {
|
|
182
|
+
return isWritableFormat(document.format);
|
|
162
183
|
}
|
|
163
184
|
function selectionKeyFor(screen) {
|
|
164
185
|
switch (screen.kind) {
|
|
@@ -171,7 +192,8 @@ function selectionKeyFor(screen) {
|
|
|
171
192
|
case "odbTableList":
|
|
172
193
|
case "pdfPageList":
|
|
173
194
|
case "exportOptions":
|
|
174
|
-
case "saveAsPrompt":
|
|
195
|
+
case "saveAsPrompt":
|
|
196
|
+
case "markdownLineList": return screen.kind;
|
|
175
197
|
case "filePicker": return `filePicker:${screen.purpose}:${screen.cwd}`;
|
|
176
198
|
case "paragraphDetail":
|
|
177
199
|
case "tableView":
|
|
@@ -189,6 +211,7 @@ function selectionKeyFor(screen) {
|
|
|
189
211
|
case "shapeOrVectorDetail":
|
|
190
212
|
case "pdfItemDetail": return `${screen.kind}:${screen.pageIndex}:${screen.itemIndex}`;
|
|
191
213
|
case "odbTableRows": return `odbTableRows:${screen.tableName}`;
|
|
214
|
+
case "markdownLineEditor": return `markdownLineEditor:${screen.lineIndex}`;
|
|
192
215
|
}
|
|
193
216
|
}
|
|
194
217
|
function rootScreenForFormat(format) {
|
|
@@ -200,6 +223,7 @@ function rootScreenForFormat(format) {
|
|
|
200
223
|
case "ods": return { kind: "sheetList" };
|
|
201
224
|
case "odg": return { kind: "pageList" };
|
|
202
225
|
case "odb": return { kind: "odbTableList" };
|
|
226
|
+
case "markdown": return { kind: "markdownLineList" };
|
|
203
227
|
case "pdf": return { kind: "pdfPageList" };
|
|
204
228
|
}
|
|
205
229
|
}
|
|
@@ -317,6 +341,11 @@ function documentWithPath(doc, path) {
|
|
|
317
341
|
tables: doc.tables,
|
|
318
342
|
path
|
|
319
343
|
};
|
|
344
|
+
case "markdown": return {
|
|
345
|
+
format: "markdown",
|
|
346
|
+
source: doc.source,
|
|
347
|
+
path
|
|
348
|
+
};
|
|
320
349
|
case "pdf": return {
|
|
321
350
|
format: "pdf",
|
|
322
351
|
layout: doc.layout,
|
|
@@ -367,6 +396,18 @@ function mutate(state, doc, apply) {
|
|
|
367
396
|
undoStack: pushSnapshot(state.undoStack, snapshot)
|
|
368
397
|
};
|
|
369
398
|
}
|
|
399
|
+
function mutateMarkdown(state, doc, source) {
|
|
400
|
+
const snapshot = encodeMarkdownText(doc.source);
|
|
401
|
+
return {
|
|
402
|
+
...state,
|
|
403
|
+
openDocument: {
|
|
404
|
+
...doc,
|
|
405
|
+
source
|
|
406
|
+
},
|
|
407
|
+
hasUnsavedChanges: true,
|
|
408
|
+
undoStack: pushSnapshot(state.undoStack, snapshot)
|
|
409
|
+
};
|
|
410
|
+
}
|
|
370
411
|
function wrongDocument(state, expected) {
|
|
371
412
|
return withStatus(state, "warning", `That action needs ${expected}; the open document is ${state.openDocument === void 0 ? "no document" : state.openDocument.format}`);
|
|
372
413
|
}
|
|
@@ -395,6 +436,11 @@ function drawingDocument(state) {
|
|
|
395
436
|
if (doc === void 0) return;
|
|
396
437
|
return doc.format === "odg" ? doc : void 0;
|
|
397
438
|
}
|
|
439
|
+
function markdownDocument(state) {
|
|
440
|
+
const doc = state.openDocument;
|
|
441
|
+
if (doc === void 0) return;
|
|
442
|
+
return doc.format === "markdown" ? doc : void 0;
|
|
443
|
+
}
|
|
398
444
|
function paragraphAt(doc, blockIndex) {
|
|
399
445
|
return doc.editor.paragraphs()[blockIndex];
|
|
400
446
|
}
|
|
@@ -771,6 +817,11 @@ function appReducer(state, action) {
|
|
|
771
817
|
action.vector.stroke = action.stroke;
|
|
772
818
|
});
|
|
773
819
|
}
|
|
820
|
+
case "SET_MARKDOWN_SOURCE": {
|
|
821
|
+
const doc = markdownDocument(state);
|
|
822
|
+
if (doc === void 0) return wrongDocument(state, "a markdown document");
|
|
823
|
+
return mutateMarkdown(state, doc, action.source);
|
|
824
|
+
}
|
|
774
825
|
case "APPEND_DIAGNOSTIC": return {
|
|
775
826
|
...state,
|
|
776
827
|
diagnostics: [...state.diagnostics, action.diagnostic]
|
|
@@ -802,9 +853,13 @@ function appReducer(state, action) {
|
|
|
802
853
|
if (doc.format === "odb" || doc.format === "pdf") return withStatus(state, "warning", `A ${doc.format} document is read-only, so it has no history to undo`);
|
|
803
854
|
const snapshot = state.undoStack.at(-1);
|
|
804
855
|
if (snapshot === void 0) return withStatus(state, "info", "There is nothing to undo");
|
|
856
|
+
const restored = doc.format === "markdown" ? {
|
|
857
|
+
...doc,
|
|
858
|
+
source: decodeMarkdownText(snapshot)
|
|
859
|
+
} : reopenEditable(doc, snapshot);
|
|
805
860
|
return withStatus({
|
|
806
861
|
...state,
|
|
807
|
-
openDocument:
|
|
862
|
+
openDocument: restored,
|
|
808
863
|
undoStack: state.undoStack.slice(0, -1),
|
|
809
864
|
hasUnsavedChanges: true
|
|
810
865
|
}, "info", "Undone");
|
|
@@ -2171,6 +2226,123 @@ function DocxBodyListScreen() {
|
|
|
2171
2226
|
return /* @__PURE__ */ jsx(ParagraphFamilyBodyList, { adapter });
|
|
2172
2227
|
}
|
|
2173
2228
|
//#endregion
|
|
2229
|
+
//#region src/tui/screens/editors/markdown/shared.ts
|
|
2230
|
+
function requireMarkdownDocument(openDocument) {
|
|
2231
|
+
if (openDocument?.format !== "markdown") throw new Error("A markdown editing screen rendered without an open markdown document; the app router only reaches this screen group from markdownLineList, which is only ever the root screen of an open markdown document.");
|
|
2232
|
+
return openDocument;
|
|
2233
|
+
}
|
|
2234
|
+
//#endregion
|
|
2235
|
+
//#region src/tui/screens/editors/markdown/line-list.tsx
|
|
2236
|
+
function MarkdownLineListScreen() {
|
|
2237
|
+
const state = useAppState();
|
|
2238
|
+
const dispatch = useAppDispatch();
|
|
2239
|
+
const doc = requireMarkdownDocument(state.openDocument);
|
|
2240
|
+
const query = state.searchQuery.trim().toLowerCase();
|
|
2241
|
+
const allLines = doc.source.split("\n").map((line, lineIndex) => ({
|
|
2242
|
+
line,
|
|
2243
|
+
lineIndex
|
|
2244
|
+
}));
|
|
2245
|
+
const lines = query === "" ? allLines : allLines.filter((entry) => entry.line.toLowerCase().includes(query));
|
|
2246
|
+
const { selectedIndex } = useNavigationInput({
|
|
2247
|
+
itemCount: lines.length,
|
|
2248
|
+
onSelect: (index) => {
|
|
2249
|
+
const entry = lines[index];
|
|
2250
|
+
if (entry === void 0) return;
|
|
2251
|
+
dispatch({
|
|
2252
|
+
type: "PUSH_SCREEN",
|
|
2253
|
+
screen: {
|
|
2254
|
+
kind: "markdownLineEditor",
|
|
2255
|
+
lineIndex: entry.lineIndex
|
|
2256
|
+
}
|
|
2257
|
+
});
|
|
2258
|
+
},
|
|
2259
|
+
onBack: () => {
|
|
2260
|
+
dispatch({ type: "POP_SCREEN" });
|
|
2261
|
+
},
|
|
2262
|
+
isActive: !anyOverlayOpen(state)
|
|
2263
|
+
});
|
|
2264
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
2265
|
+
flexDirection: "column",
|
|
2266
|
+
children: [/* @__PURE__ */ jsxs(Text, {
|
|
2267
|
+
bold: true,
|
|
2268
|
+
children: [
|
|
2269
|
+
"Lines (",
|
|
2270
|
+
lines.length,
|
|
2271
|
+
" of ",
|
|
2272
|
+
allLines.length,
|
|
2273
|
+
")"
|
|
2274
|
+
]
|
|
2275
|
+
}), /* @__PURE__ */ jsx(ListView, {
|
|
2276
|
+
items: lines,
|
|
2277
|
+
selectedIndex,
|
|
2278
|
+
emptyMessage: query === "" ? "This document has no lines." : `No lines match "${state.searchQuery}".`,
|
|
2279
|
+
renderItem: ({ line, lineIndex }, isSelected) => /* @__PURE__ */ jsxs(Text, {
|
|
2280
|
+
color: isSelected ? "cyan" : void 0,
|
|
2281
|
+
inverse: isSelected,
|
|
2282
|
+
children: [
|
|
2283
|
+
lineIndex + 1,
|
|
2284
|
+
": ",
|
|
2285
|
+
line === "" ? "(blank)" : line
|
|
2286
|
+
]
|
|
2287
|
+
})
|
|
2288
|
+
})]
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
//#endregion
|
|
2292
|
+
//#region src/tui/screens/editors/markdown/line-editor.tsx
|
|
2293
|
+
function MarkdownLineEditorScreen() {
|
|
2294
|
+
const state = useAppState();
|
|
2295
|
+
const dispatch = useAppDispatch();
|
|
2296
|
+
const screen = currentScreen(state);
|
|
2297
|
+
const doc = state.openDocument;
|
|
2298
|
+
if (screen.kind !== "markdownLineEditor") return /* @__PURE__ */ jsx(Text, {
|
|
2299
|
+
color: "red",
|
|
2300
|
+
children: "MarkdownLineEditorScreen rendered outside a markdownLineEditor screen."
|
|
2301
|
+
});
|
|
2302
|
+
if (doc?.format !== "markdown") return /* @__PURE__ */ jsx(Text, {
|
|
2303
|
+
color: "red",
|
|
2304
|
+
children: "MarkdownLineEditorScreen requires an open markdown document."
|
|
2305
|
+
});
|
|
2306
|
+
const lines = doc.source.split("\n");
|
|
2307
|
+
const line = lines[screen.lineIndex];
|
|
2308
|
+
if (line === void 0) return /* @__PURE__ */ jsxs(Text, {
|
|
2309
|
+
color: "red",
|
|
2310
|
+
children: [
|
|
2311
|
+
"There is no line at index ",
|
|
2312
|
+
screen.lineIndex,
|
|
2313
|
+
"."
|
|
2314
|
+
]
|
|
2315
|
+
});
|
|
2316
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
2317
|
+
flexDirection: "column",
|
|
2318
|
+
children: [
|
|
2319
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
2320
|
+
bold: true,
|
|
2321
|
+
children: ["Edit line ", screen.lineIndex + 1]
|
|
2322
|
+
}),
|
|
2323
|
+
/* @__PURE__ */ jsx(RunTextEditor, {
|
|
2324
|
+
initialText: line,
|
|
2325
|
+
onCommit: (text) => {
|
|
2326
|
+
const nextLines = [...lines];
|
|
2327
|
+
nextLines[screen.lineIndex] = text;
|
|
2328
|
+
dispatch({
|
|
2329
|
+
type: "SET_MARKDOWN_SOURCE",
|
|
2330
|
+
source: nextLines.join("\n")
|
|
2331
|
+
});
|
|
2332
|
+
dispatch({ type: "POP_SCREEN" });
|
|
2333
|
+
},
|
|
2334
|
+
onCancel: () => {
|
|
2335
|
+
dispatch({ type: "POP_SCREEN" });
|
|
2336
|
+
}
|
|
2337
|
+
}),
|
|
2338
|
+
/* @__PURE__ */ jsx(Text, {
|
|
2339
|
+
dimColor: true,
|
|
2340
|
+
children: "Enter to commit, Esc to discard"
|
|
2341
|
+
})
|
|
2342
|
+
]
|
|
2343
|
+
});
|
|
2344
|
+
}
|
|
2345
|
+
//#endregion
|
|
2174
2346
|
//#region src/tui/screens/editors/odb/shared.ts
|
|
2175
2347
|
function requireOdbDocument(openDocument) {
|
|
2176
2348
|
if (openDocument?.format !== "odb") throw new Error("An .odb browsing screen rendered without an open .odb document; the app router only reaches this screen group from odbTableList, which is only ever the root screen of an open .odb document.");
|
|
@@ -5093,7 +5265,7 @@ function defaultBasenameFor(purpose, document) {
|
|
|
5093
5265
|
const sourcePath = document?.path;
|
|
5094
5266
|
const stem = sourcePath === void 0 ? "untitled" : basename(sourcePath, extname(sourcePath));
|
|
5095
5267
|
if (purpose === "exportTarget") return `${stem}.pdf`;
|
|
5096
|
-
return document !== void 0 &&
|
|
5268
|
+
return document !== void 0 && isWritableDocument(document) ? `${stem}.${formatToExtension(document.format)}` : stem;
|
|
5097
5269
|
}
|
|
5098
5270
|
function titleFor(purpose) {
|
|
5099
5271
|
switch (purpose) {
|
|
@@ -5307,7 +5479,7 @@ function LauncherScreen() {
|
|
|
5307
5479
|
}),
|
|
5308
5480
|
/* @__PURE__ */ jsx(Text, {
|
|
5309
5481
|
dimColor: true,
|
|
5310
|
-
children: "A terminal editor for docx, pptx, odt, odp, ods, odg, odb and pdf."
|
|
5482
|
+
children: "A terminal editor for docx, pptx, odt, odp, ods, odg, markdown, odb and pdf."
|
|
5311
5483
|
}),
|
|
5312
5484
|
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
5313
5485
|
/* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Text, {
|
|
@@ -5410,7 +5582,7 @@ function NewDocumentPickerScreen() {
|
|
|
5410
5582
|
//#endregion
|
|
5411
5583
|
//#region src/tui/screens/save-as-prompt.tsx
|
|
5412
5584
|
function defaultDestinationFor(document, cwd) {
|
|
5413
|
-
const extension =
|
|
5585
|
+
const extension = isWritableDocument(document) ? formatToExtension(document.format) : "bin";
|
|
5414
5586
|
const suggestedName = document.path === void 0 ? `untitled.${extension}` : basename(document.path);
|
|
5415
5587
|
return join(cwd, suggestedName);
|
|
5416
5588
|
}
|
|
@@ -5493,6 +5665,8 @@ function ScreenBody({ screen }) {
|
|
|
5493
5665
|
case "shapeOrVectorDetail": return /* @__PURE__ */ jsx(OdgShapeOrVectorDetailScreen, {});
|
|
5494
5666
|
case "odbTableList": return /* @__PURE__ */ jsx(OdbTableListScreen, {});
|
|
5495
5667
|
case "odbTableRows": return /* @__PURE__ */ jsx(OdbTableRowsScreen, {});
|
|
5668
|
+
case "markdownLineList": return /* @__PURE__ */ jsx(MarkdownLineListScreen, {});
|
|
5669
|
+
case "markdownLineEditor": return /* @__PURE__ */ jsx(MarkdownLineEditorScreen, {});
|
|
5496
5670
|
case "pdfPageList": return /* @__PURE__ */ jsx(PdfPageListScreen, {});
|
|
5497
5671
|
case "pdfPageItems": return /* @__PURE__ */ jsx(PdfPageItemsScreen, {});
|
|
5498
5672
|
case "pdfItemDetail": return /* @__PURE__ */ jsx(PdfItemDetailScreen, {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "CLI and interactive Ink TUI for documents.js: every docx/pptx/odt/odp/ods/odg/odf/odm/odb conversion, bridge, and editor as a scriptable command or a terminal app.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"packageManager": "pnpm@11.6.0",
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"commander": "^15.0.0",
|
|
75
|
-
"documents.js": "^1.
|
|
75
|
+
"documents.js": "^1.60.0",
|
|
76
76
|
"ink": "^7.1.1",
|
|
77
77
|
"ink-text-input": "^6.0.0",
|
|
78
78
|
"odf.js": "^1.10.4",
|