refactor: follow addon template v0.0.11

This commit is contained in:
xiangyu 2023-01-04 18:10:38 +08:00
parent bd91e60296
commit fc391f9943
38 changed files with 688 additions and 648 deletions

View File

@ -287,7 +287,7 @@ Required Variable: noteItem/subNoteItem.
```js
<p>
<a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)}">
<a href="${Zotero.BetterNotes.knowledge.getNoteLink(noteItem)}">
${noteItem.key}
</a>
</p>

View File

@ -12,9 +12,9 @@
<dialog id="betternotes-export-dialog" windowtype="betternotes-export"
title="&zotero.__addonRef__.export.title;" orient="vertical" width="300" height="300"
buttons="cancel,accept" ondialogaccept="Zotero.Knowledge4Zotero.NoteExportWindow.doAccept();"
onload="Zotero.Knowledge4Zotero.NoteExportWindow.doLoad(window);"
onunload="Zotero.Knowledge4Zotero.NoteExportWindow.doUnload();"
buttons="cancel,accept" ondialogaccept="Zotero.BetterNotes.NoteExportWindow.doAccept();"
onload="Zotero.BetterNotes.NoteExportWindow.doLoad(window);"
onunload="Zotero.BetterNotes.NoteExportWindow.doUnload();"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml" style="padding:2em"
persist="screenX screenY width height">
@ -27,7 +27,7 @@
<checkbox id="embedLink"
tooltiptext="&zotero.__addonRef__.export.cannotworkwith.label;&zotero.__addonRef__.export.singlefile.enable.label;"
checked="true"
oncommand="Zotero.Knowledge4Zotero.NoteExportWindow.doUpdate(event)" />
oncommand="Zotero.BetterNotes.NoteExportWindow.doUpdate(event)" />
<label value="&zotero.__addonRef__.export.link.enable.label;"
tooltiptext="&zotero.__addonRef__.export.cannotworkwith.label;&zotero.__addonRef__.export.singlefile.enable.label;" />
</row>
@ -42,14 +42,14 @@
<rows flex="1">
<row>
<checkbox id="exportMD" checked="true"
oncommand="Zotero.Knowledge4Zotero.NoteExportWindow.doUpdate(event)" />
oncommand="Zotero.BetterNotes.NoteExportWindow.doUpdate(event)" />
<label value="&zotero.__addonRef__.export.file.enable.label;" />
</row>
<row>
<checkbox id="exportSubMD"
tooltiptext="&zotero.__addonRef__.export.cannotworkwith.label;&zotero.__addonRef__.export.link.enable.label;"
checked="false"
oncommand="Zotero.Knowledge4Zotero.NoteExportWindow.doUpdate(event)" />
oncommand="Zotero.BetterNotes.NoteExportWindow.doUpdate(event)" />
<label value="&zotero.__addonRef__.export.singlefile.enable.label;"
tooltiptext="&zotero.__addonRef__.export.cannotworkwith.label;&zotero.__addonRef__.export.link.enable.label;" />
</row>
@ -57,7 +57,7 @@
<checkbox id="exportYAMLHeader"
tooltiptext="&zotero.__addonRef__.export.cannotworkwith.label;&zotero.__addonRef__.export.yaml.enable.label;"
checked="true"
oncommand="Zotero.Knowledge4Zotero.NoteExportWindow.doUpdate(event)" />
oncommand="Zotero.BetterNotes.NoteExportWindow.doUpdate(event)" />
<label value="&zotero.__addonRef__.export.yaml.enable.label;"
tooltiptext="&zotero.__addonRef__.export.cannotworkwith.label;&zotero.__addonRef__.export.link.enable.label;" />
</row>
@ -65,7 +65,7 @@
<checkbox id="exportAutoSync"
tooltiptext="&zotero.__addonRef__.export.workwith.label;&zotero.__addonRef__.export.singlefile.enable.label;"
checked="false"
oncommand="Zotero.Knowledge4Zotero.NoteExportWindow.doUpdate(event)" />
oncommand="Zotero.BetterNotes.NoteExportWindow.doUpdate(event)" />
<label value="&zotero.__addonRef__.export.enableautosync.enable.label;"
tooltiptext="Only work with &zotero.__addonRef__.export.singlefile.enable.label;" />
</row>

View File

@ -25,30 +25,30 @@
</keyset>
<commandset id="mainCommandSet">
<command id="cmd_new_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'createWorkspace'});" />
<command id="cmd_open_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'selectMainNote'});" />
<command id="cmd_open_betternotesWindow" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openWorkspaceInWindow'});" />
<command id="cmd_export_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'export', content: {editorInstance: {_item: false}}});" />
<command id="cmd_sync_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'sync'});" />
<command id="cmd_sync_manager_betternotes" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.openSyncList();" />
<command id="cmd_editTemplate_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'editTemplate'});" />
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'importLink'});" />
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'updateLink'});" /> -->
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'updateAutoAnnotation'});" />
<command id="cmd_convertmd_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'convertMD'});" />
<command id="cmd_convertasciidoc_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'convertAsciiDoc'});" />
<command id="cmd_treeview_betternotes" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(1);" />
<command id="cmd_mindmap_betternotes" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(2);" />
<command id="cmd_bubblemap_betternotes" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(3);" />
<command id="cmd_guide_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openUserGuide'});" />
<command id="cmd_about_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openAbout'});" />
<command id="cmd_new_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'createWorkspace'});" />
<command id="cmd_open_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'selectMainNote'});" />
<command id="cmd_open_betternotesWindow" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'openWorkspaceInWindow'});" />
<command id="cmd_export_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'export', content: {editorInstance: {_item: false}}});" />
<command id="cmd_sync_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'sync'});" />
<command id="cmd_sync_manager_betternotes" oncommand="Zotero.BetterNotes.SyncListWindow.openSyncList();" />
<command id="cmd_editTemplate_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'editTemplate'});" />
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'importLink'});" />
<command id="cmd_updatelink_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'updateLink'});" /> -->
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'updateAutoAnnotation'});" />
<command id="cmd_convertmd_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'convertMD'});" />
<command id="cmd_convertasciidoc_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'convertAsciiDoc'});" />
<command id="cmd_treeview_betternotes" oncommand="Zotero.BetterNotes.WorkspaceOutline.switchView(1);" />
<command id="cmd_mindmap_betternotes" oncommand="Zotero.BetterNotes.WorkspaceOutline.switchView(2);" />
<command id="cmd_bubblemap_betternotes" oncommand="Zotero.BetterNotes.WorkspaceOutline.switchView(3);" />
<command id="cmd_guide_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'openUserGuide'});" />
<command id="cmd_about_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'openAbout'});" />
</commandset>
<popup id="zotero-itemmenu">
<menuseparator />
<menuitem id="zotero-itemmenu-__addonRef__-setMainNote" class="menuitem-iconic popup-type-single-note" label="&zotero.__addonRef__.itemmenu.setMainNote.label;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'setMainNote', content: {params: {itemID: ZoteroPane.getSelectedItems()[0].id}}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-exportNote" class="menuitem-iconic popup-type-single" label="&zotero.__addonRef__.itemmenu.exportNote.label;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'exportNotes', content: {}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-exportNotes" class="menuitem-iconic popup-type-multiple" label="&zotero.__addonRef__.itemmenu.exportNotes.label;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'exportNotes', content: {}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-setMainNote" class="menuitem-iconic popup-type-single-note" label="&zotero.__addonRef__.itemmenu.setMainNote.label;" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'setMainNote', content: {params: {itemID: ZoteroPane.getSelectedItems()[0].id}}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-exportNote" class="menuitem-iconic popup-type-single" label="&zotero.__addonRef__.itemmenu.exportNote.label;" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent.bind(Zotero.BetterNotes.ZoteroEvents)({type: 'exportNotes', content: {}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
<menuitem id="zotero-itemmenu-__addonRef__-exportNotes" class="menuitem-iconic popup-type-multiple" label="&zotero.__addonRef__.itemmenu.exportNotes.label;" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent.bind(Zotero.BetterNotes.ZoteroEvents)({type: 'exportNotes', content: {}})" style="list-style-image: url('chrome://__addonRef__/skin/favicon.png');" />
</popup>
<menupopup id="menu_FilePopup">
@ -63,14 +63,14 @@
<menupopup id="menu_EditPopup">
<menu id="menu_insertTextTemplate_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.insertTextTemplate;">
<menupopup id="menu_insertTextTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Text');" />
<menupopup id="menu_insertTextTemplatePopup" onpopupshowing="Zotero.BetterNotes.ZoteroViews.updateTemplateMenu('Text');" />
</menu>
<menu id="menu_insertItemTemplate_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.insertItemTemplate;">
<menupopup id="menu_insertItemTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Item');" />
<menupopup id="menu_insertItemTemplatePopup" onpopupshowing="Zotero.BetterNotes.ZoteroViews.updateTemplateMenu('Item');" />
</menu>
<menuitem id="menu_editTemplate_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.editTemplate;" command="cmd_editTemplate_betternotes" />
<menu id="menu_citeSetting_betternotes" class="menu-type-betternotes menu-betternotes" label="&zotero.__addonRef__.workspace.menu.citeSetting;">
<menupopup id="menu_citeSettingPopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateCitationStyleMenu();" />
<menupopup id="menu_citeSettingPopup" onpopupshowing="Zotero.BetterNotes.ZoteroViews.updateCitationStyleMenu();" />
</menu>
<!-- <menuitem id="menu_importlink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.importLink;" command="cmd_importlink_betternotes" />
<menuitem id="menu_updatelink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.updateLink;" command="cmd_updatelink_betternotes" /> -->
@ -95,10 +95,10 @@
<menupopup id="menu_HelpPopup">
<menuseparator class="menu-betternotes" />
<menu id="menu_ocrsetting_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRSetting;">
<menupopup id="menu_ocrsettingpopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateOCRStyleMenu();">
<menuitem id="menu_ocr_bing_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRBing;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'setOCREngine', content: {params: {engine: 'bing'}}})" type="checkbox" />
<menuitem id="menu_ocr_mathpix_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRMathpix;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'setOCREngine', content: {params: {engine: 'mathpix'}}})" type="checkbox" />
<menuitem id="menu_ocr_xunfei_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRXunfei;" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent.bind(Zotero.Knowledge4Zotero.ZoteroEvents)({type: 'setOCREngine', content: {params: {engine: 'xunfei'}}})" type="checkbox" />
<menupopup id="menu_ocrsettingpopup" onpopupshowing="Zotero.BetterNotes.ZoteroViews.updateOCRStyleMenu();">
<menuitem id="menu_ocr_bing_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRBing;" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent.bind(Zotero.BetterNotes.ZoteroEvents)({type: 'setOCREngine', content: {params: {engine: 'bing'}}})" type="checkbox" />
<menuitem id="menu_ocr_mathpix_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRMathpix;" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent.bind(Zotero.BetterNotes.ZoteroEvents)({type: 'setOCREngine', content: {params: {engine: 'mathpix'}}})" type="checkbox" />
<menuitem id="menu_ocr_xunfei_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.OCRXunfei;" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent.bind(Zotero.BetterNotes.ZoteroEvents)({type: 'setOCREngine', content: {params: {engine: 'xunfei'}}})" type="checkbox" />
</menupopup>
</menu>
<menuitem id="menu_guide_betternotes menu-betternotes" label="&zotero.__addonRef__.workspace.menu.guide;" command="cmd_guide_betternotes" />

View File

@ -11,7 +11,7 @@
%knowledgeDTD;
]>
<dialog id="betternotes-sync-dialog" windowtype="betternotes-sync" title="&zotero.__addonRef__.sync.title;" orient="vertical" width="300" height="300" buttons="cancel,accept,help" ondialogaccept="Zotero.Knowledge4Zotero.SyncInfoWindow.doAccept();" ondialoghelp="Zotero.Knowledge4Zotero.SyncInfoWindow.doExport();" onload="Zotero.Knowledge4Zotero.SyncInfoWindow.doLoad(window);" onunload="Zotero.Knowledge4Zotero.SyncInfoWindow.doUnload();" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml" style="padding:2em" persist="screenX screenY width height" buttonlabelhelp="&zotero.__addonRef__.sync.export.label;">
<dialog id="betternotes-sync-dialog" windowtype="betternotes-sync" title="&zotero.__addonRef__.sync.title;" orient="vertical" width="300" height="300" buttons="cancel,accept,help" ondialogaccept="Zotero.BetterNotes.SyncInfoWindow.doAccept();" ondialoghelp="Zotero.BetterNotes.SyncInfoWindow.doExport();" onload="Zotero.BetterNotes.SyncInfoWindow.doLoad(window);" onunload="Zotero.BetterNotes.SyncInfoWindow.doUnload();" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml" style="padding:2em" persist="screenX screenY width height" buttonlabelhelp="&zotero.__addonRef__.sync.export.label;">
<script src="chrome://zotero/content/include.js" />
<vbox flex="1">
<label value="&zotero.__addonRef__.sync.path.label;" />
@ -20,8 +20,8 @@
<label id="__addonRef__-sync-lastsync" />
<hbox>
<checkbox id="__addonRef__-sync-enable" label="&zotero.__addonRef__.sync.enable.label;" checked="true" />
<button flex="0" label="&zotero.__addonRef__.sync.dosync.label;" oncommand="Zotero.Knowledge4Zotero.SyncController.doSync(null, true)"></button>
<button flex="0" label="&zotero.__addonRef__.sync.synclist.label;" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.openSyncList()"></button>
<button flex="0" label="&zotero.__addonRef__.sync.dosync.label;" oncommand="Zotero.BetterNotes.SyncController.doSync(null, true)"></button>
<button flex="0" label="&zotero.__addonRef__.sync.synclist.label;" oncommand="Zotero.BetterNotes.SyncListWindow.openSyncList()"></button>
</hbox>
</vbox>
</dialog>

View File

@ -16,7 +16,7 @@
%knowledgeDTD;
]>
<window id="zotero-knowledge-sync-list" onload="Zotero.Knowledge4Zotero.SyncListWindow.doLoad(window);" onresize="Zotero.Knowledge4Zotero.SyncListWindow.doUpdate();" orient="vertical" width="600" height="350" title="&zotero.__addonRef__.syncList.title;" persist="screenX screenY width height" windowtype="zotero:knowledgeSyncList" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<window id="zotero-knowledge-sync-list" onload="Zotero.BetterNotes.SyncListWindow.doLoad(window);" onresize="Zotero.BetterNotes.SyncListWindow.doUpdate();" orient="vertical" width="600" height="350" title="&zotero.__addonRef__.syncList.title;" persist="screenX screenY width height" windowtype="zotero:knowledgeSyncList" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<script src="chrome://zotero/content/include.js" />
<keyset>
@ -29,7 +29,7 @@
<command id="cmd_unselectall" oncommand="window.document.getElementById('sync-list').clearSelection();" />
<vbox flex="1">
<listbox id="sync-list" flex="1" seltype="multiple" onselect="Zotero.Knowledge4Zotero.SyncListWindow.onSelect();">
<listbox id="sync-list" flex="1" seltype="multiple" onselect="Zotero.BetterNotes.SyncListWindow.onSelect();">
<listhead>
<listheader id="icon" label="#" flex="1" />
<listheader id="notename" label="&zotero.__addonRef__.syncList.notename.label;" flex="1" />
@ -41,11 +41,11 @@
</listcols>
</listbox>
<hbox flex="0">
<button id="doupdate" label="&zotero.__addonRef__.syncList.doupdate.label;" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.doUpdate();"></button>
<button id="changesyncperiod" label="&zotero.__addonRef__.syncList.changesyncperiod.label;" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.changeSyncPeriod();"></button>
<button id="dosync" label="&zotero.__addonRef__.syncList.dosync.label;" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.doSync();"></button>
<button id="changesync" label="&zotero.__addonRef__.syncList.changesync.label;" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.changeSync();"></button>
<button id="removesync" label="&zotero.__addonRef__.syncList.removesync.label;" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.removeSync();"></button>
<button id="doupdate" label="&zotero.__addonRef__.syncList.doupdate.label;" oncommand="Zotero.BetterNotes.SyncListWindow.doUpdate();"></button>
<button id="changesyncperiod" label="&zotero.__addonRef__.syncList.changesyncperiod.label;" oncommand="Zotero.BetterNotes.SyncListWindow.changeSyncPeriod();"></button>
<button id="dosync" label="&zotero.__addonRef__.syncList.dosync.label;" oncommand="Zotero.BetterNotes.SyncListWindow.doSync();"></button>
<button id="changesync" label="&zotero.__addonRef__.syncList.changesync.label;" oncommand="Zotero.BetterNotes.SyncListWindow.changeSync();"></button>
<button id="removesync" label="&zotero.__addonRef__.syncList.removesync.label;" oncommand="Zotero.BetterNotes.SyncListWindow.removeSync();"></button>
</hbox>
</vbox>

View File

@ -16,7 +16,7 @@
%knowledgeDTD;
]>
<window id="zotero-knowledge-template-editor" onload="Zotero.Knowledge4Zotero.TemplateWindow.initTemplates(window);" orient="vertical" width="600" height="350" title="&zotero.__addonRef__.template.title;" persist="screenX screenY width height" windowtype="zotero:knowledgeTemplateEditor" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<window id="zotero-knowledge-template-editor" onload="Zotero.BetterNotes.TemplateWindow.initTemplates(window);" orient="vertical" width="600" height="350" title="&zotero.__addonRef__.template.title;" persist="screenX screenY width height" windowtype="zotero:knowledgeTemplateEditor" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<script src="chrome://zotero/content/include.js" />
<keyset>
@ -24,14 +24,14 @@
<key id="key_help" key="H" modifiers="accel" command="cmd_help" />
<key id="key_close" key="W" modifiers="accel" command="cmd_close" />
</keyset>
<command id="cmd_save" oncommand="Zotero.Knowledge4Zotero.TemplateWindow.saveSelectedTemplate();" />
<command id="cmd_save" oncommand="Zotero.BetterNotes.TemplateWindow.saveSelectedTemplate();" />
<command id="cmd_help" oncommand="Zotero.launchURL('https://github.com/windingwind/zotero-better-notes/blob/master/Template.md');" />
<command id="cmd_more" oncommand="Zotero.launchURL('https://github.com/windingwind/zotero-better-notes/discussions/categories/note-templates');" />
<command id="cmd_close" oncommand="window.close();" />
<hbox flex="1">
<vbox id="template-container" flex="1" minwidth="400px">
<listbox id="template-list" flex="1" seltype="single" onselect="Zotero.Knowledge4Zotero.TemplateWindow.updateEditorView();">
<listbox id="template-list" flex="1" seltype="single" onselect="Zotero.BetterNotes.TemplateWindow.updateEditorView();">
<listhead>
<listheader id="name" label="&zotero.__addonRef__.template.list.label;" flex="1" />
</listhead>
@ -40,8 +40,8 @@
</listcols>
</listbox>
<row style="margin: 10px 0 10px 0;">
<button id="create-template" label="&zotero.__addonRef__.template.create.label;" oncommand="Zotero.Knowledge4Zotero.TemplateWindow.createTemplate();"></button>
<button id="import-template" label="&zotero.__addonRef__.template.import.label;" oncommand="Zotero.Knowledge4Zotero.TemplateWindow.importNoteTemplate();"></button>
<button id="create-template" label="&zotero.__addonRef__.template.create.label;" oncommand="Zotero.BetterNotes.TemplateWindow.createTemplate();"></button>
<button id="import-template" label="&zotero.__addonRef__.template.import.label;" oncommand="Zotero.BetterNotes.TemplateWindow.importNoteTemplate();"></button>
<button id="help" label="&helpMenu.label;" command="cmd_help" key="key_help" accesskey="H"></button>
<button id="more" label="&zotero.__addonRef__.template.more.label;" command="cmd_more"></button>
</row>
@ -57,8 +57,8 @@
</row>
<row style="margin: 10px 0 10px 0;">
<button id="save-template" label="&zotero.__addonRef__.template.save.label;" command="cmd_save" key="key_save" accesskey="S"></button>
<button id="delete-template" label="&zotero.__addonRef__.template.delete.label;" oncommand="Zotero.Knowledge4Zotero.TemplateWindow.deleteSelectedTemplate();"></button>
<button id="reset-template" label="&zotero.__addonRef__.template.reset.label;" oncommand="Zotero.Knowledge4Zotero.TemplateWindow.resetSelectedTemplate();" hidden="hidden"></button>
<button id="delete-template" label="&zotero.__addonRef__.template.delete.label;" oncommand="Zotero.BetterNotes.TemplateWindow.deleteSelectedTemplate();"></button>
<button id="reset-template" label="&zotero.__addonRef__.template.reset.label;" oncommand="Zotero.BetterNotes.TemplateWindow.resetSelectedTemplate();" hidden="hidden"></button>
</row>
</rows>
</hbox>

View File

@ -11,7 +11,7 @@
%knowledgeDTD;
]>
<wizard xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="knowledge-wizard" windowtype="knowledge-wizard" title="&zotero.__addonRef__.wizard.title;" width="788" height="600" onwizardfinish="Zotero.Knowledge4Zotero.WizardWindow.setup()">
<wizard xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="knowledge-wizard" windowtype="knowledge-wizard" title="&zotero.__addonRef__.wizard.title;" width="788" height="600" onwizardfinish="Zotero.BetterNotes.WizardWindow.setup()">
<script src="chrome://zotero/content/include.js" />
<wizardpage label="&zotero.__addonRef__.wizard.title;">
@ -43,19 +43,19 @@
<description style="white-space: pre-wrap; color: red;">&zotero.__addonRef__.wizard.page6.description2;</description>
<rows>
<row>
<checkbox id="__addonRef__-setup-enable" checked="true" oncommand="Zotero.Knowledge4Zotero.WizardWindow.changeSetup()" />
<checkbox id="__addonRef__-setup-enable" checked="true" oncommand="Zotero.BetterNotes.WizardWindow.changeSetup()" />
<label value="&zotero.__addonRef__.wizard.setup.enable.label;" />
</row>
<row>
<checkbox id="__addonRef__-setup-collectionenable" checked="true" oncommand="Zotero.Knowledge4Zotero.WizardWindow.updateCollectionSetup()" />
<checkbox id="__addonRef__-setup-collectionenable" checked="true" oncommand="Zotero.BetterNotes.WizardWindow.updateCollectionSetup()" />
<label value="&zotero.__addonRef__.wizard.setup.collectionenable.label;" />
<textbox id="__addonRef__-setup-collectionname" value="My Notes" oninput="Zotero.Knowledge4Zotero.WizardWindow.updateCollectionSetup()" />
<textbox id="__addonRef__-setup-collectionname" value="My Notes" oninput="Zotero.BetterNotes.WizardWindow.updateCollectionSetup()" />
</row>
<row>
<checkbox id="__addonRef__-setup-noteenable" checked="true" oncommand="Zotero.Knowledge4Zotero.WizardWindow.updateNoteSetup()" />
<checkbox id="__addonRef__-setup-noteenable" checked="true" oncommand="Zotero.BetterNotes.WizardWindow.updateNoteSetup()" />
<label value="&zotero.__addonRef__.wizard.setup.noteenable.label;" />
</row>
</rows>
</wizardpage>
<script>Zotero.Knowledge4Zotero.WizardWindow.init(document)</script>
<script>Zotero.BetterNotes.WizardWindow.init(document)</script>
</wizard>

View File

@ -19,7 +19,7 @@
%knowledgeDTD;
]>
<window id="zotero-knowledge-workspace" orient="vertical" width="1000" height="350" title="&zotero.__addonRef__.workspace.title;" persist="screenX screenY width height sizemode" windowtype="zotero:knowledgeWorkspace" onload="Zotero.Knowledge4Zotero.WorkspaceWindow._workspacePromise.resolve()" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<window id="zotero-knowledge-workspace" orient="vertical" width="1000" height="350" title="&zotero.__addonRef__.workspace.title;" persist="screenX screenY width height sizemode" windowtype="zotero:knowledgeWorkspace" onload="Zotero.BetterNotes.WorkspaceWindow._workspacePromise.resolve()" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<script src="chrome://zotero/content/include.js" />
@ -33,25 +33,25 @@
<key id="key_indent" keycode="VK_TAB" command="cmd_indent_betternotes" />
<key id="key_unindent" keycode="VK_TAB" modifiers="shift" command="cmd_unindent_betternotes" />
</keyset>
<command id="cmd_new" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'createWorkspace'});" />
<command id="cmd_open" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'selectMainNote'});" />
<command id="cmd_openWindow" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openWorkspaceInWindow'});" />
<command id="cmd_export" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'export', content: {editorInstance: {_item: false}}});" />
<command id="cmd_sync_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'sync'});" />
<command id="cmd_sync_manager_betternotes" oncommand="Zotero.Knowledge4Zotero.SyncListWindow.openSyncList();" />
<command id="cmd_close" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'closeWorkspace'});" />
<!-- <command id="cmd_insertNotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'insertNotes'});" /> -->
<command id="cmd_editTemplate" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'editTemplate'});" />
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'importLink'});" />
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'updateLink'});" /> -->
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'updateAutoAnnotation', content: {event: event}});" />
<command id="cmd_convertmd_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'convertMD'});" />
<command id="cmd_convertasciidoc_betternotes" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'convertAsciiDoc'});" />
<command id="cmd_treeview" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(1);" />
<command id="cmd_mindmap" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(2);" />
<command id="cmd_bubblemap" oncommand="Zotero.Knowledge4Zotero.WorkspaceOutline.switchView(3);" />
<command id="cmd_guide" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openUserGuide'});" />
<command id="cmd_about" oncommand="Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({type: 'openAbout'});" />
<command id="cmd_new" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'createWorkspace'});" />
<command id="cmd_open" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'selectMainNote'});" />
<command id="cmd_openWindow" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'openWorkspaceInWindow'});" />
<command id="cmd_export" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'export', content: {editorInstance: {_item: false}}});" />
<command id="cmd_sync_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'sync'});" />
<command id="cmd_sync_manager_betternotes" oncommand="Zotero.BetterNotes.SyncListWindow.openSyncList();" />
<command id="cmd_close" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'closeWorkspace'});" />
<!-- <command id="cmd_insertNotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'insertNotes'});" /> -->
<command id="cmd_editTemplate" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'editTemplate'});" />
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'importLink'});" />
<command id="cmd_updatelink_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'updateLink'});" /> -->
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'updateAutoAnnotation', content: {event: event}});" />
<command id="cmd_convertmd_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'convertMD'});" />
<command id="cmd_convertasciidoc_betternotes" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'convertAsciiDoc'});" />
<command id="cmd_treeview" oncommand="Zotero.BetterNotes.WorkspaceOutline.switchView(1);" />
<command id="cmd_mindmap" oncommand="Zotero.BetterNotes.WorkspaceOutline.switchView(2);" />
<command id="cmd_bubblemap" oncommand="Zotero.BetterNotes.WorkspaceOutline.switchView(3);" />
<command id="cmd_guide" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'openUserGuide'});" />
<command id="cmd_about" oncommand="Zotero.BetterNotes.ZoteroEvents.onEditorEvent({type: 'openAbout'});" />
<!-- Menu -->
<menubar id="better-notes-menu">
@ -70,14 +70,14 @@
<menupopup id="menu_EditPopup">
<!-- <menuitem id="menu_insertNotes" label="&zotero.__addonRef__.workspace.menu.insertNotes;" key="key_insertNotes" accesskey="I" command="cmd_insertNotes" /> -->
<menu id="menu_insertTextTemplate" label="&zotero.__addonRef__.workspace.menu.insertTextTemplate;">
<menupopup id="menu_insertTextTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Text');" />
<menupopup id="menu_insertTextTemplatePopup" onpopupshowing="Zotero.BetterNotes.ZoteroViews.updateTemplateMenu('Text');" />
</menu>
<menu id="menu_insertItemTemplate" label="&zotero.__addonRef__.workspace.menu.insertItemTemplate;">
<menupopup id="menu_insertItemTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Item');" />
<menupopup id="menu_insertItemTemplatePopup" onpopupshowing="Zotero.BetterNotes.ZoteroViews.updateTemplateMenu('Item');" />
</menu>
<menuitem id="menu_editTemplate" label="&zotero.__addonRef__.workspace.menu.editTemplate;" command="cmd_editTemplate" />
<menu id="menu_citeSetting_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.citeSetting;">
<menupopup id="menu_citeSettingPopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateCitationStyleMenu();" />
<menupopup id="menu_citeSettingPopup" onpopupshowing="Zotero.BetterNotes.ZoteroViews.updateCitationStyleMenu();" />
</menu>
<!-- <menuitem id="menu_importlink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.importLink;" command="cmd_importlink_betternotes" />
<menuitem id="menu_updatelink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.updateLink;" command="cmd_updatelink_betternotes" /> -->
@ -89,7 +89,7 @@
</menupopup>
</menu>
<menu id="view-menu" label="&viewMenu.label;" accesskey="&viewMenu.accesskey;" onpopupshowing="Zotero.Knowledge4Zotero.WorkspaceMenu.updateViewMenu();">
<menu id="view-menu" label="&viewMenu.label;" accesskey="&viewMenu.accesskey;" onpopupshowing="Zotero.BetterNotes.WorkspaceMenu.updateViewMenu();">
<menupopup id="menu_ViewPopup">
<menuitem id="menu_openWindow" label="&zotero.__addonRef__.workspace.menu.openWindow;" command="cmd_openWindow" />
<menuseparator />

View File

@ -98,6 +98,9 @@ async function main() {
await esbuild
.build({
entryPoints: ["src/index.ts"],
define: {
__env__: process.env.NODE_ENV,
},
bundle: true,
// Entry should be the same as addon/chrome/content/overlay.xul
outfile: path.join(buildDir, "addon/chrome/content/scripts/index.js"),

View File

@ -7,10 +7,11 @@
"description": "Everything about note management. All in Zotero.",
"main": "src/index.js",
"scripts": {
"build": "node build.js",
"build-dev": "cross-env NODE_ENV=development node build.js",
"build": "cross-env NODE_ENV=production node build.js",
"start": "node start.js",
"stop": "node stop.js",
"prerestart": "npm run build",
"prerestart": "npm run build-dev",
"restart": "node restart.js",
"release": "release-it",
"test": "echo \"Error: no test specified\" && exit 1"
@ -59,6 +60,7 @@
"@types/jquery": "^3.5.14",
"@types/node": "^17.0.31",
"compressing": "^1.5.1",
"cross-env": "^7.0.3",
"esbuild": "^0.14.34",
"release-it": "^14.14.0",
"zotero-types": "^0.1.2"

View File

@ -3,6 +3,7 @@
*/
import ZoteroEvents from "./zotero/events";
import ZoteroNotifies from "./zotero/notifies";
import ZoteroViews from "./zotero/views";
import ReaderViews from "./reader/readerViews";
import WizardWindow from "./wizard/wizardWindow";
@ -26,8 +27,10 @@ import TemplateWindow from "./template/templateWindow";
import { SyncUtils } from "./sync/syncUtils";
import ZoteroToolkit from "zotero-plugin-toolkit";
class Knowledge4Zotero {
class BetterNotes {
public env: "development" | "production";
public ZoteroEvents: ZoteroEvents;
public ZoteroNotifies: ZoteroNotifies;
// Zotero UI
public ZoteroViews: ZoteroViews;
// Reader UI
@ -63,6 +66,7 @@ class Knowledge4Zotero {
constructor() {
this.ZoteroEvents = new ZoteroEvents(this);
this.ZoteroNotifies = new ZoteroNotifies(this);
this.ZoteroViews = new ZoteroViews(this);
this.ReaderViews = new ReaderViews(this);
this.WorkspaceOutline = new WorkspaceOutline(this);
@ -88,8 +92,8 @@ class Knowledge4Zotero {
this.toolkit = new ZoteroToolkit();
// Disable since we are still using overlay
this.toolkit.UI.enableElementRecordGlobal = false
this.toolkit.UI.enableElementRecordGlobal = false;
}
}
export default Knowledge4Zotero;
export default BetterNotes;

View File

@ -2,7 +2,7 @@
* This file realizes editor watch.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
class EditorController extends AddonBase {
@ -13,7 +13,7 @@ class EditorController extends AddonBase {
editorPromise: _ZoteroPromiseObject;
activeEditor: Zotero.EditorInstance;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.editorHistory = [];
}
@ -37,7 +37,7 @@ class EditorController extends AddonBase {
_window.document.head.append(messageScript);
}
_window.addEventListener("BNMessage", (e: CustomEvent) => {
console.log("BN: note editor event", e.detail);
this._Addon.toolkit.Tool.log("BN: note editor event", e.detail);
switch (e.detail.type) {
case "exportPDFDone":
this._Addon.NoteExport._pdfPrintPromise.resolve();

View File

@ -2,14 +2,14 @@
* This file contains note editor UI code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { EditorMessage } from "../utils";
import AddonBase from "../module";
class EditorViews extends AddonBase {
icons: object;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.icons = {
addToNoteEnd: `<svg t="1651124422933" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3269" width="24" height="24"><path d="M896.00324 352c70.7 0 128-57.3 128-128 0-70.6-57.4-128-128-128-70.7 0-128 57.3-128 128 0 18.8 4.1 36.7 11.3 52.8 2.7 6 1.4 13.1-3.3 17.8l-24.2 24.2c-5.7 5.7-14.9 6.3-21.2 1.2-38.1-30.1-86.3-48-138.6-48-18.8 0-37.1 2.3-54.6 6.7-6.9 1.7-14.1-1.4-17.7-7.5l-6.6-11.4c-3.4-5.8-2.7-13.1 1.6-18.3 18.6-22.6 29.7-51.6 29.3-83.2C543.10324 89 486.30324 32.6 417.00324 32c-70.6-0.6-128.1 56.1-129 126.3-0.9 69.5 56.5 128.6 126 129.6 9.4 0.1 18.5-0.7 27.4-2.5 6.8-1.4 13.6 1.7 17.1 7.7l2.2 3.8c4 7 2.2 15.9-4.2 20.7-42.4 32.3-73 79.4-84 133.6-1.5 7.4-8.1 12.7-15.7 12.7h-94.1c-6.6 0-12.6-4-14.9-10.2-18.1-48-64.3-82.2-118.5-82.8C58.70324 370.3 0.50324 427.6 0.00324 498.1-0.49676 569.2 57.00324 627 128.00324 627c56.7 0 104.8-36.9 121.6-87.9 2.2-6.6 8.3-11.1 15.2-11.1h92c7.6 0 14.2 5.4 15.7 12.9 9.5 46.7 33.5 88 67 119.2 5.4 5 6.6 13.2 2.9 19.6l-21.7 37.6c-3.7 6.3-11.1 9.4-18.2 7.4-11.1-3.1-22.7-4.7-34.8-4.7-69.7 0.1-127 56.8-127.8 126.6-0.8 71.7 57.4 130 129.1 129.4 69.5-0.6 126.3-57.3 126.9-126.8 0.3-28-8.5-53.9-23.5-75.1-3.6-5.1-3.9-11.8-0.8-17.2l24.9-43.1c3.9-6.7 12-9.7 19.3-7 23.7 8.6 49.3 13.2 76 13.2 34.9 0 67.9-8 97.3-22.2 7.6-3.7 16.7-0.9 20.9 6.4l37 64c-26.3 23.5-43 57.7-43 95.8 0 70.9 58 128.5 128.9 128 69.7-0.5 126.2-56.7 127.1-126.3 0.9-70.1-57-129.3-127.1-129.7-6.2 0-12.3 0.4-18.3 1.2-6.5 0.9-12.8-2.2-16.1-7.8l-39.2-67.9c-3.4-5.9-2.7-13.3 1.7-18.4 34.2-39.3 54.9-90.7 54.9-147 0-38.9-9.9-75.5-27.4-107.4-3.4-6.2-2.2-13.9 2.8-18.9l28.4-28.4c4.9-4.9 12.4-6 18.7-2.9 17.4 8.6 36.9 13.5 57.6 13.5z m0-192c35.3 0 64 28.7 64 64s-28.7 64-64 64-64-28.7-64-64 28.7-64 64-64zM128.00324 563c-35.3 0-64-28.7-64-64s28.7-64 64-64 64 28.7 64 64-28.7 64-64 64z m240 349c-35.3 0-64-28.7-64-64s28.7-64 64-64 64 28.7 64 64-28.7 64-64 64z m464-112c35.3 0 64 28.7 64 64s-28.7 64-64 64-64-28.7-64-64 28.7-64 64-64zM416.00324 224c-35.3 0-64-28.7-64-64s28.7-64 64-64 64 28.7 64 64-28.7 64-64 64z m289.1 385.1C674.90324 639.4 634.70324 656 592.00324 656s-82.9-16.6-113.1-46.9C448.60324 578.9 432.00324 538.7 432.00324 496s16.6-82.9 46.9-113.1C509.10324 352.6 549.30324 336 592.00324 336s82.9 16.6 113.1 46.9C735.40324 413.1 752.00324 453.3 752.00324 496s-16.6 82.9-46.9 113.1z" p-id="3270" fill="currentColor"></path></svg>`,
@ -200,14 +200,14 @@ class EditorViews extends AddonBase {
addLinkDropDown.addEventListener("click", leaveAction);
// Observe the popup remove triggered by button click
const ob = new MutationObserver((e) => {
console.log(e);
this._Addon.toolkit.Tool.log(e);
if (e[0].removedNodes) {
leaveAction();
}
});
ob.observe(addLinkDropDown, { childList: true });
const keyAction = (e: KeyboardEvent) => {
console.log(e);
this._Addon.toolkit.Tool.log(e);
if (e.key === "Control") {
hintWindow?.close();
e.preventDefault();
@ -629,7 +629,7 @@ class EditorViews extends AddonBase {
});
}
parentDropDown.append(popup);
Zotero.debug(popup.offsetWidth);
this._Addon.toolkit.Tool.log(popup.offsetWidth);
let style: string = "";
if (align === "center") {
style = `right: -${popup.offsetWidth / 2 - 15}px;`;
@ -694,7 +694,7 @@ class EditorViews extends AddonBase {
const newLineString = newLines.join("\n");
const notifyFlag: _ZoteroPromiseObject = Zotero.Promise.defer();
const notifierName = "insertLinkWait";
this._Addon.ZoteroEvents.addNotifyListener(
this._Addon.ZoteroNotifies.registerNotifyListener(
notifierName,
(
event: string,
@ -708,21 +708,21 @@ class EditorViews extends AddonBase {
ids.includes(targetNote.id)
) {
notifyFlag.resolve();
this._Addon.ZoteroEvents.removeNotifyListener(notifierName);
this._Addon.ZoteroNotifies.unregisterNotifyListener(notifierName);
}
}
);
await this._Addon.NoteUtils.modifyLineInNote(
targetNote,
(oldLine: string) => {
Zotero.debug(oldLine);
this._Addon.toolkit.Tool.log(oldLine);
const params = this._Addon.NoteParse.parseParamsFromLink(link);
const newLink = !params.ignore
? link + (link.includes("?") ? "&ignore=1" : "?ignore=1")
: link;
const linkIndex =
this._Addon.NoteParse.parseLinkIndexInText(oldLine);
Zotero.debug(linkIndex);
this._Addon.toolkit.Tool.log(linkIndex);
return `${oldLine.slice(0, linkIndex[0])}${newLink}${oldLine.slice(
linkIndex[1]
)}\n${newLineString}`;
@ -768,10 +768,10 @@ class EditorViews extends AddonBase {
);
updateButton.innerHTML = this.icons["updateLinkText"];
updateButton.addEventListener("click", async (e) => {
Zotero.debug("ZBN: Update Link Text");
this._Addon.toolkit.Tool.log("ZBN: Update Link Text");
const noteLines = this._Addon.NoteUtils.getLinesInNote(targetNote);
let line = noteLines[this._Addon.NoteUtils.currentLine[targetNote.id]];
Zotero.debug(line);
this._Addon.toolkit.Tool.log(line);
let linkStart = line.search(/<a /g);
let linkEnd = line.search(/<\/a>/g) + 4;
@ -810,7 +810,7 @@ class EditorViews extends AddonBase {
beforeLink = beforeLink + linkPart.slice(0, linkPart.search(/>/) + 1);
afterLink = "</a>" + afterLink;
const newLine = `${beforeLink}${currentNote.getNoteTitle()}${afterLink}`;
Zotero.debug(newLine);
this._Addon.toolkit.Tool.log(newLine);
noteLines[this._Addon.NoteUtils.currentLine[targetNote.id]] = newLine;
await this._Addon.NoteUtils.setLinesToNote(targetNote, noteLines);
@ -833,7 +833,7 @@ class EditorViews extends AddonBase {
openInWindowButton.setAttribute("title", "Open In New Window");
openInWindowButton.innerHTML = this.icons["openInNewWindow"];
openInWindowButton.addEventListener("click", async (e) => {
Zotero.debug("ZBN: Open link in new window");
this._Addon.toolkit.Tool.log("ZBN: Open link in new window");
ZoteroPane.openNoteWindow(note.id);
});
@ -930,7 +930,7 @@ class EditorViews extends AddonBase {
}
public updatePopupMenu() {
console.log("updating editor popup");
this._Addon.toolkit.Tool.log("updating editor popup");
const instance = this._Addon.EditorController.activeEditor;
const noteItem = instance._item;
const lineIndex = this._Addon.NoteUtils.currentLine[noteItem.id];
@ -1086,7 +1086,7 @@ class EditorViews extends AddonBase {
id: `menu_insert${instance._item.id}TextTemplatePopup`,
ignoreIfExists: true,
attributes: {
onpopupshowing: `Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Text', Zotero.Knowledge4Zotero.EditorController.activeEditor._popup.ownerDocument, '${instance._item.id}', false);`,
onpopupshowing: `Zotero.BetterNotes.ZoteroViews.updateTemplateMenu('Text', Zotero.BetterNotes.EditorController.activeEditor._popup.ownerDocument, '${instance._item.id}', false);`,
},
},
],
@ -1103,7 +1103,7 @@ class EditorViews extends AddonBase {
id: `menu_insert${instance._item.id}ItemTemplatePopup`,
ignoreIfExists: true,
attributes: {
onpopupshowing: `Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Item', Zotero.Knowledge4Zotero.EditorController.activeEditor._popup.ownerDocument, '${instance._item.id}', false);`,
onpopupshowing: `Zotero.BetterNotes.ZoteroViews.updateTemplateMenu('Item', Zotero.BetterNotes.EditorController.activeEditor._popup.ownerDocument, '${instance._item.id}', false);`,
},
},
],
@ -1185,7 +1185,7 @@ class EditorViews extends AddonBase {
eleList.push(ele);
}
}
console.log(eleList, lineIndex);
this._Addon.toolkit.Tool.log(eleList, lineIndex);
if (lineIndex >= eleList.length) {
lineIndex = eleList.length - 1;
} else if (lineIndex < 0) {

View File

@ -2,7 +2,7 @@
* This file contains image viewer for note editor.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
class EditorImageViewer extends AddonBase {
@ -17,7 +17,7 @@ class EditorImageViewer extends AddonBase {
top: number;
};
icons: any;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.scaling = 1;
this.title = "Note";

View File

@ -2,14 +2,17 @@
* This file is the esbuild entrance.
*/
import Knowledge4Zotero from "./addon";
import BetterNotes from "./addon";
Zotero.Knowledge4Zotero = new Knowledge4Zotero();
const addon = new BetterNotes();
Zotero.BetterNotes = addon;
// For compatibility
Zotero.Knowledge4Zotero = addon;
window.addEventListener(
"load",
async function (e) {
Zotero.Knowledge4Zotero.ZoteroEvents.onInit();
Zotero.BetterNotes.ZoteroEvents.onInit();
},
false
);

View File

@ -3,11 +3,11 @@
*/
import Knowledge4Zotero from "./addon";
import BetterNotes from "./addon";
class AddonBase {
protected _Addon: Knowledge4Zotero;
constructor(parent: Knowledge4Zotero) {
protected _Addon: BetterNotes;
constructor(parent: BetterNotes) {
this._Addon = parent;
}
}

View File

@ -2,7 +2,7 @@
* This file realizes note export.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
class NoteExport extends AddonBase {
@ -17,7 +17,7 @@ class NoteExport extends AddonBase {
_docxPromise: _ZoteroPromiseObject;
_docxBlob: Blob;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this._exportFileInfo = [];
}
@ -52,7 +52,7 @@ class NoteExport extends AddonBase {
.filter((k) => k.includes("export"))
.find((k) => options[k])
) {
console.log("[BN] options containing 'export' all false");
this._Addon.toolkit.Tool.log("[BN] options containing 'export' all false");
return;
}
this._exportFileInfo = [];
@ -70,7 +70,7 @@ class NoteExport extends AddonBase {
);
await this._Addon.NoteUtils.setLinesToNote(newNote, convertResult.lines);
Zotero.debug(convertResult.subNotes);
this._Addon.toolkit.Tool.log(convertResult.subNotes);
await Zotero.DB.executeTransaction(async () => {
await Zotero.Notes.copyEmbeddedImages(note, newNote);
@ -107,7 +107,7 @@ class NoteExport extends AddonBase {
this._docxPromise = Zotero.Promise.defer();
instance._iframeWindow.postMessage({ type: "exportDocx" }, "*");
await this._docxPromise.promise;
console.log(this._docxBlob);
this._Addon.toolkit.Tool.log(this._docxBlob);
const filename = await this._Addon.toolkit.Tool.openFilePicker(
`${Zotero.getString("fileInterface.export")} MS Word Document`,
"save",
@ -119,14 +119,14 @@ class NoteExport extends AddonBase {
}
}
if (options.exportPDF) {
console.log(newNote);
this._Addon.toolkit.Tool.log(newNote);
let _w: Window;
let t = 0;
ZoteroPane.selectItem(note.id);
do {
ZoteroPane.openNoteWindow(newNote.id);
_w = ZoteroPane.findNoteWindow(newNote.id);
console.log(_w);
this._Addon.toolkit.Tool.log(_w);
await Zotero.Promise.delay(10);
t += 1;
} while (!_w && t < 500);
@ -150,7 +150,7 @@ class NoteExport extends AddonBase {
this._pdfPrintPromise = Zotero.Promise.defer();
instance._iframeWindow.postMessage({ type: "exportPDF" }, "*");
await this._pdfPrintPromise.promise;
console.log("print finish detected");
this._Addon.toolkit.Tool.log("print finish detected");
const closeFlag = _w.confirm(
"Printing finished. Do you want to close the preview window?"
);
@ -205,7 +205,7 @@ class NoteExport extends AddonBase {
filedir = Zotero.File.normalizeToUnix(filedir);
if (!filedir) {
Zotero.debug("BN:export, filepath invalid");
this._Addon.toolkit.Tool.log("BN:export, filepath invalid");
return;
}
@ -233,7 +233,7 @@ class NoteExport extends AddonBase {
newNote,
convertResult.lines
);
Zotero.debug(convertResult.subNotes);
this._Addon.toolkit.Tool.log(convertResult.subNotes);
await Zotero.DB.executeTransaction(async () => {
await Zotero.Notes.copyEmbeddedImages(note, newNote);

View File

@ -2,7 +2,7 @@
* This file contains note export window code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
class NoteExportWindow extends AddonBase {
@ -14,7 +14,7 @@ class NoteExportWindow extends AddonBase {
private _window: Window;
private options: string[];
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.options = [
"embedLink",
@ -98,8 +98,8 @@ class NoteExportWindow extends AddonBase {
};
this.options.forEach(saveOptions);
Zotero.debug(this.io);
Zotero.debug(this.io.dataOut);
this._Addon.toolkit.Tool.log(this.io);
this._Addon.toolkit.Tool.log(this.io.dataOut);
}
}

View File

@ -2,11 +2,11 @@
* This file realizes md import.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
class NoteImport extends AddonBase {
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
}
@ -39,7 +39,7 @@ class NoteImport extends AddonBase {
try {
mdStatus = await this._Addon.SyncUtils.getMDStatus(file);
} catch (e) {
Zotero.debug(`BN Import: ${String(e)}`);
this._Addon.toolkit.Tool.log(`BN Import: ${String(e)}`);
}
if (!options.ignoreVersion && mdStatus.meta?.version < noteItem?._version) {
if (
@ -75,7 +75,7 @@ class NoteImport extends AddonBase {
noteItem,
true
);
console.log("bn import", noteStatus);
this._Addon.toolkit.Tool.log("bn import", noteStatus);
if (options.append) {
await this._Addon.NoteUtils.addLineToNote(

View File

@ -6,12 +6,12 @@ import TreeModel = require("tree-model");
const asciidoctor = require("asciidoctor")();
import YAML = require("yamljs");
import AddonBase from "../module";
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { NodeMode } from "../sync/syncUtils";
class NoteParse extends AddonBase {
tools: any;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
}
@ -211,7 +211,7 @@ class NoteParse extends AddonBase {
if (currentLineIndex <= lineIndex) {
currentLineIndex += 1;
currentElement = _e;
// console.log(currentLineIndex, _e);
// this._Addon.toolkit.Tool.log(currentLineIndex, _e);
}
}
} else {
@ -221,10 +221,10 @@ class NoteParse extends AddonBase {
} else {
currentLineIndex += 1;
currentElement = e as HTMLElement;
// console.log(currentLineIndex, e);
// this._Addon.toolkit.Tool.log(currentLineIndex, e);
}
}
console.log(currentLineIndex);
this._Addon.toolkit.Tool.log(currentLineIndex);
return currentElement;
}
@ -381,8 +381,8 @@ class NoteParse extends AddonBase {
template = "<p>{{image}}<br/>{{citation}} {{comment}}</p>";
}
Zotero.debug("Using note template:");
Zotero.debug(template);
this._Addon.toolkit.Tool.log("Using note template:");
this._Addon.toolkit.Tool.log(template);
template = template.replace(
/(<blockquote>[^<>]*?)({{highlight}})([\s\S]*?<\/blockquote>)/g,
@ -431,7 +431,7 @@ class NoteParse extends AddonBase {
}
annotationJSONList.push(annotJson);
}
await this._Addon.NoteUtils.importImagesToNote(note, annotationJSONList);
await this._Addon.NoteUtils.importAnnotationImagesToNote(note, annotationJSONList);
const html = this.serializeAnnotations(
annotationJSONList,
false,
@ -483,7 +483,7 @@ class NoteParse extends AddonBase {
)
.slice(0, lineCount)
.join("\n")}</div>`;
console.log(this.parseHTMLLines(item.getNote()).slice(0, lineCount));
this._Addon.toolkit.Tool.log(this.parseHTMLLines(item.getNote()).slice(0, lineCount));
const parser = this._Addon.toolkit.Compat.getDOMParser();
let doc = parser.parseFromString(note, "text/html");
@ -712,7 +712,7 @@ class NoteParse extends AddonBase {
let mmXML = '<map version="freeplane 1.9.0">';
convertNode(root);
mmXML += "</map>";
console.log(mmXML);
this._Addon.toolkit.Tool.log(mmXML);
return mmXML;
}
@ -726,7 +726,7 @@ class NoteParse extends AddonBase {
) {
const noteStatus = this._Addon.SyncUtils.getNoteStatus(noteItem);
const rehype = this._Addon.SyncUtils.note2rehype(noteStatus.content);
console.log(rehype);
this._Addon.toolkit.Tool.log(rehype);
this._Addon.SyncUtils.processN2MRehypeHighlightNodes(
this._Addon.SyncUtils.getN2MRehypeHighlightNodes(rehype),
NodeMode.direct
@ -748,9 +748,9 @@ class NoteParse extends AddonBase {
false,
NodeMode.direct
);
console.log("rehype", rehype);
this._Addon.toolkit.Tool.log("rehype", rehype);
const remark = await this._Addon.SyncUtils.rehype2remark(rehype);
console.log("remark", remark);
this._Addon.toolkit.Tool.log("remark", remark);
let md = this._Addon.SyncUtils.remark2md(remark);
if (options.withMeta) {
@ -772,7 +772,7 @@ class NoteParse extends AddonBase {
let yamlFrontMatter = `---\n${YAML.stringify(header, 10)}\n---`;
md = `${yamlFrontMatter}\n${md}`;
}
console.log(md);
this._Addon.toolkit.Tool.log(md);
return md;
}
@ -796,18 +796,18 @@ class NoteParse extends AddonBase {
// }
// }
// if (!editorInstance) {
// Zotero.debug("BN:Import: failed to open note.");
// this._Addon.toolkit.Tool.log("BN:Import: failed to open note.");
// return;
// }
console.log("md", mdStatus);
this._Addon.toolkit.Tool.log("md", mdStatus);
const remark = this._Addon.SyncUtils.md2remark(mdStatus.content);
console.log("remark", remark);
this._Addon.toolkit.Tool.log("remark", remark);
const _rehype = await this._Addon.SyncUtils.remark2rehype(remark);
console.log("_rehype", _rehype);
this._Addon.toolkit.Tool.log("_rehype", _rehype);
const _note = this._Addon.SyncUtils.rehype2note(_rehype);
console.log("_note", _note);
this._Addon.toolkit.Tool.log("_note", _note);
const rehype = this._Addon.SyncUtils.note2rehype(_note);
console.log("rehype", rehype);
this._Addon.toolkit.Tool.log("rehype", rehype);
// Import highlight to note meta
// Annotations don't need to be processed.
// Image annotations are imported with normal images.
@ -848,8 +848,8 @@ class NoteParse extends AddonBase {
// // root -> p -> span(cite, this is what we actually want)
// replace(node, (newNode.children[0] as any).children[0]);
// } catch (e) {
// Zotero.debug(e);
// console.log(e);
// this._Addon.toolkit.Tool.log(e);
// this._Addon.toolkit.Tool.log(e);
// continue;
// }
// }
@ -874,7 +874,7 @@ class NoteParse extends AddonBase {
mdStatus.filedir,
isImport
);
console.log(rehype);
this._Addon.toolkit.Tool.log(rehype);
const noteContent = this._Addon.SyncUtils.rehype2note(rehype);
return noteContent;
}

View File

@ -3,12 +3,12 @@
*/
import TreeModel = require("tree-model");
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
class NoteUtils extends AddonBase {
public currentLine: any;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.currentLine = {};
}
@ -52,7 +52,9 @@ class NoteUtils extends AddonBase {
return;
}
let noteLines = this.getLinesInNote(note);
let autoLineIndex = false;
if (lineIndex < 0) {
autoLineIndex = true;
lineIndex = this.currentLine[note.id];
lineIndex = lineIndex && lineIndex >= 0 ? lineIndex : noteLines.length;
} else if (lineIndex >= noteLines.length) {
@ -61,12 +63,12 @@ class NoteUtils extends AddonBase {
Zotero.debug(
`insert to ${lineIndex}, it used to be ${noteLines[lineIndex]}`
);
Zotero.debug(text);
this._Addon.toolkit.Tool.log(text);
const editorInstance = this._Addon.WorkspaceWindow.getEditorInstance(note);
if (editorInstance && !forceMetadata) {
// The note is opened. Add line via note editor
console.log("Add note line via note editor");
this._Addon.toolkit.Tool.log("Add note line via note editor");
const _document = editorInstance._iframeWindow.document;
const currentElement = this._Addon.NoteParse.parseHTMLLineElement(
this._Addon.EditorViews.getEditorElement(_document) as HTMLElement,
@ -85,7 +87,7 @@ class NoteUtils extends AddonBase {
}
const defer = Zotero.Promise.defer();
const notifyName = `addLineToNote-${note.id}`;
this._Addon.ZoteroEvents.addNotifyListener(
this._Addon.ZoteroNotifies.registerNotifyListener(
notifyName,
(
event: string,
@ -94,7 +96,7 @@ class NoteUtils extends AddonBase {
extraData: object
) => {
if (event === "modify" && type === "item" && ids.includes(note.id)) {
this._Addon.ZoteroEvents.removeNotifyListener(notifyName);
this._Addon.ZoteroNotifies.unregisterNotifyListener(notifyName);
defer.resolve();
}
}
@ -111,7 +113,7 @@ class NoteUtils extends AddonBase {
);
} else {
// The note editor does not exits yet. Fall back to modify the metadata
console.log("Add note line via note metadata");
this._Addon.toolkit.Tool.log("Add note line via note metadata");
// insert after/before current line
if (position === "after") {
@ -123,6 +125,18 @@ class NoteUtils extends AddonBase {
await this.scrollWithRefresh(lineIndex);
}
}
if (autoLineIndex) {
// Compute annotation lines length
const temp = this._Addon.toolkit.UI.createElement(
document,
"div"
) as HTMLDivElement;
temp.innerHTML = text;
const elementList = this._Addon.NoteParse.parseHTMLElements(temp);
// Move cursor foward
this._Addon.NoteUtils.currentLine[note.id] += elementList.length;
}
}
private _dataURLtoBlob(dataurl: string) {
@ -150,17 +164,7 @@ class NoteUtils extends AddonBase {
return null;
}
public async getAttachmentKeyFromFileName(
libraryID: number,
path: string
): Promise<false | _ZoteroItem> {
return await Zotero.Items.getByLibraryAndKeyAsync(
libraryID,
Zotero.File.normalizeToUnix(path).split("/").pop().split(".").shift()
);
}
public async _importImage(
public async importImageToNote(
note: Zotero.Item,
src: string,
type: "b64" | "url" | "file" = "b64"
@ -209,11 +213,14 @@ class NoteUtils extends AddonBase {
return attachment.key;
}
public async importImagesToNote(note: Zotero.Item, annotations: any) {
public async importAnnotationImagesToNote(
note: Zotero.Item,
annotations: AnnotationJson[]
) {
for (let annotation of annotations) {
if (annotation.image) {
annotation.imageAttachmentKey =
(await this._importImage(note, annotation.image)) || "";
(await this.importImageToNote(note, annotation.image)) || "";
}
delete annotation.image;
}
@ -222,7 +229,8 @@ class NoteUtils extends AddonBase {
public async addAnnotationsToNote(
note: Zotero.Item,
annotations: Zotero.Item[],
lineIndex: number
lineIndex: number,
showMsg: boolean = false
) {
if (!note) {
return;
@ -231,7 +239,16 @@ class NoteUtils extends AddonBase {
note,
annotations
);
await this.addLineToNote(note, html, lineIndex);
await this.addLineToNote(note, html, lineIndex, showMsg);
const noteTitle = note.getNoteTitle();
this._Addon.ZoteroViews.showProgressWindow(
"Better Notes",
`Insert lines into ${
lineIndex >= 0 ? `line ${lineIndex} in` : "end of"
} note ${
noteTitle.length > 15 ? noteTitle.slice(0, 12) + "..." : noteTitle
}`
);
return html;
}
@ -277,7 +294,7 @@ class NoteUtils extends AddonBase {
this._Addon.ZoteroViews.showProgressWindow(
"Better Notes",
`Link is added to workspace${lineIndex >= 0 ? ` line ${lineIndex}` : ""}`
`Link is added to ${lineIndex >= 0 ? ` line ${lineIndex}` : ""}`
);
}
@ -367,7 +384,7 @@ class NoteUtils extends AddonBase {
const editorInstance = this._Addon.WorkspaceWindow.getEditorInstance(note);
if (editorInstance && !forceMetadata) {
// The note is opened. Add line via note editor
console.log("Modify note line via note editor");
this._Addon.toolkit.Tool.log("Modify note line via note editor");
const _document = editorInstance._iframeWindow.document;
const currentElement: HTMLElement =
this._Addon.NoteParse.parseHTMLLineElement(
@ -387,7 +404,7 @@ class NoteUtils extends AddonBase {
}
const defer = Zotero.Promise.defer();
const notifyName = `modifyLineInNote-${note.id}`;
this._Addon.ZoteroEvents.addNotifyListener(
this._Addon.ZoteroNotifies.registerNotifyListener(
notifyName,
(
event: string,
@ -396,7 +413,7 @@ class NoteUtils extends AddonBase {
extraData: object
) => {
if (event === "modify" && type === "item" && ids.includes(note.id)) {
this._Addon.ZoteroEvents.removeNotifyListener(notifyName);
this._Addon.ZoteroNotifies.unregisterNotifyListener(notifyName);
defer.resolve();
}
}
@ -413,39 +430,6 @@ class NoteUtils extends AddonBase {
}
}
async changeHeadingLineInNote(
note: Zotero.Item,
rankChange: number,
lineIndex: number
) {
if (!note) {
return;
}
const noteLines = this.getLinesInNote(note);
if (lineIndex < 0 || lineIndex >= noteLines.length) {
return;
}
const headerStartReg = new RegExp("<h[1-6]>");
const headerStopReg = new RegExp("</h[1-6]>");
let headerStart = noteLines[lineIndex].search(headerStartReg);
if (headerStart === -1) {
return;
}
let lineRank = parseInt(noteLines[lineIndex][headerStart + 2]) + rankChange;
if (lineRank > 6) {
lineRank = 6;
} else if (lineRank < 1) {
lineRank = 1;
}
this.modifyLineInNote(
note,
noteLines[lineIndex]
.replace(headerStartReg, `<h${lineRank}>`)
.replace(headerStopReg, `</h${lineRank}>`),
lineIndex
);
}
async moveHeaderLineInNote(
note: Zotero.Item,
currentNode: TreeModel.Node<object>,
@ -509,15 +493,15 @@ class NoteUtils extends AddonBase {
if (currentNode.model.endIndex <= targetIndex) {
targetIndex -= movedLines.length;
}
Zotero.debug(`move to ${targetIndex}`);
this._Addon.toolkit.Tool.log(`move to ${targetIndex}`);
let newLines = lines
.slice(0, targetIndex + 1)
.concat(movedLines, lines.slice(targetIndex + 1));
console.log("new lines", newLines);
console.log("moved", movedLines);
console.log("insert after", lines[targetIndex]);
console.log("next line", lines[targetIndex + 1]);
this._Addon.toolkit.Tool.log("new lines", newLines);
this._Addon.toolkit.Tool.log("moved", movedLines);
this._Addon.toolkit.Tool.log("insert after", lines[targetIndex]);
this._Addon.toolkit.Tool.log("next line", lines[targetIndex + 1]);
await this.setLinesToNote(note, newLines);
}
@ -604,10 +588,10 @@ class NoteUtils extends AddonBase {
toID,
tree
);
Zotero.debug(fromNode.model);
Zotero.debug(toNode.model);
Zotero.debug(moveType);
console.log(toNode.model, fromNode.model, moveType);
this._Addon.toolkit.Tool.log(fromNode.model);
this._Addon.toolkit.Tool.log(toNode.model);
this._Addon.toolkit.Tool.log(moveType);
this._Addon.toolkit.Tool.log(toNode.model, fromNode.model, moveType);
this.moveHeaderLineInNote(
this._Addon.WorkspaceWindow.getWorkspaceNote(),
fromNode,
@ -631,7 +615,7 @@ class NoteUtils extends AddonBase {
rootNoteIds: number[],
convertNoteLinks: boolean = true
): Promise<{ lines: string[]; subNotes: Zotero.Item[] }> {
Zotero.debug(`convert note ${currentNote.id}`);
this._Addon.toolkit.Tool.log(`convert note ${currentNote.id}`);
let subNotes: Zotero.Item[] = [];
const [..._rootNoteIds] = rootNoteIds;
@ -652,7 +636,7 @@ class NoteUtils extends AddonBase {
// Ignore links that are not in <a>
!noteLines[i].slice(linkIndex - 8, linkIndex).includes("href")
) {
Zotero.debug("ignore link");
this._Addon.toolkit.Tool.log("ignore link");
noteLines[i] = noteLines[i].substring(
noteLines[i].search(/zotero:\/\/note\//g)
);
@ -662,11 +646,13 @@ class NoteUtils extends AddonBase {
link = this._Addon.NoteParse.parseLinkInText(noteLines[i]);
continue;
}
Zotero.debug("convert link");
this._Addon.toolkit.Tool.log("convert link");
let res = await this.getNoteFromLink(link);
const subNote = res.item;
if (subNote && _rootNoteIds.indexOf(subNote.id) === -1) {
Zotero.debug(`Knowledge4Zotero: Exporting sub-note ${link}`);
this._Addon.toolkit.Tool.log(
`Knowledge4Zotero: Exporting sub-note ${link}`
);
const convertResult = await this.convertNoteLines(
subNote,
_rootNoteIds,
@ -694,7 +680,7 @@ class NoteUtils extends AddonBase {
}
}
}
Zotero.debug(subNotes);
this._Addon.toolkit.Tool.log(subNotes);
return { lines: newLines, subNotes: subNotes };
}
@ -707,7 +693,7 @@ class NoteUtils extends AddonBase {
infoText: "Library does not exist or access denied.",
};
}
Zotero.debug(params);
this._Addon.toolkit.Tool.log(params);
let item: Zotero.Item = await Zotero.Items.getByLibraryAndKeyAsync(
params.libraryID,
params.noteKey
@ -789,13 +775,15 @@ class NoteUtils extends AddonBase {
}
}
}
Zotero.debug(`Knowledge4Zotero: line ${currentLineIndex} selected.`);
console.log(currentLineIndex);
this._Addon.toolkit.Tool.log(
`Knowledge4Zotero: line ${currentLineIndex} selected.`
);
this._Addon.toolkit.Tool.log(currentLineIndex);
// Zotero.debug(
// `Current Element: ${focusNode.outerHTML}; Real Element: ${realElement.outerHTML}`
// );
this.currentLine[editor._item.id] = currentLineIndex;
// console.log(realElement);
// this._Addon.toolkit.Tool.log(realElement);
if (realElement.tagName === "A") {
let link = (realElement as HTMLLinkElement).href;
let linkedNote = (await this.getNoteFromLink(link)).item;

View File

@ -3,14 +3,14 @@
*/
const CryptoJS = require("crypto-js");
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
import { EditorMessage } from "../utils";
class ReaderViews extends AddonBase {
icons: object;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.icons = {
createNote: `<svg t="1651630304116" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="14011" width="16" height="16"><path d="M791.30324 369.7c-5 5-6.2 12.7-2.8 18.9 17.5 31.9 27.4 68.5 27.4 107.4 0 56.2-20.7 107.6-54.9 147-4.5 5.1-5.1 12.6-1.8 18.4l39.2 67.9c3.3 5.7 9.6 8.7 16.1 7.8 6-0.8 12.1-1.2 18.3-1.2 70.1 0.5 128 59.7 127.1 129.7-0.9 69.7-57.4 125.9-127.1 126.4-70.9 0.5-128.9-57.1-128.9-128 0-38.1 16.7-72.3 43.1-95.8l-37-64c-4.2-7.3-13.3-10-20.9-6.4-29.3 14.2-62.3 22.2-97.2 22.2-26.7 0-52.3-4.7-76-13.2-7.3-2.6-15.4 0.3-19.3 7l-24.9 43.1c-3.1 5.4-2.8 12.1 0.8 17.2 15 21.2 23.7 47.1 23.5 75.1-0.7 69.5-57.5 126.2-127 126.8-71.6 0.6-129.8-57.7-129.1-129.4 0.8-69.7 58-126.5 127.8-126.6 12 0 23.7 1.6 34.8 4.7 7 2 14.5-1.1 18.2-7.4l21.7-37.6c3.7-6.4 2.5-14.6-2.9-19.6-33.6-31.2-57.5-72.6-67-119.2-1.5-7.5-8-12.9-15.7-12.9h-92c-6.9 0-13.1 4.5-15.2 11.1C232.80324 590.2 184.70324 627 128.00324 627 57.00324 627-0.49676 569.2 0.00324 498.1 0.40324 427.5 58.60324 370.3 129.20324 371c54.2 0.5 100.4 34.8 118.5 82.8C250.00324 460 256.00324 464 262.60324 464h94.1c7.6 0 14.2-5.3 15.7-12.7 11-54.2 41.5-101.3 84-133.6 6.4-4.9 8.2-13.8 4.2-20.8l-2.2-3.8c-3.5-6-10.3-9-17.1-7.7-8.8 1.8-18 2.7-27.4 2.5-69.5-1-126.9-60.1-126-129.6 0.9-70.3 58.4-126.9 129-126.3 69.3 0.6 126 57 127 126.2 0.4 31.6-10.6 60.7-29.3 83.2-4.3 5.2-5 12.5-1.6 18.3l6.6 11.4c3.6 6.2 10.8 9.3 17.7 7.5 17.5-4.4 35.8-6.7 54.6-6.7 52.3 0 100.4 17.9 138.6 48 6.4 5 15.5 4.5 21.2-1.2l24.2-24.2c4.7-4.7 6-11.8 3.3-17.8-7.3-16.1-11.3-34-11.3-52.8 0-70.7 57.3-128 128-128 70.6 0 128 57.4 128 128 0 70.7-57.3 128-128 128-20.7 0-40.2-4.9-57.5-13.6-6.2-3.1-13.7-2-18.7 2.9l-28.4 28.5z" p-id="14012" fill="#ffd400"></path></svg>`,
@ -101,9 +101,9 @@ class ReaderViews extends AddonBase {
}
public async buildReaderAnnotationButtons() {
Zotero.debug("Knowledge4Zotero: buildReaderAnnotationButton");
this._Addon.toolkit.Tool.log("buildReaderAnnotationButton")
for (const reader of Zotero.Reader._readers) {
Zotero.debug("reader found");
this._Addon.toolkit.Tool.log("reader found");
let t = 0;
while (t < 100 && !(await this.addReaderAnnotationButton(reader))) {
await Zotero.Promise.delay(50);
@ -207,7 +207,7 @@ class ReaderViews extends AddonBase {
responseType: "json",
}
);
console.log(xhr);
this._Addon.toolkit.Tool.log(xhr);
if (xhr && xhr.status && xhr.status === 200 && xhr.response.text) {
result = xhr.response.text;
success = true;
@ -255,7 +255,7 @@ class ReaderViews extends AddonBase {
.map((r) => r.recog.content)
.join(" ")
.replace(/ifly-latex-(begin)?(end)?/g, "$");
console.log(xhr);
this._Addon.toolkit.Tool.log(xhr);
success = true;
} else {
result =

View File

@ -2,14 +2,14 @@
* This file realizes the sycn feature.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
import { SyncCode } from "../utils";
class SyncController extends AddonBase {
sycnLock: boolean;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.sycnLock = false;
}
@ -139,12 +139,12 @@ class SyncController extends AddonBase {
let progress;
// Wrap the code in try...catch so that the lock can be released anyway
try {
Zotero.debug("Better Notes: sync start");
this._Addon.toolkit.Tool.log("sync start")
this.sycnLock = true;
if (!items || !items.length) {
items = Zotero.Items.get(this.getSyncNoteIds());
}
console.log("BN:Sync", items);
this._Addon.toolkit.Tool.log("BN:Sync", items);
if (!quiet) {
progress = this._Addon.ZoteroViews.showProgressWindow(
@ -191,7 +191,7 @@ class SyncController extends AddonBase {
}
i += 1;
}
console.log(toExport, toImport, toDiff);
this._Addon.toolkit.Tool.log(toExport, toImport, toDiff);
i = 1;
let totalCount = Object.keys(toExport).length;
for (const filepath of Object.keys(toExport)) {
@ -272,8 +272,8 @@ class SyncController extends AddonBase {
progress.startCloseTimer(5000);
}
} catch (e) {
Zotero.debug(e);
console.log(e);
this._Addon.toolkit.Tool.log(e);
this._Addon.toolkit.Tool.log(e);
this._Addon.ZoteroViews.showProgressWindow(
"[Syncing] Better Notes",
String(e),

View File

@ -2,14 +2,14 @@
* This file realizes note diff with markdown file.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
import { diffChars } from "diff";
class SyncDiffWindow extends AddonBase {
_window: any | Window;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
}
@ -30,9 +30,9 @@ class SyncDiffWindow extends AddonBase {
true
);
const noteContent = await this._Addon.NoteParse.parseNoteForDiff(noteItem);
console.log(mdNoteContent, noteContent);
this._Addon.toolkit.Tool.log(mdNoteContent, noteContent);
const changes = diffChars(noteContent, mdNoteContent);
console.log("changes", changes);
this._Addon.toolkit.Tool.log("changes", changes);
const io = {
defer: Zotero.Promise.defer(),
@ -68,7 +68,7 @@ class SyncDiffWindow extends AddonBase {
const b64 = await this._Addon.SyncUtils._getDataURL(image);
imageData[image.key] = b64;
} catch (e) {
Zotero.debug(e);
this._Addon.toolkit.Tool.log(e);
}
}
@ -113,7 +113,7 @@ class SyncDiffWindow extends AddonBase {
this._window.initDiffViewer();
this._window.updateDiffRender([]);
const abort = () => {
console.log("unloaded");
this._Addon.toolkit.Tool.log("unloaded");
io.defer.resolve();
};
// If closed by user, abort syncing
@ -134,12 +134,12 @@ class SyncDiffWindow extends AddonBase {
this._window.closed || this._window.close();
break;
case "unsync":
Zotero.debug("remove synce" + noteItem.getNote());
this._Addon.toolkit.Tool.log("remove synce" + noteItem.getNote());
await this._Addon.SyncController.removeSyncNote(noteItem);
break;
case "finish":
Zotero.debug("Diff result:" + io.result);
console.log("Diff result:", io.result);
this._Addon.toolkit.Tool.log("Diff result:" + io.result);
this._Addon.toolkit.Tool.log("Diff result:", io.result);
// return io.result;
noteItem.setNote(noteStatus.meta + io.result + noteStatus.tail);
await noteItem.saveTx({

View File

@ -2,7 +2,7 @@
* This file contains sync info window related code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
class SyncInfoWindow extends AddonBase {
@ -13,7 +13,7 @@ class SyncInfoWindow extends AddonBase {
deferred?: typeof Promise;
};
public _window: Window;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
}

View File

@ -2,12 +2,12 @@
* This file contains sync list window related code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
class SyncListWindow extends AddonBase {
private _window: Window;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
}

View File

@ -19,12 +19,12 @@ import { h } from "hastscript";
import seedrandom = require("seedrandom");
import YAML = require("yamljs");
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import AddonBase from "../module";
import { NodeMode } from "../utils";
class SyncUtils extends AddonBase {
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
}
@ -129,8 +129,8 @@ class SyncUtils extends AddonBase {
try {
ret.meta = YAML.parse(yaml);
} catch (e) {
Zotero.debug(e);
console.log(e);
this._Addon.toolkit.Tool.log(e);
this._Addon.toolkit.Tool.log(e);
}
}
return ret;
@ -167,8 +167,8 @@ class SyncUtils extends AddonBase {
ret.lastmodify = stat.lastModificationDate;
}
} catch (e) {
Zotero.debug(e);
console.log(e);
this._Addon.toolkit.Tool.log(e);
this._Addon.toolkit.Tool.log(e);
}
return ret;
}
@ -556,7 +556,7 @@ class SyncUtils extends AddonBase {
rehype.children = tempChildren;
console.log("before n2r", rehype);
this._Addon.toolkit.Tool.log("before n2r", rehype);
return unified()
.use(rehypeStringify, {
@ -579,11 +579,11 @@ class SyncUtils extends AddonBase {
async md2note(str) {
const remark = this.md2remark(str);
console.log(remark);
this._Addon.toolkit.Tool.log(remark);
let rehype = await this.remark2rehype(remark);
console.log(rehype);
this._Addon.toolkit.Tool.log(rehype);
const html = this.rehype2note(rehype);
console.log(html);
this._Addon.toolkit.Tool.log(html);
return html;
}
@ -636,8 +636,8 @@ class SyncUtils extends AddonBase {
/zotero:\/\/note\/\w+\/\w+\//.test(node.properties?.href),
(node) => nodes.push(node)
);
Zotero.debug("BN:N2M link");
Zotero.debug(JSON.stringify(nodes));
this._Addon.toolkit.Tool.log("BN:N2M link");
this._Addon.toolkit.Tool.log(JSON.stringify(nodes));
return new Array(...new Set(nodes));
}
@ -673,17 +673,17 @@ class SyncUtils extends AddonBase {
// annotation.uri was used before note-editor v4
let uri = annotation.attachmentURI || annotation.uri;
let position = annotation.position;
Zotero.debug("----Debug Link----");
Zotero.debug(annotation);
console.log("convertAnnotations", node);
this._Addon.toolkit.Tool.log("----Debug Link----");
this._Addon.toolkit.Tool.log(annotation);
this._Addon.toolkit.Tool.log("convertAnnotations", node);
if (typeof uri === "string" && typeof position === "object") {
Zotero.debug(uri);
this._Addon.toolkit.Tool.log(uri);
let openURI;
let uriParts = uri.split("/");
let libraryType = uriParts[3];
let key = uriParts[uriParts.length - 1];
Zotero.debug(key);
this._Addon.toolkit.Tool.log(key);
if (libraryType === "users") {
openURI = "zotero://open-pdf/library/items/" + key;
}
@ -726,9 +726,9 @@ class SyncUtils extends AddonBase {
newChild.properties.ztype = "zhighlight";
newNode = h("zhighlight", [newChild]);
}
console.log(newNode, node);
this._Addon.toolkit.Tool.log(newNode, node);
this.replace(node, newNode);
console.log("converted", newNode, node);
this._Addon.toolkit.Tool.log("converted", newNode, node);
}
}
}
@ -755,7 +755,7 @@ class SyncUtils extends AddonBase {
let uriParts = uri.split("/");
let libraryType = uriParts[3];
let key = uriParts[uriParts.length - 1];
Zotero.debug(key);
this._Addon.toolkit.Tool.log(key);
if (libraryType === "users") {
uris.push("zotero://select/library/items/" + key);
}
@ -791,13 +791,13 @@ class SyncUtils extends AddonBase {
...childNodes.map((child, i) => {
const newNode = h("span");
this.replace(newNode, child);
console.log("cite child", child, newNode);
this._Addon.toolkit.Tool.log("cite child", child, newNode);
newNode.children = [h("a", { href: uris[i] }, child.children)];
return newNode;
}),
{ type: "text", value: ")" },
]);
console.log("cite", newNode);
this._Addon.toolkit.Tool.log("cite", newNode);
const citationKey = this.randomString(
8,
Zotero.Utilities.allowedKeyChars,
@ -832,7 +832,7 @@ class SyncUtils extends AddonBase {
return;
}
for (const node of nodes) {
console.log("note link", node);
this._Addon.toolkit.Tool.log("note link", node);
const noteInfo = infoList.find((i) =>
node.properties.href.includes(i.link)
);
@ -867,9 +867,9 @@ class SyncUtils extends AddonBase {
newChild.properties.class = "internal-link"; // required for obsidian compatibility
const newNode = h("znotelink", [newChild]);
this.replace(node, newNode);
console.log("direct link", node, newNode, newChild);
this._Addon.toolkit.Tool.log("direct link", node, newNode, newChild);
}
console.log("note link parsed", node);
this._Addon.toolkit.Tool.log("note link parsed", node);
}
}
@ -891,19 +891,19 @@ class SyncUtils extends AddonBase {
libraryID,
imgKey
);
Zotero.debug(attachmentItem);
console.log("image", libraryID, imgKey, attachmentItem, node);
this._Addon.toolkit.Tool.log(attachmentItem);
this._Addon.toolkit.Tool.log("image", libraryID, imgKey, attachmentItem, node);
if (!attachmentItem) {
continue;
}
let oldFile = String(await attachmentItem.getFilePathAsync());
Zotero.debug(oldFile);
this._Addon.toolkit.Tool.log(oldFile);
let ext = oldFile.split(".").pop();
let newAbsPath = Zotero.Knowledge4Zotero.NoteUtils.formatPath(
let newAbsPath = Zotero.BetterNotes.NoteUtils.formatPath(
`${Path}/${imgKey}.${ext}`
);
Zotero.debug(newAbsPath);
this._Addon.toolkit.Tool.log(newAbsPath);
let newFile = oldFile;
try {
// Don't overwrite
@ -917,9 +917,9 @@ class SyncUtils extends AddonBase {
absolutePath ? newFile : `attachments/${newFile.split(/\//).pop()}`
);
} catch (e) {
Zotero.debug(e);
this._Addon.toolkit.Tool.log(e);
}
Zotero.debug(newFile);
this._Addon.toolkit.Tool.log(newFile);
node.properties.src = newFile ? newFile : oldFile;
@ -931,7 +931,7 @@ class SyncUtils extends AddonBase {
// this.replace(node, newNode);
node.properties.alt = toHtml(newChild);
}
console.log("zimage", node);
this._Addon.toolkit.Tool.log("zimage", node);
}
}
@ -953,7 +953,7 @@ class SyncUtils extends AddonBase {
node.type === "element" && node.properties?.ztype === "zhighlight",
(node) => nodes.push(node)
);
console.log("N2M:highlight", nodes);
this._Addon.toolkit.Tool.log("N2M:highlight", nodes);
return new Array(...new Set(nodes));
}
@ -996,7 +996,7 @@ class SyncUtils extends AddonBase {
return;
}
console.log("processing M2N meta images", nodes);
this._Addon.toolkit.Tool.log("processing M2N meta images", nodes);
for (const node of nodes) {
if (/zimage/.test(node.properties.alt)) {
const newNode: any = unified()
@ -1004,7 +1004,7 @@ class SyncUtils extends AddonBase {
.use(remarkMath)
.use(rehypeParse, { fragment: true })
.parse(node.properties.alt);
console.log(newNode);
this._Addon.toolkit.Tool.log(newNode);
newNode.properties.src = node.properties.src;
this.replace(node, newNode);
}
@ -1050,8 +1050,8 @@ class SyncUtils extends AddonBase {
// root -> p -> span(cite, this is what we actually want)
this.replace(node, (newNode.children[0] as any).children[0]);
} catch (e) {
Zotero.debug(e);
console.log(e);
this._Addon.toolkit.Tool.log(e);
this._Addon.toolkit.Tool.log(e);
continue;
}
} else {
@ -1089,7 +1089,7 @@ class SyncUtils extends AddonBase {
return;
}
console.log("processing M2N images", nodes);
this._Addon.toolkit.Tool.log("processing M2N images", nodes);
for (const node of nodes) {
if (isImport) {
// We encode the src in md2remark and decode it here.
@ -1105,14 +1105,14 @@ class SyncUtils extends AddonBase {
if (!(await OS.File.exists(src))) {
src = OS.Path.join(fileDir, src);
if (!(await OS.File.exists(src))) {
Zotero.debug("BN:parse image, path invalid");
this._Addon.toolkit.Tool.log("BN:parse image, path invalid");
continue;
}
}
}
const key = await (
Zotero.Knowledge4Zotero as Knowledge4Zotero
).NoteUtils._importImage(noteItem, src, srcType);
Zotero.BetterNotes as BetterNotes
).NoteUtils.importImageToNote(noteItem, src, srcType);
node.properties.dataAttachmentKey = key;
}
delete node.properties.src;

View File

@ -2,14 +2,14 @@
* This file realizes the template feature.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { NoteTemplate } from "../utils";
import AddonBase from "../module";
class TemplateController extends AddonBase {
_systemTemplateNames: string[];
_defaultTemplates: NoteTemplate[];
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this._systemTemplateNames = [
"[QuickInsert]",
@ -27,7 +27,7 @@ class TemplateController extends AddonBase {
},
{
name: "[QuickBackLink]",
text: '<p>Referred in <a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)}?ignore=1&line=${lineIndex}" rel="noopener noreferrer nofollow">${noteItem.getNoteTitle().trim() ? noteItem.getNoteTitle().trim() : "Main Note"}${sectionName?`/${sectionName}`:""}</a></p>',
text: '<p>Referred in <a href="${Zotero.BetterNotes.knowledge.getNoteLink(noteItem)}?ignore=1&line=${lineIndex}" rel="noopener noreferrer nofollow">${noteItem.getNoteTitle().trim() ? noteItem.getNoteTitle().trim() : "Main Note"}${sectionName?`/${sectionName}`:""}</a></p>',
disabled: false,
},
{
@ -37,7 +37,7 @@ class TemplateController extends AddonBase {
},
{
name: "[QuickNoteV4]",
text: '${await new Promise(async (r) => {\nlet res = ""\nif(annotationItem.annotationComment){\nres += await Zotero.Knowledge4Zotero.NoteParse.parseMDToHTML(annotationItem.annotationComment);\n}\nres += await Zotero.Knowledge4Zotero.NoteParse.parseAnnotationHTML(noteItem, [annotationItem], true);\nr(res);})}',
text: '${await new Promise(async (r) => {\nlet res = ""\nif(annotationItem.annotationComment){\nres += await Zotero.BetterNotes.NoteParse.parseMDToHTML(annotationItem.annotationComment);\n}\nres += await Zotero.BetterNotes.NoteParse.parseAnnotationHTML(noteItem, [annotationItem], true);\nr(res);})}',
disabled: false,
},
{
@ -52,7 +52,7 @@ class TemplateController extends AddonBase {
},
{
name: "[Item] item-notes with metadata",
text: '<h1>${topItem.getField("title")}</h1>\n<h2 style="color:red; background-color: #efe3da;">💡 Meta Data</h2>\n<table>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Title </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'title\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Journal </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getField(\'publicationTitle\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">1<sup>st</sup> Author </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'firstCreator\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Authors </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Pub. date </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'date\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">DOI </p>\n </th>\n <td style="background-color:#f3faf4;">\n <a href="https://doi.org/${topItem.getField(\'DOI\')}">${topItem.getField(\'DOI\')}</a>\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Archive </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'archive\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Archive Location </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getField(\'archiveLocation\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Call No. </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'callNumber\')}\n </td>\n </tr>\n</table>\n${itemNotes.map((noteItem)=>{\nconst noteLine = `<h2 style="color:red; background-color: #efe3da;">📜 Note: <a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)}" rel="noopener noreferrer nofollow">${noteItem.key}</a></h2>\n<blockquote>\n ${noteItem.getNote()}\n <p style="background-color: pink;"><strong>Merge Date: </strong> ${new Date().toISOString().substr(0,10)+" "+ new Date().toTimeString()}</p>\n</blockquote>\n<p style="color:red; background-color: #efe3da;"><strong>📝 Comments</strong></p>\n<blockquote>\n <p>Make your comments</p>\n <p></p>\n</blockquote>`;\ncopyNoteImage(noteItem);\nreturn noteLine;\n}).join("\\n")}\n',
text: '<h1>${topItem.getField("title")}</h1>\n<h2 style="color:red; background-color: #efe3da;">💡 Meta Data</h2>\n<table>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Title </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'title\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Journal </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getField(\'publicationTitle\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">1<sup>st</sup> Author </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'firstCreator\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Authors </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Pub. date </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'date\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">DOI </p>\n </th>\n <td style="background-color:#f3faf4;">\n <a href="https://doi.org/${topItem.getField(\'DOI\')}">${topItem.getField(\'DOI\')}</a>\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Archive </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'archive\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#f3faf4;">\n <p style="text-align: right">Archive Location </p>\n </th>\n <td style="background-color:#f3faf4;">\n ${topItem.getField(\'archiveLocation\')}\n </td>\n </tr>\n <tr>\n <th style="background-color:#dbeedd;">\n <p style="text-align: right">Call No. </p>\n </th>\n <td style="background-color:#dbeedd;">\n ${topItem.getField(\'callNumber\')}\n </td>\n </tr>\n</table>\n${itemNotes.map((noteItem)=>{\nconst noteLine = `<h2 style="color:red; background-color: #efe3da;">📜 Note: <a href="${Zotero.BetterNotes.knowledge.getNoteLink(noteItem)}" rel="noopener noreferrer nofollow">${noteItem.key}</a></h2>\n<blockquote>\n ${noteItem.getNote()}\n <p style="background-color: pink;"><strong>Merge Date: </strong> ${new Date().toISOString().substr(0,10)+" "+ new Date().toTimeString()}</p>\n</blockquote>\n<p style="color:red; background-color: #efe3da;"><strong>📝 Comments</strong></p>\n<blockquote>\n <p>Make your comments</p>\n <p></p>\n</blockquote>`;\ncopyNoteImage(noteItem);\nreturn noteLine;\n}).join("\\n")}\n',
disabled: false,
},
{
@ -67,7 +67,7 @@ class TemplateController extends AddonBase {
},
{
name: "[Item] note links",
text: '<p><a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(topItem)}">${topItem.getNoteTitle().trim() ? topItem.getNoteTitle().trim() : Zotero.Knowledge4Zotero.knowledge.getNoteLink(topItem)}</a></p>',
text: '<p><a href="${Zotero.BetterNotes.knowledge.getNoteLink(topItem)}">${topItem.getNoteTitle().trim() ? topItem.getNoteTitle().trim() : Zotero.BetterNotes.knowledge.getNoteLink(topItem)}</a></p>',
disabled: false,
},
{
@ -85,7 +85,7 @@ class TemplateController extends AddonBase {
useDefault: boolean = true,
stage: string = "default"
) {
Zotero.debug(`renderTemplateAsync: ${key}`);
this._Addon.toolkit.Tool.log(`renderTemplateAsync: ${key}`);
let templateText = this.getTemplateText(key);
if (useDefault && !templateText) {
templateText = this._defaultTemplates.find((t) => t.name === key).text;
@ -117,11 +117,11 @@ class TemplateController extends AddonBase {
async function () {}
).constructor;
const _ = new AsyncFunction(argString, "return `" + templateText + "`");
console.log(_);
this._Addon.toolkit.Tool.log(_);
_newLine = await _(...argList);
} catch (e) {
alert(`Template ${key} Error: ${e}`);
console.log(e);
this._Addon.toolkit.Tool.log(e);
return "";
}
return _newLine;
@ -258,7 +258,7 @@ class TemplateController extends AddonBase {
* to keep API consistency
*/
class TemplateAPI extends AddonBase {
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
}

View File

@ -2,13 +2,13 @@
* This file contains template window related code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { NoteTemplate } from "../utils";
import AddonBase from "../module";
class TemplateWindow extends AddonBase {
private _window: Window;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
}
@ -77,8 +77,8 @@ class TemplateWindow extends AddonBase {
}
updateEditorView() {
Zotero.debug("update editor");
console.log("update editor");
this._Addon.toolkit.Tool.log("update editor");
this._Addon.toolkit.Tool.log("update editor");
const name = this.getSelectedTemplateName();
const templateText = this._Addon.TemplateController.getTemplateText(name);

View File

@ -41,21 +41,4 @@ enum NodeMode {
direct,
}
function getDOMParser(): DOMParser {
if (Zotero.platformMajorVersion > 60) {
return new DOMParser();
} else {
return Components.classes[
"@mozilla.org/xmlextras/domparser;1"
].createInstance(Components.interfaces.nsIDOMParser);
}
}
export {
EditorMessage,
OutlineType,
NoteTemplate,
SyncCode,
NodeMode,
getDOMParser,
};
export { EditorMessage, OutlineType, NoteTemplate, SyncCode, NodeMode };

View File

@ -2,7 +2,7 @@
* This file contains the first-run wizard window code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { EditorMessage } from "../utils";
import AddonBase from "../module";
@ -14,7 +14,7 @@ class WizardWindow extends AddonBase {
template: string;
templateCN: string;
private _document: Document;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.enableSetup = true;
this.enableCollection = true;
@ -209,7 +209,7 @@ class WizardWindow extends AddonBase {
}
init(_document: Document) {
this._document = _document;
Zotero.debug("Knowledge4Zotero: Initialize AddonWizard.");
this._Addon.toolkit.Tool.log("Initialize AddonWizard.")
this.updateCollectionSetup();
}
changeSetup() {

View File

@ -2,12 +2,12 @@
* This file contains workspace menu related code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { OutlineType } from "../utils";
import AddonBase from "../module";
class WorkspaceMenu extends AddonBase {
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
}

View File

@ -2,7 +2,7 @@
* This file contains workspace ontline related code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { OutlineType } from "../utils";
import AddonBase from "../module";
@ -10,7 +10,7 @@ class WorkspaceOutline extends AddonBase {
public currentOutline: OutlineType;
public currentNodeID: number;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.currentOutline = OutlineType.treeView;
this.currentNodeID = -1;
@ -64,7 +64,7 @@ class WorkspaceOutline extends AddonBase {
}
public async updateOutline() {
Zotero.debug("Knowledge4Zotero: updateMindMap");
this._Addon.toolkit.Tool.log("updateMindMap")
// await this._initIframe.promise;
const _window = this._Addon.WorkspaceWindow.getWorkspaceWindow();
if (!_window) {
@ -87,7 +87,7 @@ class WorkspaceOutline extends AddonBase {
}
public saveImage() {
Zotero.debug("Knowledge4Zotero: saveImage");
this._Addon.toolkit.Tool.log("saveImage")
const _window = this._Addon.WorkspaceWindow.getWorkspaceWindow();
if (!_window) {
return;

View File

@ -2,7 +2,7 @@
* This file contains workspace window related code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { EditorMessage, OutlineType } from "../utils";
import AddonBase from "../module";
@ -16,7 +16,7 @@ class WorkspaceWindow extends AddonBase {
public _workspacePromise: _ZoteroPromiseObject;
private _DOMParser: any;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this._initIframe = Zotero.Promise.defer();
this.workspaceTabId = "";
@ -37,7 +37,7 @@ class WorkspaceWindow extends AddonBase {
) {
if (this.getWorkspaceWindow()) {
if (!reopen) {
Zotero.debug("openWorkspaceWindow: focus");
this._Addon.toolkit.Tool.log("openWorkspaceWindow: focus");
if (this.workspaceTabId !== "WINDOW") {
Zotero_Tabs.select(this.workspaceTabId);
} else {
@ -45,7 +45,7 @@ class WorkspaceWindow extends AddonBase {
}
return;
} else {
Zotero.debug("openWorkspaceWindow: reopen");
this._Addon.toolkit.Tool.log("openWorkspaceWindow: reopen");
this.closeWorkspaceWindow();
}
}
@ -53,7 +53,7 @@ class WorkspaceWindow extends AddonBase {
this._workspacePromise = Zotero.Promise.defer();
this._firstInit = true;
if (type === "window") {
Zotero.debug("openWorkspaceWindow: as window");
this._Addon.toolkit.Tool.log("openWorkspaceWindow: as window");
this._initIframe = Zotero.Promise.defer();
let win = window.open(
"chrome://Knowledge4Zotero/content/workspace.xul",
@ -70,7 +70,7 @@ class WorkspaceWindow extends AddonBase {
this._Addon.WorkspaceOutline.updateOutline();
this._Addon.ZoteroViews.updateAutoInsertAnnotationsMenu();
} else {
Zotero.debug("openWorkspaceWindow: as tab");
this._Addon.toolkit.Tool.log("openWorkspaceWindow: as tab");
this._initIframe = Zotero.Promise.defer();
// Avoid sidebar show up
Zotero_Tabs.jump(0);
@ -175,8 +175,8 @@ class WorkspaceWindow extends AddonBase {
}
private async messageHandler(e) {
Zotero.debug(`Knowledge4Zotero: view message ${e.data.type}`);
console.log(`Knowledge4Zotero: view message ${e.data.type}`);
this._Addon.toolkit.Tool.log(`Knowledge4Zotero: view message ${e.data.type}`);
this._Addon.toolkit.Tool.log(`Knowledge4Zotero: view message ${e.data.type}`);
if (e.data.type === "ready") {
this._initIframe.resolve();
} else if (e.data.type === "getMindMapData") {
@ -188,7 +188,7 @@ class WorkspaceWindow extends AddonBase {
})
);
} else if (e.data.type === "jumpNote") {
Zotero.debug(e.data);
this._Addon.toolkit.Tool.log(e.data);
this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("onNoteLink", {
params: await this._Addon.NoteUtils.getNoteFromLink(e.data.link),
@ -201,7 +201,7 @@ class WorkspaceWindow extends AddonBase {
e.data.moveType
);
} else if (e.data.type === "saveSVGReturn") {
console.log(e.data.image);
this._Addon.toolkit.Tool.log(e.data.image);
const filename = await this._Addon.toolkit.Tool.openFilePicker(
`${Zotero.getString("fileInterface.export")} SVG Image`,
"save",

View File

@ -2,214 +2,30 @@
* This file contains the life-time and UI events.
*/
import TreeModel = require("tree-model");
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { EditorMessage } from "../utils";
import AddonBase from "../module";
import { addonName } from "../../package.json";
class ZoteroEvents extends AddonBase {
notifierCallback: any;
notifierCbkDict: any;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.notifierCallback = {
notify: async (
event: string,
type: string,
ids: Array<number | string>,
extraData: object
) => {
if (event === "modify" && type === "item") {
if (
ids.indexOf(
Zotero.Prefs.get("Knowledge4Zotero.mainKnowledgeID") as number
) >= 0
) {
Zotero.debug("Knowledge4Zotero: main knowledge modify check.");
this._Addon.WorkspaceOutline.updateOutline();
this._Addon.ZoteroViews.updateWordCount();
}
// Check Note Sync
const syncIds = this._Addon.SyncController.getSyncNoteIds();
const modifiedSyncIds = ids.filter((id) =>
syncIds.includes(id as number)
) as number[];
if (modifiedSyncIds.length > 0) {
// Delay so that item content is ready
setTimeout(() => {
this._Addon.SyncController.doSync(
Zotero.Items.get(modifiedSyncIds)
);
}, 10000);
Zotero.debug("Better Notes: sync planned.");
}
}
if (
(event == "select" &&
type == "tab" &&
extraData[ids[0]].type == "reader") ||
(event === "add" &&
type === "item" &&
(Zotero.Items.get(ids as number[]) as Zotero.Item[]).filter(
(item) => {
return item.isAnnotation();
}
).length > 0) ||
(event === "close" && type === "tab") ||
(event === "open" && type === "file")
) {
await this._Addon.ReaderViews.buildReaderAnnotationButtons();
}
if (event == "add" && type == "tab") {
if (ids[0] === this._Addon.WorkspaceWindow.workspaceTabId) {
const tabItem = document.querySelector(`.tab[data-id=${ids[0]}]`);
const tabTitle = tabItem && tabItem.querySelector(".tab-name");
tabTitle &&
(tabTitle.innerHTML = `${this._Addon.ZoteroViews.icons["tabIcon"]}${tabTitle.innerHTML}`);
}
}
if (event == "select" && type == "tab") {
if (extraData[ids[0]].type == "betternotes") {
let t = 0;
await this._Addon.WorkspaceWindow.waitWorkspaceReady();
while (
!(await this._Addon.WorkspaceWindow.getWorkspaceEditorInstance(
"main",
false
)) &&
t < 100
) {
t += 1;
this._Addon.WorkspaceWindow.setWorkspaceNote(
"main",
undefined,
false
);
await Zotero.Promise.delay(100);
}
const _tabCover = document.getElementById("zotero-tab-cover");
const _contextPane = document.getElementById(
"zotero-context-pane"
) as XUL.Element;
const _contextPaneSplitter = document.getElementById(
"zotero-context-splitter"
) as XUL.Element;
const _tabToolbar = document.getElementById("zotero-tab-toolbar");
_contextPaneSplitter.setAttribute("hidden", true);
_contextPane.setAttribute("collapsed", true);
_tabToolbar && (_tabToolbar.hidden = true);
_tabCover && (_tabCover.hidden = true);
this._Addon.ZoteroViews.switchRealMenuBar(false);
this._Addon.ZoteroViews.switchKey(false);
this._Addon.ZoteroViews.updateWordCount();
} else {
this._Addon.ZoteroViews.switchRealMenuBar(true);
this._Addon.ZoteroViews.switchKey(true);
}
}
if (
Zotero.Prefs.get("Knowledge4Zotero.autoAnnotation") &&
event === "add" &&
type === "item" &&
(Zotero.Items.get(ids as number[]) as Zotero.Item[]).filter(
(item) => {
return item.isAnnotation();
}
).length > 0
) {
Zotero.debug("Knowledge4Zotero: autoAnnotation");
const annotations = (
Zotero.Items.get(ids as number[]) as Zotero.Item[]
).filter((item) => {
return item.isAnnotation();
});
this.onEditorEvent(
new EditorMessage("addAnnotationToNote", {
params: { annotations: annotations },
})
);
}
if (event === "add" && type === "item-tag") {
const nodes: TreeModel.Node<object>[] =
this._Addon.NoteUtils.getNoteTreeAsList(
this._Addon.WorkspaceWindow.getWorkspaceNote()
);
const headings: string[] = nodes.map((node) => node.model.name);
console.log(ids, extraData, headings);
for (const tagId of ids.filter((t) => extraData[t].tag[0] === "#")) {
const tagName = (extraData[tagId].tag as string).slice(1).trim();
if (headings.includes(tagName) || tagName === "#") {
let lineIndex: number;
let sectionName: string;
if (tagName === "#") {
lineIndex = -1;
sectionName = "";
} else {
const targetNode = nodes.find(
(node) => node.model.name === tagName
);
lineIndex = targetNode.model.endIndex;
sectionName = targetNode.model.name;
}
const item = Zotero.Items.get(
(tagId as string).split("-")[0]
) as Zotero.Item;
if (item.isAnnotation()) {
this.onEditorEvent(
new EditorMessage("addAnnotationToNote", {
params: {
annotations: [item],
lineIndex: lineIndex,
sectionName: sectionName,
},
})
);
} else if (item.isNote()) {
this.onEditorEvent(
new EditorMessage("addToNote", {
params: {
itemID: item.id,
lineIndex: lineIndex,
sectionName: sectionName,
},
})
);
}
}
}
}
for (const cbk of Object.values(this.notifierCbkDict)) {
(cbk as Function)(event, type, ids, extraData);
}
},
};
this.notifierCbkDict = {};
}
public async onInit() {
Zotero.debug("Knowledge4Zotero: init called");
const development = "development";
const production = "production";
// The env will be replaced after esbuild
// @ts-ignore
this._Addon.env = __env__;
this._Addon.toolkit.Tool.logOptionsGlobal.prefix = `[${addonName}]`;
this._Addon.toolkit.Tool.logOptionsGlobal.disableConsole =
this._Addon.env === "production";
this._Addon.toolkit.Tool.log("init called")
this.initProxyHandler();
this.addEditorInstanceListener();
// Register the callback in Zotero as an item observer
let notifierID = Zotero.Notifier.registerObserver(this.notifierCallback, [
"item",
"tab",
"file",
"item-tag",
]);
// Unregister callback when the window closes (important to avoid a memory leak)
window.addEventListener(
"unload",
(e) => {
Zotero.Notifier.unregisterObserver(notifierID);
},
false
);
this._Addon.ZoteroNotifies.initNotifyCallback();
await Zotero.uiReadyPromise;
this._Addon.ZoteroViews.addOpenWorkspaceButton();
@ -254,11 +70,11 @@ class ZoteroEvents extends AddonBase {
private async initWorkspaceTab() {
let state = Zotero.Session.state.windows.find((x) => x.type === "pane");
Zotero.debug("initWorkspaceTab");
Zotero.debug(state);
this._Addon.toolkit.Tool.log("initWorkspaceTab");
this._Addon.toolkit.Tool.log(state);
if (state) {
const noteTab = state.tabs.find((t) => t.type === "betternotes");
Zotero.debug(noteTab);
this._Addon.toolkit.Tool.log(noteTab);
if (noteTab) {
let t = 0;
while (t < 5) {
@ -311,9 +127,9 @@ class ZoteroEvents extends AddonBase {
return;
}
Zotero.debug(`Knowledge4Zotero: note editor initializing...`);
this._Addon.toolkit.Tool.log(`Knowledge4Zotero: note editor initializing...`);
await this._Addon.EditorViews.initEditor(instance);
Zotero.debug(`Knowledge4Zotero: note editor initialized.`);
this._Addon.toolkit.Tool.log(`Knowledge4Zotero: note editor initialized.`);
if (!instance._knowledgeSelectionInitialized) {
// Put event listeners here to access Zotero instance
@ -433,7 +249,7 @@ class ZoteroEvents extends AddonBase {
instance._popup.setAttribute(
"onpopupshowing",
"Zotero.Knowledge4Zotero.EditorViews.updatePopupMenu()"
"Zotero.BetterNotes.EditorViews.updatePopupMenu()"
);
instance._iframeWindow.addEventListener("mousedown", (e) => {
@ -468,16 +284,8 @@ class ZoteroEvents extends AddonBase {
this._Addon.ZoteroViews.updateAutoInsertAnnotationsMenu();
}
public addNotifyListener(name: string, cbk: Function) {
this.notifierCbkDict[name] = cbk;
}
public removeNotifyListener(name: string) {
delete this.notifierCbkDict[name];
}
public async onEditorEvent(message: EditorMessage) {
Zotero.debug(`Knowledge4Zotero: onEditorEvent\n${message.type}`);
this._Addon.toolkit.Tool.log(`Knowledge4Zotero: onEditorEvent\n${message.type}`);
const mainNote = this._Addon.WorkspaceWindow.getWorkspaceNote();
if (message.type === "openUserGuide") {
/*
@ -591,7 +399,7 @@ class ZoteroEvents extends AddonBase {
params: {itemID, enableConfirm, enableOpen}
}
*/
Zotero.debug("Knowledge4Zotero: setMainNote");
this._Addon.toolkit.Tool.log("setMainNote")
let mainKnowledgeID = parseInt(
Zotero.Prefs.get("Knowledge4Zotero.mainKnowledgeID") as string
);
@ -638,7 +446,7 @@ class ZoteroEvents extends AddonBase {
? message.content.editorInstance._item
: message.content.params.noteItem;
let topItems: Zotero.Item[] = [];
console.log(message);
this._Addon.toolkit.Tool.log(message);
if (message.content.event) {
const topItemID = Number(
message.content.event.target.id.split("-").pop()
@ -689,7 +497,7 @@ class ZoteroEvents extends AddonBase {
editorInstance
}
*/
Zotero.debug("Knowledge4Zotero: addToNoteEnd");
this._Addon.toolkit.Tool.log("addToNoteEnd")
await this._Addon.NoteUtils.addLinkToNote(
mainNote,
(message.content.editorInstance as Zotero.EditorInstance)._item,
@ -709,11 +517,11 @@ class ZoteroEvents extends AddonBase {
}
}
*/
Zotero.debug("Knowledge4Zotero: addToNote");
this._Addon.toolkit.Tool.log("addToNote")
let lineIndex = message.content.params?.lineIndex;
if (typeof lineIndex === "undefined") {
const eventInfo = (message.content.event as XUL.XULEvent).target.id;
Zotero.debug(eventInfo);
this._Addon.toolkit.Tool.log(eventInfo);
const idSplit = eventInfo.split("-");
lineIndex = parseInt(idSplit.pop());
}
@ -730,55 +538,13 @@ class ZoteroEvents extends AddonBase {
lineIndex,
sectionName
);
} else if (message.type === "addAnnotationToNote") {
/*
message.content = {
params: {
annotations: Zotero.Item[],
lineIndex?: number
}
}
*/
const useLineIndex = message.content.params?.lineIndex >= 0;
let currentLine = useLineIndex ? message.content.params?.lineIndex : -1;
const annotations = message.content.params.annotations;
const workspaceNote = this._Addon.WorkspaceWindow.getWorkspaceNote();
const html = await this._Addon.NoteUtils.addAnnotationsToNote(
workspaceNote,
annotations,
currentLine
);
if (!useLineIndex) {
currentLine = this._Addon.NoteUtils.currentLine[workspaceNote.id];
currentLine = currentLine >= 0 ? currentLine : -1;
if (currentLine >= 0) {
// Compute annotation lines length
const temp = this._Addon.toolkit.UI.createElement(
document,
"div"
) as HTMLDivElement;
temp.innerHTML = html;
const elementList = this._Addon.NoteParse.parseHTMLElements(temp);
// Move cursor foward
this._Addon.NoteUtils.currentLine[workspaceNote.id] +=
elementList.length;
}
}
this._Addon.ZoteroViews.showProgressWindow(
"Better Notes",
`Insert Annotation to ${
currentLine >= 0 ? `line ${currentLine} in` : "end of"
} main note`
);
} else if (message.type === "jumpNode") {
/*
message.content = {
params: {id, lineIndex}
}
*/
Zotero.debug(message.content.params);
this._Addon.toolkit.Tool.log(message.content.params);
let editorInstance =
await this._Addon.WorkspaceWindow.getWorkspaceEditorInstance();
// Set node id
@ -815,9 +581,9 @@ class ZoteroEvents extends AddonBase {
const forceStandalone = message.content.params.forceStandalone;
let _window = this._Addon.WorkspaceWindow.getWorkspaceWindow();
if (!noteItem) {
Zotero.debug(`Knowledge4Zotero: ${message.content.params.infoText}`);
this._Addon.toolkit.Tool.log(`Knowledge4Zotero: ${message.content.params.infoText}`);
}
Zotero.debug(`Knowledge4Zotero: onNoteLink ${noteItem.id}`);
this._Addon.toolkit.Tool.log(`Knowledge4Zotero: onNoteLink ${noteItem.id}`);
if (
!forceStandalone &&
_window &&
@ -917,7 +683,7 @@ class ZoteroEvents extends AddonBase {
newLines.push("<p> </p>");
const html = newLines.join("\n");
if (!targetItem) {
console.log(html);
this._Addon.toolkit.Tool.log(html);
this._Addon.toolkit.Tool.getCopyHelper()
.addText(html, "text/html")
.addText(
@ -1035,7 +801,7 @@ class ZoteroEvents extends AddonBase {
if (newLines) {
const html = newLines.join("\n");
if (!targetItem) {
console.log(html);
this._Addon.toolkit.Tool.log(html);
this._Addon.toolkit.Tool.getCopyHelper()
.addText(html, "text/html")
@ -1047,7 +813,7 @@ class ZoteroEvents extends AddonBase {
progressWindow.changeHeadline("Template Copied");
} else {
const forceMetadata = toCopyImage.length > 0;
console.log(toCopyImage);
this._Addon.toolkit.Tool.log(toCopyImage);
await this._Addon.NoteUtils.addLineToNote(
targetItem,
html,
@ -1190,20 +956,20 @@ class ZoteroEvents extends AddonBase {
const note = editor._item;
if (note.parentItem) {
const attachment = await note.parentItem.getBestAttachment();
Zotero.debug(attachment);
this._Addon.toolkit.Tool.log(attachment);
if (!attachment) {
return;
}
try {
Zotero.debug("Launching PDF without page number");
this._Addon.toolkit.Tool.log("Launching PDF without page number");
let zp = Zotero.getActiveZoteroPane();
if (zp) {
zp.viewAttachment([attachment.id]);
}
Zotero.Notifier.trigger("open", "file", attachment.id);
} catch (e) {
Zotero.debug("Knowledge4Zotero: Open attachment failed:");
Zotero.debug(attachment);
this._Addon.toolkit.Tool.log("Open attachment failed:")
this._Addon.toolkit.Tool.log(attachment);
this._Addon.ZoteroViews.showProgressWindow(
"Better Notes",
"Error occurred on opening attachemnts.",
@ -1270,7 +1036,7 @@ class ZoteroEvents extends AddonBase {
return;
}
const html = await this._Addon.NoteParse.parseMDToHTML(source);
console.log(source, html);
this._Addon.toolkit.Tool.log(source, html);
this._Addon.toolkit.Tool.getCopyHelper()
.addText(html, "text/html")
.copy();
@ -1292,7 +1058,7 @@ class ZoteroEvents extends AddonBase {
return;
}
const html = this._Addon.NoteParse.parseAsciiDocToHTML(source);
console.log(source, html);
this._Addon.toolkit.Tool.log(source, html);
this._Addon.toolkit.Tool.getCopyHelper()
.addText(html, "text/html")
.copy();
@ -1302,7 +1068,7 @@ class ZoteroEvents extends AddonBase {
"Converted AsciiDoc is updated to the clipboard. You can paste them in the note."
);
} else {
Zotero.debug(`Knowledge4Zotero: message not handled.`);
this._Addon.toolkit.Tool.log(`Knowledge4Zotero: message not handled.`);
}
}
}

291
src/zotero/notifies.ts Normal file
View File

@ -0,0 +1,291 @@
import TreeModel = require("tree-model");
import BetterNotes from "../addon";
import AddonBase from "../module";
import { EditorMessage } from "../utils";
export default class ZoteroNotifies extends AddonBase {
notifierCbkDict: { [key: string]: Function };
constructor(parent: BetterNotes) {
super(parent);
this.notifierCbkDict = {};
}
public registerNotifyListener(name: string, cbk: Function) {
this.notifierCbkDict[name] = cbk;
}
public unregisterNotifyListener(name: string) {
delete this.notifierCbkDict[name];
}
initNotifyCallback() {
// Register the callback in Zotero as an item observer
const notifierCallback = {
notify: async (
event: string,
type: string,
ids: Array<number | string>,
extraData: object
) => {
for (const cbk of Object.values(this.notifierCbkDict)) {
try {
(cbk as Function)(event, type, ids, extraData);
} catch (e) {
this._Addon.toolkit.Tool.log(e);
}
}
},
};
let notifierID = Zotero.Notifier.registerObserver(notifierCallback, [
"item",
"tab",
"file",
"item-tag",
]);
this.registerDefaultCallbacks();
// Unregister callback when the window closes (important to avoid a memory leak)
window.addEventListener(
"unload",
(e) => {
Zotero.Notifier.unregisterObserver(notifierID);
},
false
);
}
// TODO: move these to seperate functions under different modules
registerDefaultCallbacks() {
const itemModifyCallback = async (
event: string,
type: string,
ids: Array<number | string>,
extraData: object
) => {
if (event === "modify" && type === "item") {
if (
ids.indexOf(
Zotero.Prefs.get("Knowledge4Zotero.mainKnowledgeID") as number
) >= 0
) {
this._Addon.toolkit.Tool.log("main knowledge modify check.");
this._Addon.WorkspaceOutline.updateOutline();
this._Addon.ZoteroViews.updateWordCount();
}
// Check Note Sync
const syncIds = this._Addon.SyncController.getSyncNoteIds();
const modifiedSyncIds = ids.filter((id) =>
syncIds.includes(id as number)
) as number[];
if (modifiedSyncIds.length > 0) {
// Delay so that item content is ready
setTimeout(() => {
this._Addon.SyncController.doSync(
Zotero.Items.get(modifiedSyncIds)
);
}, 10000);
this._Addon.toolkit.Tool.log("sync planned.");
}
}
};
const annotationDispalyCallback = async (
event: string,
type: string,
ids: Array<number | string>,
extraData: object
) => {
if (
(event == "select" &&
type == "tab" &&
extraData[ids[0]].type == "reader") ||
(event === "add" &&
type === "item" &&
(Zotero.Items.get(ids as number[]) as Zotero.Item[]).filter(
(item) => {
return item.isAnnotation();
}
).length > 0) ||
(event === "close" && type === "tab") ||
(event === "open" && type === "file")
) {
await this._Addon.ReaderViews.buildReaderAnnotationButtons();
}
};
const addWorkspaceTabCallback = async (
event: string,
type: string,
ids: Array<number | string>,
extraData: object
) => {
if (
event == "add" &&
type == "tab" &&
ids[0] === this._Addon.WorkspaceWindow.workspaceTabId
) {
const tabItem = document.querySelector(`.tab[data-id=${ids[0]}]`);
const tabTitle = tabItem && tabItem.querySelector(".tab-name");
tabTitle &&
(tabTitle.innerHTML = `${this._Addon.ZoteroViews.icons["tabIcon"]}${tabTitle.innerHTML}`);
}
};
const selectWorkspaceTabCallback = async (
event: string,
type: string,
ids: Array<number | string>,
extraData: object
) => {
if (
event == "select" &&
type == "tab" &&
extraData[ids[0]].type == "betternotes"
) {
let t = 0;
await this._Addon.WorkspaceWindow.waitWorkspaceReady();
while (
!(await this._Addon.WorkspaceWindow.getWorkspaceEditorInstance(
"main",
false
)) &&
t < 100
) {
t += 1;
this._Addon.WorkspaceWindow.setWorkspaceNote(
"main",
undefined,
false
);
await Zotero.Promise.delay(100);
}
const _tabCover = document.getElementById("zotero-tab-cover");
const _contextPane = document.getElementById(
"zotero-context-pane"
) as XUL.Element;
const _contextPaneSplitter = document.getElementById(
"zotero-context-splitter"
) as XUL.Element;
const _tabToolbar = document.getElementById("zotero-tab-toolbar");
_contextPaneSplitter.setAttribute("hidden", true);
_contextPane.setAttribute("collapsed", true);
_tabToolbar && (_tabToolbar.hidden = true);
_tabCover && (_tabCover.hidden = true);
this._Addon.ZoteroViews.switchRealMenuBar(false);
this._Addon.ZoteroViews.switchKey(false);
this._Addon.ZoteroViews.updateWordCount();
} else {
this._Addon.ZoteroViews.switchRealMenuBar(true);
this._Addon.ZoteroViews.switchKey(true);
}
};
const autoAnnotationCallback = async (
event: string,
type: string,
ids: Array<number | string>,
extraData: object
) => {
if (
Zotero.Prefs.get("Knowledge4Zotero.autoAnnotation") &&
event === "add" &&
type === "item" &&
(Zotero.Items.get(ids as number[]) as Zotero.Item[]).filter((item) => {
return item.isAnnotation();
}).length > 0
) {
this._Addon.toolkit.Tool.log("autoAnnotation");
const annotations = (
Zotero.Items.get(ids as number[]) as Zotero.Item[]
).filter((item) => {
return item.isAnnotation();
});
this._Addon.NoteUtils.addAnnotationsToNote(
this._Addon.WorkspaceWindow.getWorkspaceNote(),
annotations,
-1,
true
);
}
};
const addToNoteTriggeredByTagCallback = async (
event: string,
type: string,
ids: Array<number | string>,
extraData: object
) => {
if (event === "add" && type === "item-tag") {
const nodes: TreeModel.Node<object>[] =
this._Addon.NoteUtils.getNoteTreeAsList(
this._Addon.WorkspaceWindow.getWorkspaceNote()
);
const headings: string[] = nodes.map((node) => node.model.name);
this._Addon.toolkit.Tool.log(ids, extraData, headings);
for (const tagId of ids.filter((t) => extraData[t].tag[0] === "#")) {
const tagName = (extraData[tagId].tag as string).slice(1).trim();
if (headings.includes(tagName) || tagName === "#") {
let lineIndex: number;
let sectionName: string;
if (tagName === "#") {
lineIndex = -1;
sectionName = "";
} else {
const targetNode = nodes.find(
(node) => node.model.name === tagName
);
lineIndex = targetNode.model.endIndex;
sectionName = targetNode.model.name;
}
const item = Zotero.Items.get(
(tagId as string).split("-")[0]
) as Zotero.Item;
if (item.isAnnotation()) {
this._Addon.NoteUtils.addAnnotationsToNote(
this._Addon.WorkspaceWindow.getWorkspaceNote(),
[item],
-1,
true
);
} else if (item.isNote()) {
this._Addon.ZoteroEvents.onEditorEvent(
new EditorMessage("addToNote", {
params: {
itemID: item.id,
lineIndex: lineIndex,
sectionName: sectionName,
},
})
);
}
}
}
}
};
this.registerNotifyListener("itemModifyCallback", itemModifyCallback);
this.registerNotifyListener(
"annotationDispalyCallback",
annotationDispalyCallback
);
this.registerNotifyListener(
"addWorkspaceTabCallback",
addWorkspaceTabCallback
);
this.registerNotifyListener(
"selectWorkspaceTabCallback",
selectWorkspaceTabCallback
);
this.registerNotifyListener(
"autoAnnotationCallback",
autoAnnotationCallback
);
this.registerNotifyListener(
"addToNoteTriggeredByTagCallback",
addToNoteTriggeredByTagCallback
);
}
}

View File

@ -2,7 +2,7 @@
* This file contains the Zotero UI code.
*/
import Knowledge4Zotero from "../addon";
import BetterNotes from "../addon";
import { EditorMessage } from "../utils";
import AddonBase from "../module";
@ -10,7 +10,7 @@ class ZoteroViews extends AddonBase {
progressWindowIcon: object;
icons: object;
constructor(parent: Knowledge4Zotero) {
constructor(parent: BetterNotes) {
super(parent);
this.progressWindowIcon = {
success: "chrome://zotero/skin/tick.png",
@ -229,7 +229,7 @@ class ZoteroViews extends AddonBase {
: Zotero_Tabs.selectedID === this._Addon.WorkspaceWindow.workspaceTabId
? this._Addon.WorkspaceWindow.getWorkspaceNote().id
: -1;
Zotero.debug(`updateTemplateMenu`);
this._Addon.toolkit.Tool.log(`updateTemplateMenu`);
let templates = this._Addon.TemplateController.getTemplateKeys()
.filter((e) => e.name.indexOf(type) !== -1)
.filter(
@ -260,7 +260,7 @@ class ZoteroViews extends AddonBase {
menuitem.setAttribute(
"oncommand",
`
Zotero.Knowledge4Zotero.ZoteroEvents.onEditorEvent({
Zotero.BetterNotes.ZoteroEvents.onEditorEvent({
type: "insert${type}UsingTemplate",
content: {
params: { templateName: "${template.name}", targetItemId: ${targetItemId}, useMainNote: ${useMainNote} },
@ -278,7 +278,7 @@ class ZoteroViews extends AddonBase {
// To deprecate
public updateCitationStyleMenu() {
const _window = this._Addon.WorkspaceMenu.getWorkspaceMenuWindow();
Zotero.debug(`updateCitationStyleMenu`);
this._Addon.toolkit.Tool.log(`updateCitationStyleMenu`);
const popup = _window.document.getElementById("menu_citeSettingPopup");
popup.innerHTML = "";
@ -315,7 +315,7 @@ class ZoteroViews extends AddonBase {
}
public updateOCRStyleMenu() {
Zotero.debug(`updateOCRStyleMenu`);
this._Addon.toolkit.Tool.log(`updateOCRStyleMenu`);
const popup = document.getElementById("menu_ocrsettingpopup");
Array.prototype.forEach.call(popup.children, (e) =>
e.setAttribute("checked", false)
@ -335,7 +335,7 @@ class ZoteroViews extends AddonBase {
if (!_window) {
return;
}
Zotero.debug("updateWordCount");
this._Addon.toolkit.Tool.log("updateWordCount");
const menuitem = _window.document.getElementById(
"menu_wordcount_betternotes"
@ -368,7 +368,7 @@ class ZoteroViews extends AddonBase {
public updateAutoInsertAnnotationsMenu() {
const _window = this._Addon.WorkspaceMenu.getWorkspaceMenuWindow();
Zotero.debug("updateAutoInsertAnnotationsMenu");
this._Addon.toolkit.Tool.log("updateAutoInsertAnnotationsMenu");
let autoAnnotation = Zotero.Prefs.get("Knowledge4Zotero.autoAnnotation");
if (typeof autoAnnotation === "undefined") {

View File

@ -1,16 +1,16 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES6",
},
"include": [
"src",
"typing",
"node_modules/zotero-types",
],
"exclude": [
"builds",
"addon"
]
}
"compilerOptions": {
"module": "CommonJS",
"target": "ES6",
"resolveJsonModule": true,
},
"include": [
"src",
"typing",
"node_modules/zotero-types",
],
"exclude": [
"builds",
"addon"
]
}