contentScript/index.js000644 0000011304 14660152351012212 0ustar00000000 000000 (()=>{"use strict";var t={400:function(t,e){var n=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(i,s){function l(t){try{c(o.next(t))}catch(t){s(t)}}function r(t){try{c(o.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(l,r)}c((o=o.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});e.default=function(t,e){function o(e,o){let i="New Note";o&&(i="New Task");return{text:e,hint:(i,s,l)=>n(this,void 0,void 0,(function*(){const n=l.from||s.from;n.ch-=3;const r=yield t.postMessage({command:"createNote",title:e,todo:o});i.replaceRange(`[${e}](:/${r.newNote.id})`,n,i.getCursor(),"complete")})),render:(t,n,o)=>{const s=t.ownerDocument.createElement("div");s.setAttribute("style","width: 100%; display:table;"),t.appendChild(s),s.innerHTML=`\n\t\t\t\t\t
${e}
\n\t\t\t\t\t
${i}
\n\t\t\t\t\t`}}}const i=e=>n(this,void 0,void 0,(function*(){const i=yield t.postMessage({command:"getNotes",prefix:e});let s=[];const l=i.notes;for(let e=0;en(this,void 0,void 0,(function*(){const n=l.from||s.from;if(n.ch-=3,e.replaceRange(`[${o.title}](:/${o.id})`,n,e.getCursor(),"complete"),i.selectText){const t=Object.assign({},n),i=Object.assign({},n);t.ch+=1,i.ch+=1+o.title.length,e.setSelection(t,i)}yield t.postMessage({command:"appendLink",targetNoteId:o.id})}))};if(i.showFolders){const t=o.folder?o.folder:"unknown";r.render=(e,n,i)=>{const s=e.ownerDocument.createElement("div");s.setAttribute("style","width: 100%; display:table;"),e.appendChild(s),s.innerHTML=`\n\t\t\t\t\t
${o.title}
\n\t\t\t\t\t
In ${t}
\n\t\t\t\t\t`}}else r.displayText=o.title;s.push(r)}return i.allowNewNotes&&e&&(s.push(o(e,!1)),s.push(o(e,!0))),s}));e.defineOption("bidirectionalLinks",!1,(function(t,o,s){o&&t.on("inputRead",(function(o,s){return n(this,void 0,void 0,(function*(){if(!o.state.completionActive&&t.getTokenAt(t.getCursor()).string.startsWith("|||")){const n={line:s.from.line,ch:s.from.ch+1},o=function(t,e){const o=t.getCursor();let l=t.getRange(n,o)||"";i(l).then((t=>{e({list:t,from:{line:s.from.line,ch:s.from.ch+1},to:{line:s.to.line,ch:s.to.ch+1}})}))};setTimeout((function(){e.showHint(t,o,{completeSingle:!1,closeOnUnfocus:!0,async:!0,closeCharacters:/[()\[\]{};:>,]/})}),10)}}))}))}))}},36:function(t,e,n){var o=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(i,s){function l(t){try{c(o.next(t))}catch(t){s(t)}}function r(t){try{c(o.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(l,r)}c((o=o.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){const{autocompletion:i,insertCompletionText:s}=n(808),{EditorSelection:l}=n(864),r=e=>o(this,void 0,void 0,(function*(){var n;const i=e.matchBefore(/[|][|][|][^()\[\]{};:>,\n]*/);if(!i||i.from===i.to&&!e.explicit)return null;const r=i.text.substring(3),c=yield t.postMessage({command:"getNotes",prefix:r}),a=(e,n,o=!1)=>(i,r,a,d)=>{const u=`[${e}](:/${n})`;if(i.dispatch(s(i.state,u,a,d)),c.selectText){const t=a+1,n=t+e.length;i.dispatch({selection:l.range(t,n)})}o&&t.postMessage({command:"appendLink",targetNoteId:n})},d=c.notes,u=[];for(const t of d)u.push({apply:a(t.title,t.id,!0),label:t.title,detail:c.showFolders?`In ${null!==(n=t.folder)&&void 0!==n?n:"unknown"}`:void 0});const p=e=>{const n=r,i=e?"New Task":"New Note";u.push({label:i,detail:`"${n}"`,apply:(i,s,l,r)=>o(this,void 0,void 0,(function*(){const o=yield t.postMessage({command:"createNote",title:n,todo:e});a(n,o.newNote.id)(i,s,l,r)}))})};return c.allowNewNotes&&r.length>0&&(p(!0),p(!1)),{from:i.from,options:u,filter:!1}}));let c;c=e.joplinExtensions?e.joplinExtensions.completionSource(r):i({override:[r]}),e.addExtension([c,i({tooltipClass:()=>"quick-links-completions"})])}},424:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0});const o=n(400),i=n(36);t.exports={default:function(t){return{plugin:e=>e.cm6?(0,i.default)(t,e):(0,o.default)(t,e),codeMirrorResources:["addon/hint/show-hint"],codeMirrorOptions:{bidirectionalLinks:!0},assets:function(){return[{name:"./show-hint.css"}]}}}}},808:t=>{t.exports=require("@codemirror/autocomplete")},864:t=>{t.exports=require("@codemirror/state")}},e={},n=function n(o){var i=e[o];if(void 0!==i)return i.exports;var s=e[o]={exports:{}};return t[o].call(s.exports,s,s.exports,n),s.exports}(424);exports.default=n.default})();contentScript/show-hint.css000644 0000001454 14660152350013203 0ustar00000000 000000 .CodeMirror-hints, .quick-links-completions.cm-tooltip { position: absolute; z-index: 10; overflow: hidden; list-style: none; margin: 0; padding: 2px; -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2); -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2); box-shadow: 2px 3px 5px rgba(0,0,0,.2); border-radius: 3px; border: 1px solid silver; background-color: white; font-size: 90%; font-family: monospace; max-height: 20em; overflow-y: auto; } .quick-links-completions.cm-tooltip li { font-family: sans-serif; } .CodeMirror-hint, .quick-links-completions li { margin: 0; padding: 0 4px; border-radius: 2px; white-space: pre; color: black; cursor: pointer; } li.CodeMirror-hint-active, .quick-links-completions li[aria-selected] { background: #08f; color: white; } index.js000644 0000012550 14660152350007356 0ustar00000000 000000 (()=>{"use strict";var t={632:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=joplin},808:(t,e)=>{var i,n,o,l,d,r;Object.defineProperty(e,"__esModule",{value:!0}),e.ContentScriptType=e.SettingItemType=e.ToolbarButtonLocation=e.isContextMenuItemLocation=e.MenuItemLocation=e.ImportModuleOutputFormat=e.FileSystemItem=void 0,(r=e.FileSystemItem||(e.FileSystemItem={})).File="file",r.Directory="directory",(d=e.ImportModuleOutputFormat||(e.ImportModuleOutputFormat={})).Markdown="md",d.Html="html",function(t){t.File="file",t.Edit="edit",t.View="view",t.Note="note",t.Tools="tools",t.Help="help",t.Context="context",t.NoteListContextMenu="noteListContextMenu",t.EditorContextMenu="editorContextMenu",t.FolderContextMenu="folderContextMenu",t.TagContextMenu="tagContextMenu"}(i=e.MenuItemLocation||(e.MenuItemLocation={})),e.isContextMenuItemLocation=function(t){return[i.Context,i.NoteListContextMenu,i.EditorContextMenu,i.FolderContextMenu,i.TagContextMenu].includes(t)},(l=e.ToolbarButtonLocation||(e.ToolbarButtonLocation={})).NoteToolbar="noteToolbar",l.EditorToolbar="editorToolbar",(o=e.SettingItemType||(e.SettingItemType={}))[o.Int=1]="Int",o[o.String=2]="String",o[o.Bool=3]="Bool",o[o.Array=4]="Array",o[o.Object=5]="Object",o[o.Button=6]="Button",(n=e.ContentScriptType||(e.ContentScriptType={})).MarkdownItPlugin="markdownItPlugin",n.CodeMirrorPlugin="codeMirrorPlugin"},740:function(t,e,i){var n=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(o,l){function d(t){try{u(n.next(t))}catch(t){l(t)}}function r(t){try{u(n.throw(t))}catch(t){l(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(d,r)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const o=i(632),l=i(808),d=6e4,r="showFolders",u="allowNewNotes",a="selectText",s="prependLink",c="targetLinkPrefix";let f=!1,y=!1,p=!1,g=!1,m="",v={};function x(){return n(this,void 0,void 0,(function*(){f=yield o.default.settings.value(r),f&&(yield T())}))}function b(){return n(this,void 0,void 0,(function*(){y=yield o.default.settings.value(u)}))}function h(){return n(this,void 0,void 0,(function*(){p=yield o.default.settings.value(a)}))}function M(){return n(this,void 0,void 0,(function*(){g=yield o.default.settings.value(s)}))}function S(){return n(this,void 0,void 0,(function*(){m=yield o.default.settings.value(c)}))}function T(){return n(this,void 0,void 0,(function*(){v=yield function(){return n(this,void 0,void 0,(function*(){let t={};const e={fields:["id","title"],page:1};let i=yield o.default.data.get(["folders"],e);for(i.items.forEach((e=>t[e.id]=e.title));i.has_more;)e.page+=1,i=yield o.default.data.get(["folders"],e),i.items.forEach((e=>t[e.id]=e.title));return t}))}(),setTimeout((()=>{f&&T()}),d)}))}function I(t){return n(this,void 0,void 0,(function*(){const e=yield o.default.workspace.selectedNote(),i=yield o.default.data.get(["notes",t],{fields:["id","body"]}),n=`${0===m.trim().length?"":m}[${e.title}](:/${e.id})`,l=g?n+"\n"+i.body:i.body+"\n"+n;yield o.default.data.put(["notes",t],null,{body:l})}))}o.default.plugins.register({onStart:function(){return n(this,void 0,void 0,(function*(){yield function(){return n(this,void 0,void 0,(function*(){const t="BidirectionalLinks";yield o.default.settings.registerSection(t,{description:"Bidirectional Links Plugin Settings",label:"Bidirectional Links",iconName:"fas fa-link"}),yield o.default.settings.registerSettings({[r]:{public:!0,section:t,type:l.SettingItemType.Bool,value:f,label:"Show Notebooks"},[u]:{public:!0,section:t,type:l.SettingItemType.Bool,value:y,label:"Allow new notes"},[a]:{public:!0,section:t,type:l.SettingItemType.Bool,value:p,label:"Select link text after inserting"},[s]:{public:!0,section:t,type:l.SettingItemType.Bool,value:g,label:"Prepend link instead of append"},[c]:{public:!0,section:t,type:l.SettingItemType.String,value:"",label:"Target Link Prefix"}}),yield x(),yield b(),yield b(),yield h(),yield M(),yield S(),yield o.default.settings.onChange((t=>{t.keys.indexOf(r)>=0&&x(),t.keys.indexOf(u)>=0&&b(),t.keys.indexOf(a)>=0&&h(),t.keys.indexOf(s)>=0&&M(),t.keys.indexOf(c)>=0&&S()}))}))}(),yield o.default.contentScripts.register(l.ContentScriptType.CodeMirrorPlugin,"bidirectionalLinks","./contentScript/index.js"),yield o.default.contentScripts.onMessage("bidirectionalLinks",(t=>n(this,void 0,void 0,(function*(){const e=(yield o.default.workspace.selectedNoteIds())[0];if("getNotes"===t.command){const i=t.prefix;let l=yield function(t){return n(this,void 0,void 0,(function*(){return""===t?(yield o.default.data.get(["notes"],{fields:["id","title","parent_id"],order_by:"updated_time",order_dir:"DESC",limit:21})).items:(yield o.default.data.get(["search"],{fields:["id","title","parent_id"],limit:21,query:`title:${t.trimRight()}*`})).items}))}(i);return{notes:l.filter((t=>t.id!==e)).map((t=>({id:t.id,title:t.title,folder:v[t.parent_id]}))),showFolders:f,allowNewNotes:y,selectText:p}}if("createNote"===t.command){const e=yield o.default.workspace.selectedNote(),i=yield o.default.data.get(["folders",e.parent_id]),n=yield o.default.data.post(["notes"],null,{is_todo:t.todo,title:t.title,parent_id:i.id});return yield I(n.id),{newNote:n}}if("appendLink"===t.command){const{targetNoteId:e}=t;yield I(e)}}))))}))}})}},e={};!function i(n){var o=e[n];if(void 0!==o)return o.exports;var l=e[n]={exports:{}};return t[n].call(l.exports,l,l.exports,i),l.exports}(740)})();manifest.json000644 0000000631 14660152350010407 0ustar00000000 000000 { "manifest_version": 1, "id": "joplin-plugin-bidirectional-links", "app_min_version": "1.8.1", "version": "0.2.0", "name": "Bidirectional Links", "description": "Create bidirectional to other notes", "author": "Ben Lau", "homepage_url": "https://github.com/benlau/joplin-plugin-bidirectional-links", "repository_url": "https://github.com/benlau/joplin-plugin-bidirectional-links", "keywords": [] }