fix: mind map stability

This commit is contained in:
xiangyu 2022-05-07 00:09:34 +08:00
parent ac54bc23ae
commit cd71f664ea
4 changed files with 38 additions and 18 deletions

View File

@ -141,9 +141,8 @@
}); });
// read in the predefined graph using the JSON format data held in the "mySavedModel" textarea // read in the predefined graph using the JSON format data held in the "mySavedModel" textarea
// getData();
window.parent.postMessage({type: "ready"}, "*"); window.parent.postMessage({type: "ready"}, "*");
getData()
} }
function spotConverter(dir, from) { function spotConverter(dir, from) {
@ -279,8 +278,29 @@
} }
} }
window.addEventListener("DOMContentLoaded", init); window.addEventListener("DOMContentLoaded", ()=>{
window.addEventListener('resize', (e)=>{myDiagram.diagram.layoutDiagram(true)}) try{
init()
}catch(e){
window.parent.postMessage({type: "error", event: e}, "*");
}
});
var resizeTime = new Date().getTime()
window.addEventListener('resize', (e)=>{
const canvas = document.getElementsByTagName("canvas")[0]
const div = document.getElementById('myDiagramDiv')
canvas.setAttribute('height', div.getAttribute('height'))
canvas.setAttribute('width', div.getAttribute('width'))
const currentResize = new Date().getTime()
resizeTime = currentResize
// Delay update
setTimeout(()=>{
if(resizeTime === currentResize){
getData()
}
}, 500)
})
</script> </script>
@ -299,8 +319,6 @@
<canvas <canvas
tabindex="0" tabindex="0"
style=" style="
width: 100%;
height: 100%;
position: absolute; position: absolute;
top: 0px; top: 0px;
left: 0px; left: 0px;

View File

@ -48,7 +48,7 @@
</div> </div>
</html:div> </html:div>
<html:div id="mindmap-container"> <html:div id="mindmap-container">
<iframe src="chrome://Knowledge4Zotero/content/mindMap.html" id="mindmapIframe"></iframe> <!-- Inser Here -->
</html:div> </html:div>
<html:div id="outline-tools" height="50" maxheight="50" minheight="50" style="display: flex; flex-flex-direction: row; justify-content: space-between; margin: 0px 30px 0px 30px;"> <html:div id="outline-tools" height="50" maxheight="50" minheight="50" style="display: flex; flex-flex-direction: row; justify-content: space-between; margin: 0px 30px 0px 30px;">
<div class="tooltip"> <div class="tooltip">

View File

@ -29,6 +29,7 @@ class Knowledge extends AddonBase {
if (this.getWorkspaceWindow()) { if (this.getWorkspaceWindow()) {
(this.getWorkspaceWindow() as Window).focus(); (this.getWorkspaceWindow() as Window).focus();
} else { } else {
this._Addon.views._initIframe = Zotero.Promise.defer();
let win = window.open( let win = window.open(
"chrome://Knowledge4Zotero/content/workspace.xul", "chrome://Knowledge4Zotero/content/workspace.xul",
"_blank", "_blank",

View File

@ -5,7 +5,7 @@ class AddonViews extends AddonBase {
editorIcon: object; editorIcon: object;
$: any; $: any;
outlineView: boolean; outlineView: boolean;
_initIframe: typeof Promise; _initIframe: any;
constructor(parent: Knowledge4Zotero) { constructor(parent: Knowledge4Zotero) {
super(parent); super(parent);
@ -366,15 +366,7 @@ class AddonViews extends AddonBase {
if (e.data.type === "ready") { if (e.data.type === "ready") {
this._initIframe.resolve(); this._initIframe.resolve();
} else if (e.data.type === "getMindMapData") { } else if (e.data.type === "getMindMapData") {
( this.updateMindMap();
_window.document.getElementById("mindmapIframe") as HTMLIFrameElement
).contentWindow.postMessage(
{
type: "setMindMapData",
nodes: this._Addon.knowledge.getNoteTreeAsList(),
},
"*"
);
} else if (e.data.type === "jumpNode") { } else if (e.data.type === "jumpNode") {
this.scrollToLine( this.scrollToLine(
await this._Addon.knowledge.getWorkspaceEditorInstance(), await this._Addon.knowledge.getWorkspaceEditorInstance(),
@ -399,18 +391,27 @@ class AddonViews extends AddonBase {
const outline = _window.document.getElementById("outline-container"); const outline = _window.document.getElementById("outline-container");
this.outlineView = status; this.outlineView = status;
if (this.outlineView) { if (this.outlineView) {
_window.document.getElementById("mindmapIframe").remove();
mindmap.setAttribute("hidden", "hidden"); mindmap.setAttribute("hidden", "hidden");
outline.removeAttribute("hidden"); outline.removeAttribute("hidden");
} else { } else {
const iframe = _window.document.createElement("iframe");
iframe.setAttribute("id", "mindmapIframe");
iframe.setAttribute(
"src",
"chrome://Knowledge4Zotero/content/mindMap.html"
);
outline.setAttribute("hidden", "hidden"); outline.setAttribute("hidden", "hidden");
mindmap.removeAttribute("hidden"); mindmap.removeAttribute("hidden");
mindmap.append(iframe);
this.setTreeViewSize();
} }
this.buildOutline(this._Addon.knowledge.getWorkspaceNote()); this.buildOutline(this._Addon.knowledge.getWorkspaceNote());
} }
async updateMindMap() { async updateMindMap() {
Zotero.debug("Knowledge4Zotero: updateMindMap"); Zotero.debug("Knowledge4Zotero: updateMindMap");
await this._initIframe; // await this._initIframe.promise;
const _window = this._Addon.knowledge.getWorkspaceWindow(); const _window = this._Addon.knowledge.getWorkspaceWindow();
const iframe = _window.document.getElementById( const iframe = _window.document.getElementById(
"mindmapIframe" "mindmapIframe"