diff --git a/web/lib/editor.js b/web/lib/editor.js index f4567c7..be55460 100644 --- a/web/lib/editor.js +++ b/web/lib/editor.js @@ -1123,34 +1123,6 @@ } } - class LocalStorage { - constructor(id) { - this.id = id; - } - - set(value) { - if(!this.id) { - return; - } - try { - window.localStorage.setItem(this.id, value); - } catch(ignore) { - // Ignore - } - } - - get() { - if(!this.id) { - return ''; - } - try { - return window.localStorage.getItem(this.id) || ''; - } catch(e) { - return ''; - } - } - } - function toCappedFixed(v, cap) { const s = v.toString(); const p = s.indexOf('.'); @@ -1219,6 +1191,20 @@ } } + class VoidStorage { + constructor() { + this.value = ''; + } + + set(value) { + this.value = value; + } + + get() { + return this.value; + } + } + const DELAY_AGENTCHANGE = 500; const DELAY_STAGECHANGE = 250; const PNG_RESOLUTION = 4; @@ -1252,15 +1238,15 @@ constructor({ sequenceDiagram, defaultCode = '', - localStorage = '', library = [], links = [], require = null, + storage = new VoidStorage(), touchUI = false, }) { this.diagram = sequenceDiagram; this.defaultCode = defaultCode; - this.localStorage = new LocalStorage(localStorage); + this.storage = storage; this.library = library; this.links = links; this.minScale = 1.5; @@ -1558,7 +1544,7 @@ this.code = new CodeEditor(this.dom, container, { mode: 'sequence', require: this.require, - value: this.localStorage.get() || this.defaultCode, + value: this.storage.get() || this.defaultCode, }); this.code @@ -1751,7 +1737,7 @@ update(immediate = true) { this._hideURLBuilder(); const src = this.code.value(); - this.localStorage.set(src); + this.storage.set(src); let sequence = null; try { sequence = this.diagram.process(src); @@ -1837,6 +1823,34 @@ } } + class LocalStorage { + constructor(id) { + this.id = id; + } + + set(value) { + if(!this.id) { + return; + } + try { + window.localStorage.setItem(this.id, value); + } catch(ignore) { + // Ignore + } + } + + get() { + if(!this.id) { + return ''; + } + try { + return window.localStorage.getItem(this.id) || ''; + } catch(e) { + return ''; + } + } + } + var SequenceDiagram = window.SequenceDiagram; const require = window.requirejs; @@ -1909,13 +1923,15 @@ }); } + const storage = new LocalStorage('src'); + const ui = new Interface({ defaultCode, library: ComponentsLibrary, links, - localStorage: 'src', require, sequenceDiagram: new SequenceDiagram(), + storage, touchUI: ('ontouchstart' in window), }); loader.parentNode.removeChild(loader); diff --git a/web/lib/editor.min.js b/web/lib/editor.min.js index 7525604..cae9a93 100644 --- a/web/lib/editor.min.js +++ b/web/lib/editor.min.js @@ -1 +1 @@ -!function(){"use strict";function e(e){return null===e?null:e.element?e.element:e}function t(e){return e.length>0&&"\n"!==e.charAt(e.length-1)?e+"\n":e}function i(e,t){let i=0,s=0;for(;;){const n=e.indexOf("\n",i)+1;if(ti.line||e.line===i.line&&e.ch>i.ch)}function n(e,t){const i=e.toString(),s=i.indexOf(".");return-1===s||i.length-s-1<=t?i:e.toFixed(t)}function r(e=null){return null!==e&&!Number.isNaN(e)}var o=[{code:"{Agent1} -> {Agent2}: {Message}",title:"Simple arrow (synchronous)"},{code:"{Agent1} --\x3e {Agent2}: {Message}",title:"Arrow with dotted line (response)"},{code:"{Agent1} ->> {Agent2}: {Message}",title:"Open arrow (asynchronous)"},{code:"{Agent1} -x {Agent2}: {Message}",title:"Lost message"},{code:"{Agent1} ~> {Agent2}: {Message}",title:"Wavy line"},{code:"{Agent1} -> {Agent1}: {Message}",title:"Self-connection"},{code:"{Agent1} -> ...{id}\n...{id} -> {Agent2}: {Message}",preview:"begin A, B\nA -> ...x\n...x -> B: Message",title:"Asynchronous message"},{code:"* -> {Agent1}: {Message}",title:"Found message"},{code:"{Agent1} -> {Agent2}\n& {Agent1} -> {Agent3}: {Broadcast}",title:"Broadcast message"},{code:"{Agent1} -> +{Agent2}: {Request}\n{Agent1} <-- -{Agent2}: {Response}",title:"Request/response pair"},{code:"{Agent1} -> *{Agent2}: {Request}\n{Agent1} <-- !{Agent2}: {Response}",title:"Inline agent creation / destruction"},{code:"{Agent1} -> {Agent2}: {Request}\n{Agent1} <-- {Agent2}: {Response}\nend {Agent2}",preview:"begin A\n::\nA -> B: Request\nA <-- B: Response\nend B",title:"Agent creation / destruction"},{code:'autolabel "[]