-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make tests pass
- Loading branch information
Showing
18 changed files
with
7,085 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
|
||
pkgs.mkShell { | ||
|
||
buildInputs = [ | ||
pkgs.nodejs | ||
pkgs.pnpm | ||
]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { isFullPage } from '@notionhq/client'; | ||
|
||
import { getGlobalNotero, getXULElementById } from '../utils'; | ||
import { setMenuItems } from '../utils/elements'; | ||
|
||
import { getNoteroPref, NoteroPref } from './notero-pref'; | ||
|
||
type DialogArguments = { | ||
accepted: boolean; | ||
associatedLink: string; | ||
syncEnabled: boolean; | ||
}; | ||
|
||
class Dialog { | ||
private collectionDialogContainer!: XUL.XULElement; | ||
private associatedLinkElement!: XUL.MenuListElement; | ||
private syncEnabledElement!: XUL.CheckboxElement; | ||
private params!: DialogArguments; | ||
|
||
public async init(): Promise<void> { | ||
await Zotero.uiReadyPromise; | ||
|
||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
this.params = window.arguments![0]! as DialogArguments; | ||
|
||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
this.collectionDialogContainer = getXULElementById( | ||
'notero-collection-dialog', | ||
)!; | ||
this.associatedLinkElement = getXULElementById('notero-associatedLink')!; | ||
|
||
const notero = getGlobalNotero(); | ||
const pref = getNoteroPref(NoteroPref.linkedCollectionID); | ||
if (pref) { | ||
const client = await notero.getNotionClient(); | ||
const res = await client.databases.query({ database_id: pref }); | ||
const results = res.results | ||
.map((result: (typeof res.results)[0]) => { | ||
if (isFullPage(result)) { | ||
return { | ||
value: result.id, | ||
label: Object.values(result.properties).find( | ||
(prop) => prop.type === 'title', | ||
)?.title[0]!.plain_text, | ||
}; | ||
} | ||
}) | ||
.filter((item) => item != undefined); | ||
setMenuItems(this.associatedLinkElement, results); | ||
} | ||
|
||
this.associatedLinkElement.value = this.params.associatedLink; | ||
this.syncEnabledElement = getXULElementById('notero-syncEnabled')!; | ||
this.syncEnabledElement.checked = this.params.syncEnabled; | ||
document.addEventListener('dialogaccept', () => { | ||
return this.accept(); | ||
}); | ||
} | ||
accept(): boolean { | ||
// @ts-expect-error dataOut is not defined in the type | ||
window.arguments![0]!.dataOut = { | ||
associatedLink: this.associatedLinkElement.value, | ||
syncEnabled: this.syncEnabledElement.checked, | ||
accepted: true, | ||
}; | ||
return true; | ||
} | ||
} | ||
|
||
module.exports = { | ||
dialog: new Dialog(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0"?> | ||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <?xml-stylesheet | ||
href="chrome://zotero/skin/zotero.css" type="text/css"?> <?xml-stylesheet | ||
href="chrome://zotero-platform/content/zotero.css" type="text/css"?> | ||
|
||
<window | ||
type="child" | ||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" | ||
xmlns:html="http://www.w3.org/1999/xhtml" | ||
style="width: 100px; height: 100px" | ||
buttons="cancel,accept" | ||
onload="notero.dialog.init();" | ||
> | ||
<script> | ||
Services.scriptloader.loadSubScript( | ||
'chrome://zotero/content/customElements.js', | ||
this, | ||
); | ||
|
||
Services.scriptloader.loadSubScript( | ||
'chrome://notero/content/prefs/dialog.js', | ||
this, | ||
); | ||
</script> | ||
<dialog | ||
id="notero-collection-dialog" | ||
title="Collection Properties" | ||
onload="notero.dialog.init();" | ||
> | ||
<div> | ||
<label>Collection Settings</label> | ||
<grid> | ||
<rows> | ||
<row> | ||
<label value="Associated Link:" /> | ||
<menulist id="notero-associatedLink"> | ||
<menupopup /> | ||
</menulist> | ||
</row> | ||
<row> | ||
<label value="Sync Enabled:" /> | ||
<checkbox id="notero-syncEnabled" /> | ||
</row> | ||
</rows> | ||
</grid> | ||
</div> | ||
</dialog> | ||
</window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.