Skip to content

Commit

Permalink
Release 0.5.0 🚀 (#25)
Browse files Browse the repository at this point in the history
* style: Prettify src

* 0.5.0

* chore: bump version in manifest.json
  • Loading branch information
xUser5000 authored Aug 2, 2021
1 parent e5a5507 commit 9453560
Show file tree
Hide file tree
Showing 26 changed files with 5,113 additions and 166 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "joplin-plugin-bibtex",
"version": "0.4.0",
"version": "0.5.0",
"scripts": {
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
"prepare": "npm run dist",
Expand Down
21 changes: 8 additions & 13 deletions src/add-bibtex-reference.command.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import joplin from "api";
import { showCitationPopup } from './ui/citation-popup';
import { showCitationPopup } from "./ui/citation-popup";
import { Reference } from "./model/reference.model";
import { formatReference } from "./util/format-ref.util";
import { DataStore } from "./data/data-store";
import { getBibTeXData } from "./getBibTeXData";
import {
ADD_BIBTEX_REFERENCE_COMMAND,
PLUGIN_ICON,
} from "./constants";
import { ADD_BIBTEX_REFERENCE_COMMAND, PLUGIN_ICON } from "./constants";
const fs = joplin.require("fs-extra");

/**
* Register the main command of the plugin
*/
export async function registerAddBibTexReferenceCommand () {
export async function registerAddBibTexReferenceCommand() {
await joplin.commands.register({
name: ADD_BIBTEX_REFERENCE_COMMAND,
label: 'Add BibTeX Reference',
label: "Add BibTeX Reference",
iconName: PLUGIN_ICON,
execute: async () => {

// Get refs
let refs: Reference[] = [];
try {
Expand All @@ -37,15 +33,14 @@ export async function registerAddBibTexReferenceCommand () {

// Insert the selected references into the note content
const toBeInsertedText = selectedRefsIDs
.map(refId => DataStore.getReferenceById(refId))
.map(ref => formatReference(ref))
.map((refId) => DataStore.getReferenceById(refId))
.map((ref) => formatReference(ref))
.reduce((acc, curr) => acc + " " + curr);

await joplin.commands.execute("insertText", toBeInsertedText);

// Return the focus to the note editor
await joplin.commands.execute("focusElement", "noteBody");

}
},
});
}
16 changes: 6 additions & 10 deletions src/data/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Reference } from "../model/reference.model";
* This class is responsible for storing citation data and providing it when requested
*/
export class DataStore {

/**
* Array containing reference objects
*/
Expand All @@ -13,26 +12,26 @@ export class DataStore {
/**
* Private constructor to prevent the instantiation of this class
*/
private constructor () { }
private constructor() {}

/**
* Sets the data to be stored in the references array
*/
public static setReferences (refs: Reference[]): void {
public static setReferences(refs: Reference[]): void {
this.references = refs;
}

/**
* Returns all the stored references
*/
public static getAllReferences (): Reference[] {
public static getAllReferences(): Reference[] {
return this.references;
}

/**
* Gets a single reference using its id
*/
public static getReferenceById (id: string): Reference {
public static getReferenceById(id: string): Reference {
const n = this.references.length;
for (let i = 0; i < n; i++) {
if (this.references[i].id === id) return this.references[i];
Expand All @@ -46,10 +45,7 @@ export class DataStore {
* Compatible means that the search query is an exact substring of the "title" field, which will be improved later
* @param query Search Query
*/
public static search (query: string): Reference[] {
return (
this.references.
filter(ref => ref.title.includes(query))
);
public static search(query: string): Reference[] {
return this.references.filter((ref) => ref.title.includes(query));
}
}
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import joplin from 'api';
import { init } from './init';
import joplin from "api";
import { init } from "./init";

joplin.plugins.register({
onStart: async function() {
console.info('BibTeX plugin started!');
onStart: async function () {
console.info("BibTeX plugin started!");

init();
}
init();
},
});
20 changes: 10 additions & 10 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"manifest_version": 1,
"id": "com.xUser5000.bibtex",
"app_min_version": "1.7",
"version": "0.4.0",
"name": "BibTeX",
"description": "Use locally stored BibTeX files to integrate citation into Joplin",
"author": "Abdallah Ahmed",
"homepage_url": "",
"repository_url": "https://github.com/joplin/plugin-bibtex",
"keywords": []
"manifest_version": 1,
"id": "com.xUser5000.bibtex",
"app_min_version": "1.7",
"version": "0.5.0",
"name": "BibTeX",
"description": "Use locally stored BibTeX files to integrate citation into Joplin",
"author": "Abdallah Ahmed",
"homepage_url": "",
"repository_url": "https://github.com/joplin/plugin-bibtex",
"keywords": []
}
6 changes: 3 additions & 3 deletions src/model/author.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Author {
given: string,
family: string
}
given: string;
family: string;
}
26 changes: 13 additions & 13 deletions src/model/reference.model.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Author } from "./author.model";

export interface Reference {
id: string,
title: string,
author?: Author[],
type: string,
DOI?: string,
URL?: string,
publisher?: string,
"publisher-place"?: string,
edition?: string,
volume?: string,
issue?: string,
page?: string,
issued?: { "date-parts": number[][] },
id: string;
title: string;
author?: Author[];
type: string;
DOI?: string;
URL?: string;
publisher?: string;
"publisher-place"?: string;
edition?: string;
volume?: string;
issue?: string;
page?: string;
issued?: { "date-parts": number[][] };
}
46 changes: 31 additions & 15 deletions src/ui/citation-popup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,70 @@ let popupHandle: string = "";
* to be inserted in the note content
* @returns ID of the selected reference
*/
export async function showCitationPopup (refs: Reference[]): Promise<string[]> {

export async function showCitationPopup(refs: Reference[]): Promise<string[]> {
// If the dialog was not initialized, create it and get its handle
if (popupHandle === "") {
popupHandle = await joplin.views.dialogs.create(CITATION_POPUP_ID);
}

await loadAssets(refs);
const result = await joplin.views.dialogs.open(popupHandle);

if (result.id === "cancel") return [];

let selectedRefsIDs: string[] = JSON.parse(result.formData["main"]["output"]);
let selectedRefsIDs: string[] = JSON.parse(
result.formData["main"]["output"]
);

/* Return an array of selected references' IDS */
return selectedRefsIDs;
}

async function loadAssets (refs: Reference[]): Promise<void> {
async function loadAssets(refs: Reference[]): Promise<void> {
const installationDir = await joplin.plugins.installationDir();
let html: string = await fs.readFile(
installationDir + "/ui/citation-popup/view.html",
'utf8'
"utf8"
);
html = html.replace("<!-- content -->", fromRefsToHTML(refs));

await joplin.views.dialogs.setHtml(popupHandle, html);
await joplin.views.dialogs.addScript(popupHandle, "./ui/citation-popup/lib/autoComplete.min.css");
await joplin.views.dialogs.addScript(popupHandle, "./ui/citation-popup/lib/autoComplete.min.js");
await joplin.views.dialogs.addScript(popupHandle, "./ui/citation-popup/lib/he.min.js");
await joplin.views.dialogs.addScript(popupHandle, "./ui/citation-popup/view.css");
await joplin.views.dialogs.addScript(popupHandle, "./ui/citation-popup/view.js");
await joplin.views.dialogs.addScript(
popupHandle,
"./ui/citation-popup/lib/autoComplete.min.css"
);
await joplin.views.dialogs.addScript(
popupHandle,
"./ui/citation-popup/lib/autoComplete.min.js"
);
await joplin.views.dialogs.addScript(
popupHandle,
"./ui/citation-popup/lib/he.min.js"
);
await joplin.views.dialogs.addScript(
popupHandle,
"./ui/citation-popup/view.css"
);
await joplin.views.dialogs.addScript(
popupHandle,
"./ui/citation-popup/view.js"
);
}

function fromRefsToHTML (refs: Reference[]): string {
function fromRefsToHTML(refs: Reference[]): string {
const JSONString = JSON.stringify(
refs.map(ref => {
refs.map((ref) => {
return {
id: ref.id,
title: ref.title,
author: ref.author,
year: getDateYear(ref)
year: getDateYear(ref),
};
})
);
const ans: string = `
<div id="json" style="display:none;">
${ encode(JSONString) }
${encode(JSONString)}
</div>
`;
return ans;
Expand Down
75 changes: 73 additions & 2 deletions src/ui/citation-popup/lib/autoComplete.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9453560

Please sign in to comment.