felixhayashi / TW5-TiddlyMap

Map drawing and topic visualization for your wiki
http://tiddlymap.org
BSD 2-Clause "Simplified" License
845 stars 127 forks source link

Error when using MapWidget and TiddlyRemember plugin #387

Closed scarbajali closed 6 months ago

scarbajali commented 3 years ago

Hi,

I have a tiddler that uses the MapWidget as following:

<$tmap view="Knowledge Management System" ></$tmap>

It works just fine, but after installing the TiddlyRemember plugin (https://sobjornstad.github.io/TiddlyRemember) and trying to synchronize with Anki, I have the error message below.

When I remove the widget line from the tiddler and try to synchronize again, TiddlyRemember works fine. It seems an issue caused by a missing definition in $tm variable in MapWidget.js file.

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-on support site.
Debug info:
Anki 2.1.38 (355e4cd5) Python 3.8.1 Qt 5.15.1 PyQt 5.15.1
Platform: Linux
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2021-01-23 02:10:53
Add-ons possibly involved: ⁨TiddlyRemember⁩

Caught exception:
Traceback (most recent call last):
  File "/home/scarbajali/.local/share/Anki2/addons21/60456529/twimport.py", line 61, in _invoke_tw_command
    proc = subprocess.run(cmd, cwd=wiki_path, stdout=subprocess.PIPE,
  File "subprocess.py", line 512, in run
subprocess.CalledProcessError: Command '['/usr/local/bin/tiddlywiki', '--output', '/tmp/tmp73o09ld8/render', '--render', '[type[text/vnd.tiddlywiki]] [type[]] +[!is[system]]', '[encodeuricomponent[]addsuffix[.html]]', 'text/html', '$:/plugins/sobjornstad/TiddlyRemember/templates/TiddlyRememberParseable']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/scarbajali/.local/share/Anki2/addons21/60456529/__init__.py", line 187, in join_thread
    if self.handle_thread_exception():
  File "/home/scarbajali/.local/share/Anki2/addons21/60456529/__init__.py", line 175, in handle_thread_exception
    raise exc
  File "/home/scarbajali/.local/share/Anki2/addons21/60456529/__init__.py", line 62, in run
    self.notes = twimport.find_notes(
  File "/home/scarbajali/.local/share/Anki2/addons21/60456529/twimport.py", line 201, in find_notes
    _render_wiki(tw_binary, wiki_folder, render_location, filter_)
  File "/home/scarbajali/.local/share/Anki2/addons21/60456529/twimport.py", line 158, in _render_wiki
    _invoke_tw_command(cmd, wiki_path, "render wiki")
  File "/home/scarbajali/.local/share/Anki2/addons21/60456529/twimport.py", line 72, in _invoke_tw_command
    raise RenderingError(
60456529.oops.RenderingError: Failed to render wiki: return code 1.
$ /usr/local/bin/tiddlywiki --output /tmp/tmp73o09ld8/render --render [type[text/vnd.tiddlywiki]] [type[]] +[!is[system]] [encodeuricomponent[]addsuffix[.html]] text/html $:/plugins/sobjornstad/TiddlyRemember/templates/TiddlyRememberParseable

LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': Unrecognized Unicode character "−" (8722) [unknownSymbol]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \\ or \newline does nothing in display mode [newLineInDisplayMode]
$:/plugins/felixhayashi/tiddlymap/js/widget/MapWidget:11
/* @preserve TW-Guard */var MapWidget=function(e){_inherits(t,e);function t(e,i){_classCallCheck(this,t);var a=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,i));a.getAttr=a.getAttribute;a.isDebug=_utils2.default.isTrue($tm.config.sys.debug,false);_utils2.default.bindTo(a,["constructTooltip","handleResizeEvent","handleClickEvent","handleCanvasKeyup","handleCanvasKeydown","handleCanvasScroll","handleCanvasMouseMove","handleWidgetKeyup","handleWidgetKeydown","handleTriggeredRefresh","handleContextMenu"]);a.callbackManager=new _CallbackManager2.default;a.computeAttributes();a.editorMode=a.getAttr("editor");a.clickToUse=_utils2.default.isTrue(a.getAttr("click-to-use"),false);a.id=a.getAttr("object-id")||a.getStateQualifier();a.widgetPopupsPath=$tm.path.tempPopups+"/"+a.id;if(a.editorMode){_utils2.default.addTWlisteners({"tmap:tm-create-view":a.handleCreateView,"tmap:tm-rename-view":a.handleRenameView,"tmap:tm-delete-view":a.handleDeleteView,"tmap:tm-delete-element":a.handleDeleteElement,"tmap:tm-edit-view":a.handleEditView,"tmap:tm-generate-widget":a.handleGenerateWidget,"tmap:tm-toggle-central-topic":a.handleSetCentralTopic,"tmap:tm-save-canvas":a.handleSaveCanvas},a,a)}_utils2.default.addTWlisteners({"tmap:tm-focus-node":a.handleFocusNode,"tmap:tm-reset-focus":a.repaintGraph,"tmap:tm-neighbourhood-reset-trace":function e(){a.initAndRenderGraph(a.graphDomNode)}},a,a);a.visListeners={click:a.handleVisSingleClickEvent,doubleClick:a.handleVisDoubleClickEvent,stabilized:a.handleVisStabilizedEvent,selectNode:a.handleVisSelectNode,deselectNode:a.handleVisDeselectNode,dragStart:a.handleVisDragStart,dragEnd:a.handleVisDragEnd,hoverNode:a.handleVisHoverElement,hoverEdge:a.handleVisHoverElement,blurNode:a.handleVisBlurElement,blurEdge:a.handleVisBlurElement,beforeDrawing:a.handleVisBeforeDrawing,afterDrawing:a.handleVisAfterDrawing,stabilizationProgress:a.handleVisLoading,stabilizationIterationsDone:a.handleVisLoadingDone};a.windowDomListeners={resize:[a.handleResizeEvent,false],click:[a.handleClickEvent,false],mousemove:[a.handleCanvasMouseMove,true]};a.canvasDomListeners={keyup:[a.handleCanvasKeyup,true],keydown:[a.handleCanvasKeydown,true],mousewheel:[a.handleCanvasScroll,true],DOMMouseScroll:[a.handleCanvasScroll,true],contextmenu:[a.handleContextMenu,true],MozMousePixelScroll:[a.handleExtraCanvasScroll,true]};a.widgetDomListeners={keyup:[a.handleWidgetKeyup,true],keydown:[a.handleWidgetKeydown,true]};a.conVector={from:null,to:null};return a}_createClass(t,[{key:"handleConnectionEvent",value:function e(t,i){var a=this;var s=this.view.getEdgeTypeFilter();var r={fromLabel:$tm.adapter.selectNodeById(t.from).label,toLabel:$tm.adapter.selectNodeById(t.to).label,view:this.view.getLabel(),eTyFilter:s.raw};$tm.dialogManager.open("getEdgeType",r,function(e,r){if(e){var n=_utils2.default.getText(r);var o=_EdgeType2.default.getInstance(n);if(!o.namespace){var l=_EdgeType2.default.getIdParts(o.id),d=l.marker,h=l.name;var u=a.view.getConfig("edge_type_namespace");o=_EdgeType2.default.getInstance(_EdgeType2.default.getId(d,u,h))}if(!o.exists()){o.save()}t.type=o.id;$tm.adapter.insertEdge(t);a.isPreventZoomOnNextUpdate=true;if(!a.view.isEdgeTypeVisible(o)){$tm.dialogManager.open("edgeNotVisible",{type:o.id,view:a.view.getLabel(),eTyFilter:s.pretty})}}if(typeof i==="function"){i(e)}})}},{key:"checkForFreshInstall",value:function e(){if(!_utils2.default.getEntry($tm.ref.sysMeta,"showWelcomeMessage",true)){return}_utils2.default.setEntry($tm.ref.sysMeta,"showWelcomeMessage",false);var t={dialog:{preselects:{"config.storyview":"true","config.navigation":"true","config.sidebar":"true","config.demo":"true"}}};$tm.dialogManager.open("welcome",t,function(e,t){var i=_utils2.default.getPropertiesByPrefix(t.fields,"config.",true);if(i["storyview"]&&_utils2.default.tiddlerExists("$:/plugins/felixhayashi/topstoryview")){_utils2.default.setText("$:/view","top")}if(i["navigation"]){_utils2.default.setText("$:/config/Navigation/openLinkFromInsideRiver","above");_utils2.default.setText("$:/config/Navigation/openLinkFromOutsideRiver","top")}if(i["sidebar"]){_utils2.default.setText("$:/themes/tiddlywiki/vanilla/options/sidebarlayout","fixed-fluid")}if(i["demo"]){var a=$tm.misc.defaultViewLabel;var s=$tm.adapter.insertNode({label:"Have fun with",x:0,y:0},a);var r=$tm.adapter.insertNode({label:"TiddlyMap!!",x:100,y:100},a);$tm.adapter.insertEdge({from:s.id,to:r.id})}if(Object.keys(i).length){_utils2.default.touch("$:/plugins/felixhayashi/tiddlymap")}})}},{key:"openStandardConfirmDialog",value:function e(t,i){var a={message:i};$tm.dialogManager.open("getConfirmation",a,t)}},{key:"logger",value:function e(t,i){if(this.isDebug){var a=Array.prototype.slice.call(arguments,1);a.unshift("@"+this.id);a.unshift(t);$tm.logger.apply(this,a)}}},{key:"render",value:function e(t,i){this.parentDomNode=t;this.domNode=this.document.createElement("div");t.insertBefore(this.domNode,i);this.registerClassNames(this.domNode);this.viewHolderRef=this.getViewHolderRef();this.view=this.getView();this.graphBarDomNode=this.document.createElement("div");$tw.utils.addClass(this.graphBarDomNode,"tmap-topbar");this.domNode.appendChild(this.graphBarDomNode);this.graphDomNode=this.document.createElement("div");this.domNode.appendChild(this.graphDomNode);$tw.utils.addClass(this.graphDomNode,"tmap-vis-graph");if(_utils2.default.isPreviewed(this)){$tw.utils.addClass(this.domNode,"tmap-static-mode");this.renderPreview(this.graphBarDomNode,this.graphDomNode)}else{this.renderFullWidget(this.domNode,this.graphBarDomNode,this.graphDomNode);var a=this.document.createElement("canvas");$tw.utils.addClass(a,"tmap-download-canvas");this.domNode.appendChild(a)}}},{key:"renderPreview",value:function e(t,i){var a=this.view.snapshotTRef;var s=_utils2.default.getTiddler(a);var r=this.document.createElement("span");r.innerHTML=this.view.getLabel();r.className="tmap-view-label";t.appendChild(r);if(s){var n=_utils2.default.getTiddlerNode(this.view.getRoot());n.children.push(_utils2.default.getTranscludeNode(a));this.makeChildWidgets([n]);this.renderChildren(i,i.firstChild)}else{$tw.utils.addClass(i,"tmap-graph-placeholder")}}},{key:"renderFullWidget",value:function e(t,i,a){_utils2.default.setDomListeners("add",window,this.windowDomListeners);_utils2.default.setDomListeners("add",t,this.widgetDomListeners);this.addLoadingBar(this.domNode);this.tooltip=new _Popup2.default(this.domNode,{className:"tmap-tooltip",showDelay:$tm.config.sys.popups.delay});this.contextMenu=new _Popup2.default(this.domNode,{className:"tmap-context-menu",showDelay:0,hideOnClick:true,leavingDelay:999999});this.sidebar=_utils2.default.getFirstElementByClassName("tc-sidebar-scrollable");this.isInSidebar=this.sidebar&&!this.domNode.isTiddlyWikiFakeDom&&this.sidebar.contains(this.domNode);this.rebuildEditorBar(i);this.reloadRefreshTriggers();this.initAndRenderGraph(a);$tm.registry.push(this);this.checkForFreshInstall();if(this.id===$tm.misc.mainEditorId){var s=$tm.url;if(s&&s.query["tmap-enlarged"]){this.toggleEnlargedMode(s.query["tmap-enlarged"]);this.setView(s.query["tmap-view"])}}}},{key:"registerClassNames",value:function e(t){var i=$tw.utils.addClass;i(t,"tmap-widget");if(this.clickToUse){i(t,"tmap-click-to-use")}if(this.getAttr("editor")==="advanced"){i(t,"tmap-advanced-editor")}if(this.getAttr("design")==="plain"){i(t,"tmap-plain-design")}if(!_utils2.default.isTrue(this.getAttr("show-buttons"),true)){i(t,"tmap-no-buttons")}if(this.getAttr("class")){i(t,this.getAttr("class"))}}},{key:"addLoadingBar",value:function e(t){this.graphLoadingBarDomNode=this.document.createElement("progress");$tw.utils.addClass(this.graphLoadingBarDomNode,"tmap-loading-bar");t.appendChild(this.graphLoadingBarDomNode)}},{key:"rebuildEditorBar",value:function e(){this.removeChildDomNodes();var t=this.view;var i="tmap-unicode-button";var a=i+" tmap-active-button";var s={widgetQualifier:this.getStateQualifier(),widgetTempPath:this.widgetTempPath,widgetPopupsPath:this.widgetPopupsPath,isViewBound:String(this.isViewBound()),viewRoot:t.getRoot(),viewLabel:t.getLabel(),viewHolder:this.getViewHolderRef(),edgeTypeFilter:t.edgeTypeFilterTRef,allEdgesFilter:$tm.selector.allEdgeTypes,isShowNeighbourhood:String(t.isEnabled("neighbourhood_scope")),tracingBtnClass:t.isEnabled("neighbourhood_trace_clicks")?a:i,neighScopeBtnClass:t.isEnabled("neighbourhood_scope")?a:i,rasterMenuBtnClass:t.isEnabled("raster")?a:i};for(var r in s){this.setVariable(r,s[r])}var n=_utils2.default.getTiddlerNode(t.getRoot());if(this.editorMode==="advanced"){n.children.push(_utils2.default.getTranscludeNode($tm.ref.graphBar))}else{var o=_utils2.default.getElementNode("span","tmap-view-label",t.getLabel());n.children.push(o)}n.children.push(_utils2.default.getTranscludeNode($tm.ref.focusButton));this.makeChildWidgets([n]);this.renderChildren(this.graphBarDomNode,this.graphBarDomNode.firstChild)}},{key:"refresh",value:function e(t){return false}},{key:"update",value:function e(t){if(!this.network||this.isZombieWidget()||_utils2.default.isPreviewed(this)){return}var i=t.changedTiddlers;this.callbackManager.refresh(i);if(this.isViewSwitched(i)||this.hasChangedAttributes()||t[env.path.options]||i[this.view.getRoot()]){this.logger("warn","View switched or config changed");this.isPreventZoomOnNextUpdate=false;this.view=this.getView(true);this.reloadRefreshTriggers();this.trace=_utils2.default.makeHashMap();this.rebuildEditorBar();this.reloadBackgroundImage();this.initAndRenderGraph(this.graphDomNode)}else{var a=this.view.update(t);if(a){this.logger("warn","View components modified");this.rebuildGraph({resetFocus:{delay:1e3,duration:1e3}})}else{if(t[env.path.nodeTypes]||this.hasChangedElements(i)){this.rebuildGraph()}this.refreshChildren(i)}}}},{key:"hidePopups",value:function e(t,i){this.tooltip.hide(t,i);this.contextMenu.hide(0,true)}},{key:"reloadRefreshTriggers",value:function e(){this.callbackManager.remove(this.refreshTriggers);var t=this.getAttr("refresh-triggers")||this.view.getConfig("refresh-triggers");this.refreshTriggers=$tw.utils.parseStringArray(t)||[];this.logger("debug","Registering refresh trigger",this.refreshTriggers);for(var i=this.refreshTriggers.length;i--;){this.callbackManager.add(this.refreshTriggers[i],this.handleTriggeredRefresh,false)}}},{key:"rebuildGraph",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},i=t.resetFocus;if(_utils2.default.isPreviewed(this)){return}this.logger("debug","Rebuilding graph");this.hidePopups(0,true);this.hasNetworkStabilized=false;var a=this.rebuildGraphData();if(a.changedNodes.withoutPosition.length){i=i||{delay:1e3,duration:1e3};if(!this.view.isEnabled("physics_mode")){var s=this.visOptions.physics;s[s.solver].centralGravity=.25;this.network.setOptions(this.visOptions)}}if(!_utils2.default.hasElements(this.graphData.nodesById)){return}if(i){var r=this.isPreventZoomOnNextUpdate==null?false:typeof this.isPreventZoomOnNextUpdate==="number"?this.isPreventZoomOnNextUpdate>Date.now():this.isPreventZoomOnNextUpdate;if(!r){this.network.stabilize();this.resetFocus=i}if(typeof this.isPreventZoomOnNextUpdate!=="number"){this.isPreventZoomOnNextUpdate=false}}}},{key:"getContainer",value:function e(){return this.domNode}},{key:"rebuildGraphData",value:function e(){var t=this;$tm.start("Reloading Network");var i={view:this.view};if(this.view.isEnabled("neighbourhood_trace_clicks")){var a=_utils2.default.getMatches(this.view.getNodeFilter("compiled"));var s=Object.keys(this.trace);var r=[].concat(_toConsumableArray(a.filter(function(e){return!t.trace[e]})),_toConsumableArray(s));i.matches=r;i.includeNeighboursOf=this.view.isEnabled("neighbourhood_include_traced_node_neighbours")?function(e){return r.includes(e)}:function(e){return a.includes(e)}}var n=$tm.adapter.getGraph(i);var o=_utils2.default.refreshDataSet(this.graphData.nodes,n.nodes);var l=_utils2.default.refreshDataSet(this.graphData.edges,n.edges);this.graphData.nodesById=n.nodes;this.graphData.edgesById=n.edges;_utils2.default.setField("$:/temp/tmap/nodes/"+this.view.getLabel(),"list",$tm.adapter.getTiddlersByIds(n.nodes));$tm.stop("Reloading Network");return{changedEdges:l,changedNodes:o}}},{key:"isViewBound",value:function e(){return _utils2.default.startsWith(this.getViewHolderRef(),$tm.path.localHolders)}},{key:"isViewSwitched",value:function e(t){return!_ViewAbstraction2.default.exists(this.view)||t[this.getViewHolderRef()]}},{key:"hasChangedAttributes",value:function e(){return Object.keys(this.computeAttributes()).length}},{key:"hasChangedElements",value:function e(t){var i=[];var a=this.graphData.nodesById;var s=this.view.isEnabled("neighbourhood_scope");for(var r in t){if(_utils2.default.isSystemOrDraft(r)){continue}if(a[$tm.adapter.getId(r)]||s){return true}if(t[r].modified){i.push(r)}}if(i.length){var n=this.view.getNodeFilter("compiled");var o=_utils2.default.getMatches(n,i);return!!o.length}}},{key:"initAndRenderGraph",value:function e(t){var i=this;if(this.network){this._destructVis()}this.logger("info","Initializing and rendering the graph");if(!this.isInSidebar){this.callbackManager.add("$:/state/sidebar",this.handleResizeEvent)}this.visOptions=this.getVisOptions();this.graphData={nodes:new _vis2.default.DataSet,edges:new _vis2.default.DataSet,nodesById:_utils2.default.makeHashMap(),edgesById:_utils2.default.makeHashMap()};this.tooltip.setEnabled(_utils2.default.isTrue($tm.config.sys.popups.enabled,true));this.trace=_utils2.default.makeHashMap();this.network=new _vis2.default.Network(t,this.graphData,this.visOptions);this.canvas=t.getElementsByTagName("canvas")[0];this.networkDomNode=_utils2.default.getFirstElementByClassName("vis-network",t,true);this.canvas.tabIndex=0;for(var a in this.visListeners){this.network.on(a,this.visListeners[a].bind(this))}this.addGraphButtons({"fullscreen-button":function e(){i.toggleEnlargedMode("fullscreen")},"halfscreen-button":function e(){i.toggleEnlargedMode("halfscreen")}});_utils2.default.setDomListeners("add",this.canvas,this.canvasDomListeners);this.reloadBackgroundImage();this.rebuildGraph({resetFocus:{delay:0,duration:0}});this.handleResizeEvent();this.canvas.focus();if(this.view.isLiveView()&&this.view.isEnabled("neighbourhood_trace_clicks")){this.trace[_utils2.default.getText(this.refreshTriggers[0])]=true}}},{key:"handleCanvasKeyup",value:function e(t){var i=this;var a=this.network.getSelectedNodes();if(t.ctrlKey){t.preventDefault();if(t.keyCode===88){if(this.editorMode){this.handleAddNodesToClipboard("move")}else{$tm.notify("Map is read only!")}}else if(t.keyCode===67){this.handleAddNodesToClipboard("copy")}else if(t.keyCode===86){this.handlePasteNodesFromClipboard()}else if(t.keyCode===65){var s=Object.keys(this.graphData.nodesById);this.network.selectNodes(s)}else if(t.keyCode===49||t.keyCode===50){if(a.length!==1)return;var r=t.keyCode===49?"from":"to";$tm.notify(_utils2.default.ucFirst(r)+"-part selected");this.conVector[r]=a[0];if(this.conVector.from&&this.conVector.to){this.handleConnectionEvent(this.conVector,function(){i.conVector={from:null,to:null}})}}}else{if(t.keyCode===13){if(a.length!==1)return;this.openTiddlerWithId(a[0])}}}},{key:"handleCanvasKeydown",value:function e(t){if(t.altKey||t.metaKey){t.preventDefault();if(t.keyCode>=48&&t.keyCode<=57){var i=String.fromCharCode(t.keyCode);this.view.setConfig("neighbourhood_scope",i)}}else{if(t.keyCode===46){t.preventDefault();this.handleRemoveElements(this.network.getSelection())}}}},{key:"handleDeleteElement",value:function e(t){var i=t.paramObject.id;var a=i?[i]:this.network.getSelectedNodes();this.handleRemoveElements({nodes:a})}},{key:"handleCanvasMouseMove",value:function e(t){var i=this.network;if(!(t.ctrlKey&&t.buttons)){if(this.selectRect){this.selectRect=null;var a=i.getSelectedNodes();$tm.notify(a.length+" nodes selected");i.redraw()}return}t.preventDefault();t.stopPropagation();if(!this.domNode.contains(t.target)){return}var s=i.DOMtoCanvas({x:t.offsetX,y:t.offsetY});if(!this.selectRect){this.selectRect=new _SelectionRectangle2.default(s.x,s.y)}this.selectRect.span(s.x,s.y);var r=i.getPositions();var n=i.getSelectedNodes();for(var o in r){if(this.selectRect.isPointWithin(r[o])&&!_utils2.default.inArray(o,n)){n.push(o)}}i.selectNodes(n);this.assignActiveStyle(n);i.redraw()}},{key:"handleCanvasScroll",value:function e(t){var i=!!(this.isInSidebar||t.ctrlKey||this.enlargedMode||this.clickToUse&&this.networkDomNode.classList.contains("vis-active"));var a=this.visOptions.interaction;var s=i===a.zoomView;if(i||!s){t.preventDefault()}if(!s){t.stopPropagation();a.zoomView=i;this.network.setOptions({interaction:{zoomView:i}});return false}}},{key:"handleExtraCanvasScroll",value:function e(t){t.preventDefault()}},{key:"handleContextMenu",value:function e(t){var i=this;t.preventDefault();var a=this.network;this.hidePopups(0,true);var s=a.getNodeAt({x:t.offsetX,y:t.offsetY});if(!s)return;var r=a.getSelectedNodes();if(!_utils2.default.inArray(s,r)){r=[s];a.selectNodes(r)}this.contextMenu.show(r,function(e,t){var a=e.length>1?"multi":"single";var s="$:/plugins/felixhayashi/tiddlymap/editor/contextMenu/node";_utils2.default.registerTransclude(i,"contextMenuWidget",s);i.contextMenuWidget.setVariable("mode",a);i.contextMenuWidget.render(t)})}},{key:"handleWidgetKeyup",value:function e(t){}},{key:"handleWidgetKeydown",value:function e(t){if(t.ctrlKey){t.preventDefault();if(t.keyCode===70){t.preventDefault();var i=this.widgetPopupsPath+"/focus";_utils2.default.setText(i,_utils2.default.getText(i)?"":"1")}else{return}}else if(t.keyCode===120){t.preventDefault();this.toggleEnlargedMode("halfscreen")}else if(t.keyCode===121){t.preventDefault();this.toggleEnlargedMode("fullscreen")}else if(t.keyCode===27){t.preventDefault();_utils2.default.deleteByPrefix(this.widgetPopupsPath)}else{return}this.canvas.focus()}},{key:"handlePasteNodesFromClipboard",value:function e(){if(!this.editorMode){$tm.notify("Map is read only!");return}if(!$tm.clipBoard||$tm.clipBoard.type!=="nodes"){$tm.notify("TiddlyMap clipboad is empty!")}var t=$tm.clipBoard.nodes;var i=Object.keys(t);for(var a=i.length;a--;){var s=i[a];if(this.graphData.nodesById[s]){continue}this.view.addNode(t[s]);this.graphData.nodes.update({id:s})}this.network.selectNodes(i);this.rebuildGraph({resetFocus:{delay:0,duration:0}});$tm.notify("pasted "+i.length+" nodes into map.")}},{key:"handleAddNodesToClipboard",value:function e(t){var i=this.network.getSelectedNodes();if(!i.length){return}$tm.clipBoard={type:"nodes",nodes:this.graphData.nodes.get(i,{returnType:"Object"})};$tm.notify("Copied "+i.length+" nodes to clipboard");if(t==="move"){for(var a=i.length;a--;){this.view.removeNode(i[a])}}this.isPreventZoomOnNextUpdate=true}},{key:"getVisOptions",value:function e(){var t=this;var i=$tm.config.vis;var a=_utils2.default.parseJSON(this.view.getConfig("vis"))||{};var s=a.layout||{},r=s.hierarchical;var n={layout:{hierarchical:{enabled:r===undefined||r===null?false:typeof r==="boolean"?r:r.enabled!==false}}};var o=_utils2.default.merge({},i,_utils2.default.merge(a,n));o.clickToUse=this.clickToUse;o.manipulation.enabled=!!this.editorMode;o.manipulation.deleteNode=function(e,i){t.handleRemoveElements(e);t.resetVisManipulationBar(i)};o.manipulation.deleteEdge=function(e,i){t.handleRemoveElements(e);t.resetVisManipulationBar(i)};o.manipulation.addEdge=function(e,i){t.handleConnectionEvent(e);t.resetVisManipulationBar(i)};o.manipulation.addNode=function(e,i){t.handleInsertNode(e);t.resetVisManipulationBar(i)};o.manipulation.editNode=function(e,i){t.handleEditNode(e);t.resetVisManipulationBar(i)};o.interaction.zoomView=!!(this.isInSidebar||this.enlargedMode);o.manipulation.editEdge=false;var l=o.physics;l[l.solver]=l[l.solver]||{};l.stabilization.iterations=1e3;this.logger("debug","Loaded graph options",o);return o}},{key:"resetVisManipulationBar",value:function e(t){if(t){t(null)}this.network.disableEditMode();this.network.enableEditMode()}},{key:"isVisInEditMode",value:function e(){return this.graphDomNode.getElementsByClassName("vis-button vis-back").length>0}},{key:"handleCreateView",value:function e(){var t=this;var i={view:this.view.getLabel()};$tm.dialogManager.open("createView",i,function(e,i){if(!e)return;var a=_utils2.default.getField(i,"name");var s=_utils2.default.getField(i,"clone",false);if(_ViewAbstraction2.default.exists(a)){$tm.notify("Forbidden! View already exists!");return}if(s&&t.view.isLiveView()){$tm.notify("Forbidden to clone the live view!");return}var r=new _ViewAbstraction2.default(a,{isCreate:true,protoView:s?t.view:null});t.setView(r)})}},{key:"handleRenameView",value:function e(){var t=this;if(this.view.isLocked()){$tm.notify("Forbidden!");return}var i=this.view.getOccurrences();var a={count:i.length.toString(),refFilter:_utils2.default.joinAndWrap(i,"[[","]]")};$tm.dialogManager.open("renameView",a,function(e,i){if(!e){return}var a=_utils2.default.getText(i);if(!a){$tm.notify("Invalid name!")}else if(_ViewAbstraction2.default.exists(a)){$tm.notify("Forbidden! View already exists!")}else{t.view.rename(a);t.setView(t.view)}})}},{key:"handleEditView",value:function e(){var t=this;var i=JSON.stringify($tm.config.vis);var a=this.graphData;var s=this.view.getConfig();var r={"filter.prettyNodeFltr":this.view.getNodeFilter("pretty"),"filter.prettyEdgeFltr":this.view.getEdgeTypeFilter("pretty"),"inherited-style":i};var n={view:this.view.getLabel(),createdOn:this.view.getCreationDate(true),numberOfNodes:Object.keys(a.nodesById).length.toString(),numberOfEdges:Object.keys(a.edgesById).length.toString(),dialog:{preselects:$tw.utils.extend({},s,r)}};$tm.dialogManager.open("configureView",n,function(e,i){if(!e){return}var a=_utils2.default.getPropertiesByPrefix(i.fields,"config.",true);var s=t.view.getConfig("background_image");t.view.setConfig(a);if(a["physics_mode"]&&!t.view.isEnabled("physics_mode")){t.view.saveNodePositions(t.network.getPositions())}var r=t.view.getConfig("background_image");if(r&&r!==s){$tm.notify("Background changed! You may need to zoom out a bit.")}var n=_utils2.default.getField(i,"filter.prettyNodeFltr","");var o=_utils2.default.getField(i,"filter.prettyEdgeFltr","");t.view.setNodeFilter(n);t.view.setEdgeTypeFilter(o)})}},{key:"handleSaveCanvas",value:function e(){var t=this;var i="$:/temp/tmap/snapshot";this.createAndSaveSnapshot(100,100,i);var a=this.view.getLabel()+".png";var s={dialog:{snapshot:i,view:this.view.getLabel(),preselects:{width:this.canvas.width.toString(),height:this.canvas.height.toString(),name:a,action:"download"}}};$tm.dialogManager.open("saveCanvas",s,function(e,a){if(!e)return;var r=a.fields.width||s.dialog.preselects.width;var n=a.fields.height||s.dialog.preselects.height;t.createAndSaveSnapshot(r,n,i);var o=a.fields.name||s.dialog.preselects.imageName;var l=a.fields.action;if(l==="download"){t.handleDownloadSnapshot(r,n,o)}else if(l==="wiki"){_utils2.default.cp(i,o,true);t.dispatchEvent({type:"tm-navigate",navigateTo:o})}else if(l==="placeholder"){t.view.addPlaceholder(i)}$tw.wiki.deleteTiddler("$:/temp/tmap/snapshot")})}},{key:"handleDownloadSnapshot",value:function e(t,i,a){var s=this.document.createElement("a");var r=this.view.getLabel();s.download=a;s.href=this.getCanvasAsBase64({size:{width:t,height:i}});var n=new MouseEvent("click");s.dispatchEvent(n)}},{key:"createAndSaveSnapshot",value:function e(t,i,a,s){$tw.wiki.addTiddler(new $tw.Tiddler({title:s||a,type:"image/png",text:this.getCanvasAsBase64({size:{width:t,height:i},withoutPreamble:true})},$tw.wiki.getCreationFields(),$tw.wiki.getModificationFields()));return a}},{key:"getCanvasAsBase64",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},i=t.withoutPreamble,a=t.size;var s=this.graphDomNode.style.width;var r=this.graphDomNode.style.height;if(a){this.graphDomNode.style.width=a.width+"px";this.graphDomNode.style.height=a.height+"px";this.network.redraw()}var n=this.canvas.toDataURL("image/png");if(a){this.graphDomNode.style.width=s;this.graphDomNode.style.height=r;this.network.redraw()}return i?_utils2.default.getWithoutPrefix(n,"data:image/png;base64,"):n}},{key:"handleDeleteView",value:function e(){var t=this;var i=this.view.getLabel();if(this.view.isLocked()){$tm.notify("Forbidden!");return}var a=this.view.getOccurrences();if(a.length){var s={count:a.length.toString(),refFilter:_utils2.default.joinAndWrap(a,"[[","]]")};$tm.dialogManager.open("cannotDeleteViewDialog",s);return}var r="\n        You are about to delete the view ''"+i+"''\n        (no tiddler currently references this view).\n     ";this.openStandardConfirmDialog(function(e){if(!e){return}t.view.destroy();t.setView($tm.misc.defaultViewLabel);var a='view "'+i+"' deleted";t.logger("debug",a);$tm.notify(a)},r)}},{key:"handleTriggeredRefresh",value:function e(t){this.logger("log",t,"Triggered a refresh");var i=_utils2.default.getTiddler(_utils2.default.getText(t));if(this.view.isLiveView()){if(i){if(this.view.isEnabled("neighbourhood_trace_clicks")){this.trace[i.fields.title]=true}var a=i.fields["tmap.open-view"]||$tm.config.sys.liveTab.fallbackView;if(a&&a!==this.view.getLabel()){this.setView(a);return}}}this.rebuildGraph({resetFocus:{delay:1e3,duration:1e3}})}},{key:"handleRemoveElements",value:function e(t){var i=t.nodes,a=t.edges;if(i.length){this.handleRemoveNodes(i)}else if(a.length){this.handleRemoveEdges(a)}this.resetVisManipulationBar()}},{key:"handleRemoveEdges",value:function e(t){$tm.adapter.deleteEdges(this.graphData.edges.get(t));$tm.notify("edge"+(t.length>1?"s":"")+" removed")}},{key:"handleRemoveNodes",value:function e(t){var i=this;var a=$tm.adapter.getTiddlersByIds(t);var s={count:t.length.toString(),tiddlers:$tw.utils.stringifyList(a),dialog:{preselects:{"delete-from":"filter"}}};$tm.dialogManager.open("deleteNodeDialog",s,function(e,a){if(!e)return;var s=0;for(var r=t.length;r--;){var n=i.view.removeNode(t[r]);if(n){s++}}if(a.fields["delete-from"]==="system"){$tm.adapter.deleteNodes(t);s=t.length}i.isPreventZoomOnNextUpdate=true;$tm.notify("\n        Removed "+s+"\n        of "+t.length+"\n        from "+a.fields["delete-from"]+"\n      ")})}},{key:"toggleEnlargedMode",value:function e(t){if(!this.isInSidebar&&t==="halfscreen"){return}this.logger("log","Toggled graph enlargement");var i=this.enlargedMode;if(i){this.network.setOptions({clickToUse:this.clickToUse});_utils2.default.findAndRemoveClassNames(["tmap-has-"+i+"-widget","tmap-"+i]);this.enlargedMode=null;document.body.scrollTop=this.scrollTop}if(!i||i!==t&&(t==="fullscreen"||t==="halfscreen"&&!this.isInSidebar)){this.scrollTop=document.body.scrollTop;this.enlargedMode=t;var a=this.isInSidebar?this.sidebar:_utils2.default.getFirstElementByClassName("tc-story-river");$tw.utils.addClass(this.document.body,"tmap-has-"+t+"-widget");$tw.utils.addClass(a,"tmap-has-"+t+"-widget");$tw.utils.addClass(this.domNode,"tmap-"+t);this.network.setOptions({clickToUse:false});$tm.notify("Toggled "+t+" mode")}this.handleResizeEvent()}},{key:"handleGenerateWidget",value:function e(t){$tw.rootWidget.dispatchEvent({type:"tmap:tm-generate-widget",paramObject:{view:this.view.getLabel()}})}},{key:"handleSetCentralTopic",value:function e(t){var i=t.paramObject;var a=i.id||this.network.getSelectedNodes()[0];if(a===this.view.getConfig("central-topic")){a=""}this.view.setCentralTopic(a)}},{key:"handleVisStabilizedEvent",value:function e(t){if(this.hasNetworkStabilized){return}this.hasNetworkStabilized=true;this.logger("log","Network stabilized after",t.iterations,"iterations");if(!this.view.isEnabled("physics_mode")){var i=this.graphData.nodesById;var a=[];for(var s in i){if(i[s].x===undefined){a.push(s)}}if(a.length){this.setNodesMoveable(a,false);$tm.notify(a.length+" nodes were added to the graph")}var r=this.visOptions.physics;r[r.solver].centralGravity=0;this.network.setOptions(this.visOptions)}if(this.resetFocus){this.fitGraph(this.resetFocus.delay,this.resetFocus.duration);this.resetFocus=null}}},{key:"handleFocusNode",value:function e(t){var i=t.param;this.network.focus($tm.adapter.getId(i),{scale:1.5,animation:true})}},{key:"isZombieWidget",value:function e(){return this.domNode.isTiddlyWikiFakeDom===true||!this.document.body.contains(this.getContainer())}},{key:"fitGraph",value:function e(){var t=this;var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;clearTimeout(this.activeFitTimeout);var s=function e(){if(t.isZombieWidget()){return}t.network.redraw();t.network.fit({animation:{duration:a,easingFunction:"easeOutQuart"}})};this.activeFitTimeout=setTimeout(s,i)}},{key:"handleInsertNode",value:function e(t){var i=this;$tm.dialogManager.open("addNodeToMap",{},function(e,a){if(!e){return}var s=_utils2.default.getField(a,"draft.title").trim();if(_utils2.default.tiddlerExists(s)){if(_utils2.default.isMatch(s,i.view.getNodeFilter("compiled"))){$tm.notify("Node already exists");return}else{t=$tm.adapter.makeNode(s,t);i.view.addNode(t)}}else{var r=new $tw.Tiddler(a,{"draft.title":null});t.label=s;$tm.adapter.insertNode(t,i.view,r)}i.isPreventZoomOnNextUpdate=true})}},{key:"handleEditNode",value:function e(t){var i=this;var a=$tm.tracker.getTiddlerById(t.id);var s=_utils2.default.getTiddler(a);var r=$tm.config.vis.nodes;var n=_utils2.default.parseJSON(this.view.getConfig("vis"),{}).nodes;var o={};o[t.id]=t;var l=$tm.adapter.getInheritedNodeStyles(o);var d=l[a];var h=_utils2.default.merge({},{color:s.fields["color"]},_utils2.default.parseJSON(s.fields["tmap.style"]));var u=this.view.getLabel();var g=_extends({},this.view.getNodeData(t.id));delete g.x;delete g.y;var f={view:u,tiddler:s.fields.title,tidColor:s.fields["color"],tidIcon:s.fields[$tm.field.nodeIcon]||s.fields["tmap.fa-icon"],tidLabelField:"global."+$tm.field.nodeLabel,tidIconField:"global."+$tm.field.nodeIcon,dialog:{preselects:{"inherited-global-default-style":JSON.stringify(r),"inherited-local-default-style":JSON.stringify(n),"inherited-group-styles":JSON.stringify(d),"global.tmap.style":JSON.stringify(h),"local-individual-node-style":JSON.stringify(g)}}};var v=function e(t,i,a){for(var s=a.length;s--;){f.dialog.preselects[t+"."+a[s]]=i[a[s]]||""}};v("local",g,["label","tw-icon","fa-icon","open-view"]);v("global",s.fields,[$tm.field.nodeLabel,$tm.field.nodeIcon,"tmap.fa-icon","tmap.open-view"]);$tm.dialogManager.open("editNode",f,function(e,s){if(!e)return;var r=s.fields;var n=_utils2.default.getPropertiesByPrefix(r,"global.",true);for(var o in n){_utils2.default.setField(a,o,n[o]||undefined)}var l=_utils2.default.getPropertiesByPrefix(r,"local.",true);var d=_utils2.default.parseJSON(r["local-individual-node-style"],{});for(var h in l){d[h]=l[h]||undefined}i.view.saveNodeStyle(t.id,d);i.isPreventZoomOnNextUpdate=true})}},{key:"handleVisSingleClickEvent",value:function e(t){var i=_utils2.default.isTrue($tm.config.sys.singleClickMode);if(i&&!this.editorMode){this.handleOpenMapElementEvent(t)}}},{key:"handleVisDoubleClickEvent",value:function e(t){if(t.nodes.length||t.edges.length){if(this.editorMode||!_utils2.default.isTrue($tm.config.sys.singleClickMode)){this.handleOpenMapElementEvent(t)}}else{if(this.editorMode){this.handleInsertNode(t.pointer.canvas)}}}},{key:"handleOpenMapElementEvent",value:function e(t){var i=this;var a=t.nodes,s=t.edges;if(a.length){var r=this.graphData.nodesById[a[0]];if(this.view.isEnabled("neighbourhood_trace_clicks")){this.trace[$tm.adapter.getTiddlerById(r.id)]=true;this.isPreventZoomOnNextUpdate=Date.now()+500;this.rebuildGraph();if(this.view.isEnabled("neighbourhood_focus_newly_traced_node")){setTimeout(function(){i.network.focus(r.id,{scale:1,animation:true})},1500)}}if(r["open-view"]){$tm.notify("Switching view");this.setView(r["open-view"])}else{this.openTiddlerWithId(a[0])}}else if(s.length){this.logger("debug","Clicked on an Edge");var n=this.graphData.edgesById[s[0]].type;this.handleEditEdgeType(n)}else{return}this.hidePopups(0,true)}},{key:"handleEditEdgeType",value:function e(t){if(!this.editorMode)return;var i=$tm.config.sys.edgeClickBehaviour;if(i!=="manager")return;$tw.rootWidget.dispatchEvent({type:"tmap:tm-manage-edge-types",paramObject:{type:t}})}},{key:"handleResizeEvent",value:function e(t){if(this.isZombieWidget())return;var i=this.getAttr("height");var a=this.getAttr("width");if(this.isInSidebar){var s=this.domNode.getBoundingClientRect();var r=15;a=document.body.clientWidth-s.left-r+"px";var n=parseInt(this.getAttr("bottom-spacing"))||15;var o=window.innerHeight-s.top;i=o-n+"px"}this.domNode.style.height=i||"300px";this.domNode.style.width=a;this.repaintGraph()}},{key:"handleClickEvent",value:function e(t){if(this.isZombieWidget()||!this.network)return;if(!this.graphDomNode.contains(t.target)){var i=this.network.getSelection();if(i.nodes.length||i.edges.length){this.logger("debug","Clicked outside; deselecting nodes/edges");this.network.selectNodes([]);this.resetVisManipulationBar()}}else{this.canvas.focus()}if(t.button!==2){this.contextMenu.hide(0,true)}}},{key:"handleVisSelectNode",value:function e(t){var i=t.nodes;if(!this.isDraggingAllowed(i)){return}this.assignActiveStyle(i)}},{key:"isDraggingAllowed",value:function e(t){var i=t.nodes;return this.editorMode||this.view.isEnabled("physics_mode")}},{key:"assignActiveStyle",value:function e(t){if(!Array.isArray(t))t=[t];var i=this.visOptions.nodes.color;for(var a=t.length;a--;){var s=t[a];var r=this.graphData.nodesById[s];var n=_utils2.default.merge({},i,r.color);this.graphData.nodes.update({id:s,color:{highlight:n,hover:n}})}}},{key:"handleVisDeselectNode",value:function e(t){}},{key:"handleVisDragEnd",value:function e(t){var i=t.nodes;if(!i.length){return}if(i.length===1&&this.view.isEnabled("raster")){var a=this.network.getPositions()[i[0]];this.graphData.nodes.update(_extends({id:i[0]},_utils2.default.getNearestRasterPosition(a,parseInt(this.view.getConfig("raster")))))}this.draggedNode=null;this.setNodesMoveable(i,false)}},{key:"handleVisBeforeDrawing",value:function e(t){var i=this.view,a=this.network,s=this.backgroundImage;if(s){t.drawImage(s,0,0)}if(i.isEnabled("raster")){_utils2.default.drawRaster(t,a.getScale(),a.getViewPosition(),parseInt(i.getConfig("raster")))}}},{key:"handleVisAfterDrawing",value:function e(t){if(this.selectRect){var i=this.selectRect.getRect();t.beginPath();t.globalAlpha=.5;t.fillStyle="#EAFFEF";t.fillRect.apply(t,_toConsumableArray(i));t.beginPath();t.globalAlpha=1;t.strokeStyle="#B4D9BD";t.strokeRect.apply(t,_toConsumableArray(i))}if(this.draggedNode&&this.view.isEnabled("raster")){var a=this.network.getPositions()[this.draggedNode];var s=_utils2.default.getNearestRasterPosition(a,parseInt(this.view.getConfig("raster")));t.strokeStyle="green";t.fillStyle="green";t.beginPath();t.moveTo(a.x,a.y);t.lineTo(s.x,s.y);t.stroke();t.beginPath();t.arc(s.x,s.y,5,0,Math.PI*2);t.fill()}}},{key:"constructTooltip",value:function e(t,i){var a=_utils2.default.parseJSON(t);var s=a.node||a.edge;var r=null;var n="text/html";var o="text/vnd-tiddlywiki";if(a.node){var l=$tm.tracker.getTiddlerById(s);var d=_utils2.default.getTiddler(l);var h=d.fields[$tm.field.nodeInfo];if(h){i.innerHTML=$tw.wiki.renderText(n,o,h)}else if(d.fields.text){_utils2.default.registerTransclude(this,"tooltipWidget",l);this.tooltipWidget.setVariable("tv-tiddler-preview","yes");this.tooltipWidget.render(i)}else{i.innerHTML=l}}else{var u=this.graphData.edgesById[s];var g=$tm.indeces.allETy[u.type];if(g.description){r=$tw.wiki.renderText(n,o,g.description)}i.innerHTML=r||g.label||g.id}}},{key:"handleVisHoverElement",value:function e(t){if($tm.mouse.buttons)return;var i=t.node||t.edge;var a=JSON.stringify(t);if(t.node){this.assignActiveStyle(i)}if(!this.isVisInEditMode()&&!this.contextMenu.isShown()){var s=this.constructTooltip;this.tooltip.show(a,s)}}},{key:"handleVisBlurElement",value:function e(t){this.tooltip.hide()}},{key:"handleVisLoading",value:function e(t){var i=t.total,a=t.iterations;this.graphLoadingBarDomNode.style.display="block";this.graphLoadingBarDomNode.setAttribute("max",i);this.graphLoadingBarDomNode.setAttribute("value",a)}},{key:"handleVisLoadingDone",value:function e(t){this.graphLoadingBarDomNode.style.display="none"}},{key:"handleVisDragStart",value:function e(t){var i=t.nodes;if(!i.length||!this.isDraggingAllowed(i)){return}this.hidePopups(0,true);this.assignActiveStyle(i);this.setNodesMoveable(i,true);if(i.length===1){this.draggedNode=i[0]}}},{key:"destruct",value:function e(){_utils2.default.setDomListeners("remove",window,this.windowDomListeners);_utils2.default.setDomListeners("remove",this.domNode,this.widgetDomListeners);this._destructVis()}},{key:"_destructVis",value:function e(){if(!this.network)return;_utils2.default.setDomListeners("remove",this.canvas,this.canvasDomListeners);this.network.destroy();this.network=null}},{key:"openTiddlerWithId",value:function e(t){var i=this;var a=$tm.tracker.getTiddlerById(t);this.logger("debug","Opening tiddler",a,"with id",t);if(this.enlargedMode==="fullscreen"){var s=$tw.wiki.findDraft(a);var r=!!s;if(!r){var n="tm-edit-tiddler";this.dispatchEvent({type:n,tiddlerTitle:a});s=$tw.wiki.findDraft(a)}var o={draftTRef:s,originalTRef:a};$tm.dialogManager.open("fullscreenTiddlerEditor",o,function(e,t){if(e){var n="tm-save-tiddler";i.dispatchEvent({type:n,tiddlerTitle:s})}else if(!r){_utils2.default.deleteTiddlers([s])}var o="tm-close-tiddler";i.dispatchEvent({type:o,tiddlerTitle:a})})}else{var l=this.domNode.getBoundingClientRect();this.dispatchEvent({type:"tm-navigate",navigateTo:a,navigateFromTitle:this.getVariable("storyTiddler"),navigateFromNode:this,navigateFromClientRect:{top:l.top,left:l.left,width:l.width,right:l.right,bottom:l.bottom,height:l.height}})}}},{key:"getViewHolderRef",value:function e(){if(this.viewHolderRef){return this.viewHolderRef}this.logger("info","Retrieving or generating the view holder reference");var t=this.getAttr("view");var i=null;if(t){this.logger("log",'User wants to bind view "'+t+"' to graph");var a=$tm.path.views+"/"+t;if($tw.wiki.getTiddler(a)){i=$tm.path.localHolders+"/"+_utils2.default.genUUID();this.logger("log",'Created an independent temporary view holder "'+i+'"');_utils2.default.setText(i,a);this.logger("log",'View "'+a+"' inserted into independend holder")}else{this.logger("log",'View "'+t+'" does not exist')}}if(!i){this.logger("log","Using default (global) view holder");i=$tm.ref.defaultViewHolder}return i}},{key:"setView",value:function e(t,i){if(!_ViewAbstraction2.default.exists(t)){return}t=new _ViewAbstraction2.default(t);var a=t.getLabel();i=i||this.viewHolderRef;this.logger("info",'Inserting view "'+a+'" into holder "'+i+'"');$tw.wiki.addTiddler(new $tw.Tiddler({title:i,text:a}));this.update({changedTiddlers:_defineProperty({},i,true)})}},{key:"getView",value:function e(t){if(!t&&this.view){return this.view}var i=this.getViewHolderRef();var a=_utils2.default.getText(i);this.logger("debug","Retrieved view from holder");var s=void 0;if(_ViewAbstraction2.default.exists(a)){s=new _ViewAbstraction2.default(a)}else{this.logger("debug",'Warning: View "'+a+"\" doesn't exist. Default is used instead.");s=new _ViewAbstraction2.default("Default")}return s}},{key:"reloadBackgroundImage",value:function e(t){var i=this;this.backgroundImage=null;var a=this.view.getConfig("background_image");var s=_utils2.default.getTiddler(a);if(!s&&!a)return;var r=new Image;r.onload=function(){i.backgroundImage=r;i.repaintGraph()};if(s){var n=s.fields["_canonical_uri"];if(n){r.src=n}else if(s.fields.text){r.src=$tw.utils.makeDataUri(s.fields.text,s.fields.type)}}else if(a){r.src=a}}},{key:"repaintGraph",value:function e(){var t=$tw.utils.hasClass(this.document.body,"tmap-has-fullscreen-widget");if(this.network&&(!t||t&&this.enlargedMode)){this.logger("info","Repainting the whole graph");this.network.redraw();this.fitGraph(0,1e3)}}},{key:"setGraphButtonEnabled",value:function e(t,i){var a="vis-button tmap-"+t;var s=_utils2.default.getFirstElementByClassName(a,this.domNode);$tw.utils.toggleClass(s,"tmap-button-enabled",i)}},{key:"setNodesMoveable",value:function e(t,i){if(!t||!t.length||this.view.isEnabled("physics_mode")){return}var a=[];var s=!i;for(var r=t.length;r--;){a.push({id:t[r],fixed:{x:s,y:s}})}this.graphData.nodes.update(a);if(s){this.logger("debug","Fixing",a.length,"nodes");this.view.saveNodePositions(this.network.getPositions());this.isPreventZoomOnNextUpdate=true}}},{key:"addGraphButtons",value:function e(t){var i=_utils2.default.getFirstElementByClassName("vis-navigation",this.domNode);for(var a in t){var s=this.document.createElement("div");s.className="vis-button tmap-"+a;s.addEventListener("click",t[a].bind(this),false);i.appendChild(s);this.setGraphButtonEnabled(a,true)}}}]);return t}(_widget.widget);exports.tmap=MapWidget;exports.tiddlymap=MapWidget;
                                                                                                                                                                                                                                                                 ^

