@ncukondo/reference-manager 0.13.3 → 0.13.4
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/chunks/{action-menu-Dc3wCGod.js → action-menu-De64T89o.js} +3 -3
- package/dist/chunks/{action-menu-Dc3wCGod.js.map → action-menu-De64T89o.js.map} +1 -1
- package/dist/chunks/{index-C0TB_ha0.js → index-4KSTJ3rp.js} +26 -15
- package/dist/chunks/{index-C0TB_ha0.js.map → index-4KSTJ3rp.js.map} +1 -1
- package/dist/chunks/{index-CU6eBQaB.js → index-DNGailHu.js} +21 -13
- package/dist/chunks/{index-CU6eBQaB.js.map → index-DNGailHu.js.map} +1 -1
- package/dist/cli.js +2 -2
- package/dist/features/operations/add.d.ts +2 -2
- package/dist/features/operations/add.d.ts.map +1 -1
- package/dist/features/operations/cite.d.ts +4 -0
- package/dist/features/operations/cite.d.ts.map +1 -1
- package/dist/features/operations/operations-library.d.ts +3 -1
- package/dist/features/operations/operations-library.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as formatBibtex } from "./index-
|
|
2
|
-
import { f as formatBibliographyCSL } from "./index-
|
|
1
|
+
import { f as formatBibtex } from "./index-DNGailHu.js";
|
|
2
|
+
import { f as formatBibliographyCSL } from "./index-4KSTJ3rp.js";
|
|
3
3
|
const ACTION_CHOICES = [
|
|
4
4
|
{ name: "output-ids", message: "Output IDs (citation keys)", value: "output-ids" },
|
|
5
5
|
{ name: "output-csl-json", message: "Output as CSL-JSON", value: "output-csl-json" },
|
|
@@ -116,4 +116,4 @@ export {
|
|
|
116
116
|
runActionMenu,
|
|
117
117
|
runStyleSelectPrompt
|
|
118
118
|
};
|
|
119
|
-
//# sourceMappingURL=action-menu-
|
|
119
|
+
//# sourceMappingURL=action-menu-De64T89o.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-menu-
|
|
1
|
+
{"version":3,"file":"action-menu-De64T89o.js","sources":["../../src/features/interactive/action-menu.ts"],"sourcesContent":["/**\n * Action menu for interactive search mode.\n * Allows users to perform actions on selected references.\n */\n\nimport type { CslItem } from \"../../core/csl-json/types.js\";\nimport { formatBibliographyCSL, formatBibtex } from \"../format/index.js\";\n\n/**\n * Action types available in the action menu.\n */\nexport type ActionType =\n | \"output-ids\"\n | \"output-csl-json\"\n | \"output-bibtex\"\n | \"cite-apa\"\n | \"cite-choose\"\n | \"cancel\";\n\n/**\n * Result from action menu selection.\n */\nexport interface ActionMenuResult {\n /** Selected action type */\n action: ActionType;\n /** Generated output (empty for cancel) */\n output: string;\n /** Whether the prompt was cancelled */\n cancelled: boolean;\n}\n\n/**\n * Result from style selection prompt.\n */\nexport interface StyleSelectResult {\n /** Selected style (undefined if cancelled) */\n style?: string;\n /** Whether the prompt was cancelled */\n cancelled: boolean;\n}\n\n/**\n * Choice definition for Enquirer Select prompt.\n */\ninterface SelectChoice {\n name: string;\n message: string;\n value: ActionType | string;\n}\n\n/**\n * Available action choices for the action menu.\n */\nexport const ACTION_CHOICES: SelectChoice[] = [\n { name: \"output-ids\", message: \"Output IDs (citation keys)\", value: \"output-ids\" },\n { name: \"output-csl-json\", message: \"Output as CSL-JSON\", value: \"output-csl-json\" },\n { name: \"output-bibtex\", message: \"Output as BibTeX\", value: \"output-bibtex\" },\n { name: \"cite-apa\", message: \"Generate citation (APA)\", value: \"cite-apa\" },\n { name: \"cite-choose\", message: \"Generate citation (choose style)\", value: \"cite-choose\" },\n { name: \"cancel\", message: \"Cancel\", value: \"cancel\" },\n];\n\n/**\n * Available style choices for citation style selection.\n * Uses BUILTIN_STYLES from config/csl-styles.ts\n */\nexport const STYLE_CHOICES: SelectChoice[] = [\n { name: \"apa\", message: \"APA\", value: \"apa\" },\n { name: \"vancouver\", message: \"Vancouver\", value: \"vancouver\" },\n { name: \"harvard\", message: \"Harvard\", value: \"harvard\" },\n];\n\n/**\n * Run the style selection prompt.\n */\n\n/**\n * Generate output for the given action and items.\n */\nfunction generateOutput(action: ActionType, items: CslItem[], style = \"apa\"): string {\n switch (action) {\n case \"output-ids\":\n return items.map((item) => item.id).join(\"\\n\");\n\n case \"output-csl-json\":\n return JSON.stringify(items, null, 2);\n\n case \"output-bibtex\":\n return formatBibtex(items);\n\n case \"cite-apa\":\n return formatBibliographyCSL(items, { style: \"apa\" });\n\n case \"cite-choose\":\n return formatBibliographyCSL(items, { style });\n\n case \"cancel\":\n return \"\";\n\n default:\n return \"\";\n }\n}\n\n/**\n * Process the selected action and generate result.\n */\nasync function processAction(action: ActionType, items: CslItem[]): Promise<ActionMenuResult> {\n // Handle cite-choose: prompt for style first\n if (action === \"cite-choose\") {\n const styleResult = await runStyleSelectPrompt();\n if (styleResult.cancelled) {\n return {\n action: \"cancel\",\n output: \"\",\n cancelled: true,\n };\n }\n return {\n action,\n output: generateOutput(action, items, styleResult.style),\n cancelled: false,\n };\n }\n\n // Handle cancel\n if (action === \"cancel\") {\n return {\n action,\n output: \"\",\n cancelled: true,\n };\n }\n\n // Handle other actions\n return {\n action,\n output: generateOutput(action, items),\n cancelled: false,\n };\n}\n\nexport async function runStyleSelectPrompt(): Promise<StyleSelectResult> {\n // Dynamic import to allow mocking in tests\n // enquirer is a CommonJS module, so we must use default import\n const enquirer = await import(\"enquirer\");\n const Select = (enquirer.default as unknown as Record<string, unknown>).Select as new (\n options: Record<string, unknown>\n ) => { run(): Promise<string> };\n\n const promptOptions = {\n name: \"style\",\n message: \"Select citation style:\",\n choices: STYLE_CHOICES,\n };\n\n try {\n const prompt = new Select(promptOptions);\n const result = (await prompt.run()) as string;\n\n return {\n style: result,\n cancelled: false,\n };\n } catch (error) {\n // Enquirer throws an empty string when cancelled\n if (error === \"\" || (error instanceof Error && error.message === \"\")) {\n return {\n cancelled: true,\n };\n }\n throw error;\n }\n}\n\n/**\n * Run the action menu for selected references.\n *\n * @param items - Selected references\n * @returns Action result with output\n */\nexport async function runActionMenu(items: CslItem[]): Promise<ActionMenuResult> {\n // Dynamic import to allow mocking in tests\n // enquirer is a CommonJS module, so we must use default import\n const enquirer = await import(\"enquirer\");\n const Select = (enquirer.default as unknown as Record<string, unknown>).Select as new (\n options: Record<string, unknown>\n ) => { run(): Promise<string> };\n\n const count = items.length;\n const refWord = count === 1 ? \"reference\" : \"references\";\n const message = `Action for ${count} selected ${refWord}:`;\n\n const promptOptions = {\n name: \"action\",\n message,\n choices: ACTION_CHOICES,\n };\n\n try {\n const prompt = new Select(promptOptions);\n const action = (await prompt.run()) as ActionType;\n\n return processAction(action, items);\n } catch (error) {\n // Enquirer throws an empty string when cancelled\n if (error === \"\" || (error instanceof Error && error.message === \"\")) {\n return {\n action: \"cancel\",\n output: \"\",\n cancelled: true,\n };\n }\n throw error;\n }\n}\n"],"names":[],"mappings":";;AAqDO,MAAM,iBAAiC;AAAA,EAC5C,EAAE,MAAM,cAAc,SAAS,8BAA8B,OAAO,aAAA;AAAA,EACpE,EAAE,MAAM,mBAAmB,SAAS,sBAAsB,OAAO,kBAAA;AAAA,EACjE,EAAE,MAAM,iBAAiB,SAAS,oBAAoB,OAAO,gBAAA;AAAA,EAC7D,EAAE,MAAM,YAAY,SAAS,2BAA2B,OAAO,WAAA;AAAA,EAC/D,EAAE,MAAM,eAAe,SAAS,oCAAoC,OAAO,cAAA;AAAA,EAC3E,EAAE,MAAM,UAAU,SAAS,UAAU,OAAO,SAAA;AAC9C;AAMO,MAAM,gBAAgC;AAAA,EAC3C,EAAE,MAAM,OAAO,SAAS,OAAO,OAAO,MAAA;AAAA,EACtC,EAAE,MAAM,aAAa,SAAS,aAAa,OAAO,YAAA;AAAA,EAClD,EAAE,MAAM,WAAW,SAAS,WAAW,OAAO,UAAA;AAChD;AASA,SAAS,eAAe,QAAoB,OAAkB,QAAQ,OAAe;AACnF,UAAQ,QAAA;AAAA,IACN,KAAK;AACH,aAAO,MAAM,IAAI,CAAC,SAAS,KAAK,EAAE,EAAE,KAAK,IAAI;AAAA,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AAAA,MAAA;AAAA,IAEf;AACA,UAAM;AAAA,EACR;AACF;AAQA,eAAsB,cAAc,OAA6C;AAG/E,QAAM,WAAW,MAAM,OAAO,UAAU;AACxC,QAAM,SAAU,SAAS,QAA+C;AAIxE,QAAM,QAAQ,MAAM;AACpB,QAAM,UAAU,UAAU,IAAI,cAAc;AAC5C,QAAM,UAAU,cAAc,KAAK,aAAa,OAAO;AAEvD,QAAM,gBAAgB;AAAA,IACpB,MAAM;AAAA,IACN;AAAA,IACA,SAAS;AAAA,EAAA;AAGX,MAAI;AACF,UAAM,SAAS,IAAI,OAAO,aAAa;AACvC,UAAM,SAAU,MAAM,OAAO,IAAA;AAE7B,WAAO,cAAc,QAAQ,KAAK;AAAA,EACpC,SAAS,OAAO;AAEd,QAAI,UAAU,MAAO,iBAAiB,SAAS,MAAM,YAAY,IAAK;AACpE,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,WAAW;AAAA,MAAA;AAAA,IAEf;AACA,UAAM;AAAA,EACR;AACF;"}
|
|
@@ -1508,8 +1508,10 @@ async function processImportResult(result, existingItems, addedIds, force, libra
|
|
|
1508
1508
|
}
|
|
1509
1509
|
}
|
|
1510
1510
|
const allExistingIds = /* @__PURE__ */ new Set([...existingItems.map((i) => i.id), ...addedIds]);
|
|
1511
|
-
const
|
|
1512
|
-
const
|
|
1511
|
+
const originalId = item.id?.trim() || "";
|
|
1512
|
+
const hasOriginalId = originalId.length > 0;
|
|
1513
|
+
const baseId = hasOriginalId ? originalId : generateId(item);
|
|
1514
|
+
const { id, changed } = resolveIdCollision(baseId, allExistingIds);
|
|
1513
1515
|
const finalItem = { ...item, id };
|
|
1514
1516
|
const addedToLibrary = await library.add(finalItem);
|
|
1515
1517
|
addedIds.add(id);
|
|
@@ -1520,9 +1522,9 @@ async function processImportResult(result, existingItems, addedIds, force, libra
|
|
|
1520
1522
|
uuid,
|
|
1521
1523
|
title: typeof finalItem.title === "string" ? finalItem.title : ""
|
|
1522
1524
|
};
|
|
1523
|
-
if (changed) {
|
|
1525
|
+
if (hasOriginalId && changed) {
|
|
1524
1526
|
addedItem.idChanged = true;
|
|
1525
|
-
addedItem.originalId =
|
|
1527
|
+
addedItem.originalId = originalId;
|
|
1526
1528
|
}
|
|
1527
1529
|
return { type: "added", item: addedItem };
|
|
1528
1530
|
}
|
|
@@ -1633,19 +1635,28 @@ async function generateCitationForIdentifier(library, identifier, idType, inText
|
|
|
1633
1635
|
};
|
|
1634
1636
|
}
|
|
1635
1637
|
async function citeReferences(library, options) {
|
|
1636
|
-
const {
|
|
1638
|
+
const {
|
|
1639
|
+
identifiers,
|
|
1640
|
+
idType = "id",
|
|
1641
|
+
inText = false,
|
|
1642
|
+
style,
|
|
1643
|
+
cslFile,
|
|
1644
|
+
defaultStyle,
|
|
1645
|
+
cslDirectory,
|
|
1646
|
+
locale,
|
|
1647
|
+
format
|
|
1648
|
+
} = options;
|
|
1637
1649
|
const results = [];
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
}
|
|
1650
|
+
const resolution = resolveStyle({
|
|
1651
|
+
...cslFile !== void 0 && { cslFile },
|
|
1652
|
+
...style !== void 0 && { style },
|
|
1653
|
+
...defaultStyle !== void 0 && { defaultStyle },
|
|
1654
|
+
...cslDirectory !== void 0 && { cslDirectory }
|
|
1655
|
+
});
|
|
1645
1656
|
for (const identifier of identifiers) {
|
|
1646
1657
|
const result = await generateCitationForIdentifier(library, identifier, idType, inText, {
|
|
1647
|
-
style:
|
|
1648
|
-
styleXml,
|
|
1658
|
+
style: resolution.styleName,
|
|
1659
|
+
styleXml: resolution.styleXml,
|
|
1649
1660
|
locale,
|
|
1650
1661
|
format
|
|
1651
1662
|
});
|
|
@@ -1990,4 +2001,4 @@ export {
|
|
|
1990
2001
|
startServerWithFileWatcher as s,
|
|
1991
2002
|
updateReference as u
|
|
1992
2003
|
};
|
|
1993
|
-
//# sourceMappingURL=index-
|
|
2004
|
+
//# sourceMappingURL=index-4KSTJ3rp.js.map
|