From 5caced35784db7e16310cb41f62b819ef617f75f Mon Sep 17 00:00:00 2001
From: windingwind <33902321+windingwind@users.noreply.github.com>
Date: Thu, 12 Sep 2024 08:17:26 +0000
Subject: [PATCH] add: template editor snippets
---
addon/chrome/content/templateEditor.xhtml | 32 +++
addon/locale/en-US/templateEditor.ftl | 77 ++++++
addon/locale/it-IT/templateEditor.ftl | 77 ++++++
addon/locale/ru-RU/templateEditor.ftl | 77 ++++++
addon/locale/tr-TR/templateEditor.ftl | 77 ++++++
addon/locale/zh-CN/templateEditor.ftl | 77 ++++++
src/addon.ts | 1 +
src/modules/template/editorWindow.ts | 276 ++++++++++++++++++++++
8 files changed, 694 insertions(+)
diff --git a/addon/chrome/content/templateEditor.xhtml b/addon/chrome/content/templateEditor.xhtml
index ca08b64..b7f3d47 100644
--- a/addon/chrome/content/templateEditor.xhtml
+++ b/addon/chrome/content/templateEditor.xhtml
@@ -133,6 +133,37 @@
-moz-default-appearance: -moz-mac-help-button;
min-width: 0;
}
+ #snippets-container {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 4px;
+ padding: 4px;
+ }
+ .snippet {
+ border: var(--material-panedivider);
+ border-radius: 4px;
+ cursor: pointer;
+ font-size: 0.916666667em;
+ line-height: 1.272727273;
+ overflow: hidden;
+ padding: 1px 4px;
+ text-overflow: ellipsis;
+ white-space: pre;
+ box-sizing: border-box;
+ color: var(--fill-primary);
+ }
+ .snippet.syntax {
+ background-color: color-mix(in srgb, var(--accent-yellow) 50%, transparent 50%);
+ }
+ .snippet.expression {
+ background-color: color-mix(in srgb, var(--accent-green) 50%, transparent 50%);
+ }
+ .snippet.variable {
+ background-color: color-mix(in srgb, var(--accent-azure) 50%, transparent 50%);
+ }
+ .snippet:hover {
+ background-color: var(--fill-quinary);
+ }
+
{
+ const { editor, monaco } = addon.data.template.editor;
+ const selection = editor.getSelection();
+ const range = new monaco.Range(
+ selection.startLineNumber,
+ selection.startColumn,
+ selection.endLineNumber,
+ selection.endColumn,
+ );
+ const text = snippet.code;
+ editor.executeEdits("", [
+ {
+ range,
+ text,
+ forceMoveMarkers: true,
+ },
+ ]);
+ });
+ container.appendChild(button);
}
}
@@ -526,3 +581,224 @@ async function restoreTemplates(win: Window) {
}
await refresh();
}
+
+const snippetsStore = {
+ global: [
+ {
+ name: "useMarkdown",
+ code: "\n// @use-markdown\n",
+ type: "syntax",
+ },
+ {
+ name: "useRefresh",
+ code: "\n// @use-refresh\n",
+ type: "syntax",
+ },
+ {
+ name: "inlineScript",
+ code: "${ // write your script here }",
+ type: "syntax",
+ },
+ {
+ name: "multiLineScript",
+ code: "\n${{\n // write your script here\n}}$\n",
+ type: "syntax",
+ },
+ {
+ name: "dryRunFlag",
+ code: "_env.dryRun",
+ type: "variable",
+ },
+ ],
+ item: [
+ {
+ name: "itemBeforeLoop",
+ code: "\n// @beforeloop-begin\n\n// @beforeloop-end\n",
+ type: "syntax",
+ },
+ {
+ name: "itemInLoop",
+ code: "\n// @default-begin\n\n// @default-end\n",
+ type: "syntax",
+ },
+ {
+ name: "itemAfterLoop",
+ code: "\n// @afterloop-begin\n\n// @afterloop-end\n",
+ type: "syntax",
+ },
+ {
+ name: "itemItems",
+ code: "items",
+ type: "variable",
+ },
+ {
+ name: "itemItem",
+ code: "item",
+ type: "variable",
+ },
+ {
+ name: "itemTopItem",
+ code: "topItem",
+ type: "variable",
+ },
+ {
+ name: "itemTargetNoteItem",
+ code: "targetNoteItem",
+ type: "variable",
+ },
+ {
+ name: "itemCopyNoteImage",
+ code: "${copyNoteImage(...)}",
+ type: "expression",
+ },
+ {
+ name: "itemSharedObj",
+ code: "sharedObj",
+ type: "variable",
+ },
+ {
+ name: "itemFieldTitle",
+ code: '${topItem.getField("title")}',
+ type: "expression",
+ },
+ {
+ name: "itemFieldAbstract",
+ code: '${topItem.getField("abstractNote")}',
+ type: "expression",
+ },
+ {
+ name: "itemFieldCitKey",
+ code: '${topItem.getField("citationKey")}',
+ type: "expression",
+ },
+ {
+ name: "itemFieldDate",
+ code: '${topItem.getField("date")}',
+ type: "expression",
+ },
+ {
+ name: "itemFieldDOI",
+ code: '${topItem.getField("DOI")}',
+ type: "expression",
+ },
+ {
+ name: "itemFieldDOIURL",
+ code: `
+\${{
+const doi = topItem.getField("DOI");
+const url = topItem.getField("url");
+if (doi) {
+ return \`DOI: \${doi}\`;
+} else {
+ return \`URL: \${url}\`;
+}
+}}$
+`,
+ type: "expression",
+ },
+ {
+ name: "itemFieldAuthors",
+ code: '${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}',
+ type: "expression",
+ },
+ {
+ name: "itemFieldJournal",
+ code: '${topItem.getField("publicationTitle")}',
+ type: "expression",
+ },
+ {
+ name: "itemFieldTitleTranslation",
+ code: '${topItem.getField("titleTranslation")}',
+ type: "expression",
+ },
+ ],
+ text: [
+ {
+ name: "textTargetNoteItem",
+ code: "targetNoteItem",
+ type: "variable",
+ },
+ {
+ name: "textSharedObj",
+ code: "sharedObj",
+ type: "variable",
+ },
+ ],
+ QuickInsertV2: [
+ {
+ name: "quickInsertLink",
+ code: "link",
+ type: "variable",
+ },
+ {
+ name: "quickInsertLinkText",
+ code: "linkText",
+ type: "variable",
+ },
+ {
+ name: "quickInsertSubNoteItem",
+ code: "subNoteItem",
+ type: "variable",
+ },
+ {
+ name: "quickInsertNoteItem",
+ code: "noteItem",
+ type: "variable",
+ },
+ ],
+ QuickImportV2: [
+ {
+ name: "quickImportLink",
+ code: "link",
+ type: "variable",
+ },
+ {
+ name: "quickImportNoteItem",
+ code: "noteItem",
+ type: "variable",
+ },
+ ],
+ QuickNoteV5: [
+ {
+ name: "quickNoteAnnotationItem",
+ code: "annotationItem",
+ type: "variable",
+ },
+ {
+ name: "quickNoteTopItem",
+ code: "topItem",
+ type: "variable",
+ },
+ {
+ name: "quickNoteNoteItem",
+ code: "noteItem",
+ type: "variable",
+ },
+ ],
+ ExportMDFileNameV2: [
+ {
+ name: "exportMDFileNameNoteItem",
+ code: "noteItem",
+ type: "variable",
+ },
+ ],
+ ExportMDFileHeaderV2: [
+ {
+ name: "exportMDFileHeaderNoteItem",
+ code: "noteItem",
+ type: "variable",
+ },
+ ],
+ ExportMDFileContent: [
+ {
+ name: "exportMDFileContentNoteItem",
+ code: "noteItem",
+ type: "variable",
+ },
+ {
+ name: "exportMDFileContentMDContent",
+ code: "mdContent",
+ type: "variable",
+ },
+ ],
+};