ReferenceError: $tm is not defined
    at new t ($:/plugins/felixhayashi/tiddlymap/js/widget/MapWidget:11:258)
    at ElementWidget.Widget.makeChildWidget ($:/core/modules/widgets/widget.js:353:9)
    at $:/core/modules/widgets/widget.js:340:27
    at Object.$tw.utils.each (/usr/local/lib/node_modules/tiddlywiki/boot/boot.js:126:12)
    at ElementWidget.Widget.makeChildWidgets ($:/core/modules/widgets/widget.js:339:12)
    at ElementWidget.render ($:/core/modules/widgets/element.js:66:7)
    at TranscludeWidget.Widget.renderChildren ($:/core/modules/widgets/widget.js:393:15)
    at TranscludeWidget.render ($:/core/modules/widgets/transclude.js:33:7)
    at ImportVariablesWidget.Widget.renderChildren ($:/core/modules/widgets/widget.js:393:15)
    at ImportVariablesWidget.render ($:/core/modules/widgets/importvariables.js:33:7)
flibbles commented 6 months ago

@scarbajali, Sooo... I'm about three years later than you would have probably liked. I'm not really the primary developer on this, but I've gotten around to looking into this.

I'm not sure how the TiddlyRemember plugin works. Does it use Node.JS at all? My guess is that the synchronization is trying to render the tiddler with the MapWidget before TiddlyMap has an opportunity to load. It looks like parts of TiddlyWiki are being called through python? That would likely do it. TiddlyMap doesn't work at all on command line.

If you still want this fix (which I totally understand if you've moved on), I could install something into MapWidget which would neuter the widget if it's not in a browser context. (There's no need for it to work if it's not.) But I would need to have you around to test it.

If you're not around anymore, I may close this. The primary developer for TiddlyMap is gone. I'm just here keeping the lights on.

scarbajali commented 6 months ago

HI @flibbles,

after all I moved on, so I'm ok to close this.

Thanks anyways for the support and keeping the lights on!

flibbles commented 6 months ago

Understood. I'll close this down until the next person has a TiddlyMap/TiddlyRemember/Anki/Python problem.