add: standalone workspace

This commit is contained in:
windingwind 2023-05-04 23:55:30 +08:00
parent 7dd8d7bd96
commit 2264c8592b
6 changed files with 113 additions and 5 deletions

View File

@ -0,0 +1,63 @@
<?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-react-client.css" type="text/css"?>
<!DOCTYPE html>
<html
lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
windowtype="__addonRef__-syncManager"
sizemode="normal"
scrolling="false"
persist="screenX screenY width height sizemode"
>
<head>
<title locale-target="innerHTML">workspaceWindow.name</title>
<meta charset="utf-8" />
<script>
document.addEventListener("DOMContentLoaded", (ev) => {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
Services.scriptloader.loadSubScript(
"chrome://zotero/content/include.js",
this
);
Services.scriptloader.loadSubScript(
"resource://zotero/require.js",
this
);
window.arguments[0]._initPromise.resolve();
});
</script>
<style>
html,
body {
padding: 0;
margin: 0;
height: 100%;
overflow-x: hidden;
overflow-y: auto;
word-wrap: break-word;
background-color: #f0f0f0;
font-family: initial;
}
#workspace-container {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="workspace-container">
</div>
</body>
</html>

View File

@ -21,6 +21,8 @@ templateEditor.help=Help
tab.name=Note Workspace
workspaceWindow.name=Note Workspace
export.title=Export Notes
export.options.linkMode=Linked Notes Mode
export.options.MD=MarkDown(.md)

View File

@ -21,6 +21,8 @@ templateEditor.help=帮助
tab.name=笔记工作区
workspaceWindow.name=笔记工作区
export.title=导出笔记
export.options.linkMode=链接笔记模式
export.options.MD=MarkDown(.md)

View File

@ -55,7 +55,7 @@ export function initWorkspace(container: XUL.Box | undefined) {
{
tag: "hbox",
id: makeId("top-container"),
styles: { width: "100%" },
styles: { width: "100%", height: "100%" },
properties: {},
attributes: {
flex: "1",

View File

@ -286,6 +286,19 @@ export async function activateWorkspaceTab() {
});
tabElem.addEventListener("mousedown", () => hoverWorkspaceTab(true));
tabElem.addEventListener("mouseleave", () => hoverWorkspaceTab(false));
tabElem.addEventListener("mousedown", async (ev) => {
if (ev.button !== 2) {
return;
}
await Zotero.Promise.delay(300);
const menu = document
.querySelector("#zotero-itemmenu")
?.parentElement?.lastElementChild?.querySelector("menu")
?.querySelector("menupopup")?.lastElementChild;
menu?.addEventListener("click", () => {
addon.hooks.onOpenWorkspace("window");
});
});
// load workspace content
addon.hooks.onInitWorkspace(addon.data.workspace.tab.container);
registerWorkspaceTabPaneObserver();

View File

@ -1,5 +1,33 @@
export function showWorkspaceWindow() {
// TODO
// const win;
// win.addEventListener("message", (e) => messageHandler(e), false);
import { config } from "../../../package.json";
import { isWindowAlive, localeWindow } from "../../utils/window";
import { messageHandler } from "./message";
export async function showWorkspaceWindow() {
if (isWindowAlive(addon.data.workspace.window.window)) {
addon.data.workspace.window.window?.focus();
return;
}
const windowArgs = {
_initPromise: Zotero.Promise.defer(),
};
const win = window.openDialog(
`chrome://${config.addonRef}/content/workspaceWindow.xhtml`,
`${config.addonRef}-workspaceWindow`,
`chrome,centerscreen,resizable,status,width=800,height=400,dialog=no`,
windowArgs
)!;
await windowArgs._initPromise.promise;
localeWindow(win);
addon.data.workspace.window.active = true;
addon.data.workspace.window.window = win;
addon.data.workspace.window.container = win.document.querySelector(
"#workspace-container"
) as XUL.Box;
addon.hooks.onInitWorkspace(addon.data.workspace.window.container);
win.addEventListener("message", messageHandler, false);
win.addEventListener("unload", function onWindowUnload(ev) {
addon.data.workspace.window.active = false;
this.window.removeEventListener("unload", onWindowUnload, false);
this.window.removeEventListener("message", messageHandler, false);
});
}