{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-jsx/src/components/halo/Connection.js"],"names":["pt","Set","Connection","nextId","constructor","target","targetProperty","source","sourceProperty","isEvent","activate","deactivate","activateEvent","activateAexpr","svalue","connectionFunction","sourceValue","code","myFunction","boundEval","drawConnectionLine","line","getGlobalPosition","showPath","setActive","shouldBeActive","destroy","getSource","getTarget","getAexpr","getSourceProperty","setSourceProperty","newProperty","getTargetProperty","setTargetProperty","getModifyingCodeString","setModifyingCodeString","newCode","allConnections","window","connectionString","connection"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;AACQA,Q,wBAAAA,E;;;;;;;;;;;;;;;;;;;;;;;AACR;;AAEA,8GAAwB,2GAAyB,mEAAIC,GAAJ,GAAjD;;AAEe,YAAMC,UAAN,CAAiB;;AAE9B,eAAOC,MAAP,GAAe;AACb,yCAAkB,kCAAmB,CAArC;AACA,oCAAO,IAAP;AACD;;AAEDC,oBAAYC,MAAZ,EAAoBC,cAApB,EAAoCC,MAApC,EAA4CC,cAA5C,EAA4DC,OAA5D,EAAqE;AAAA;;AACnE,iHAAU,sGAAWN,MAAX,EAAV;AACA,6IAA0B,IAA1B;;AAEA,uHAAcE,MAAd;AACA,+IAAsBC,cAAtB;AACA,uHAAcC,MAAd;AACA,+IAAsBC,cAAtB;AACA,0HAAeC,OAAf;AACA,uCAAgB,KAAhB;AACA,iDAA0B,OAA1B;AACD;;AAEDC,mBAAU;;AAER,yBAAG,IAAH,eAAiB;AAAA;;AACd,iBAAKC,UAAL;AACF;;AAED,yBAAG,IAAH,cAAgB;AAAA;;AACd,iBAAKC,aAAL;AACD,WAFD,MAGK;AAAA;;AACH,iBAAKC,aAAL;AACD;AACD,uCAAgB,IAAhB;AACD;;AAEDD,wBAAe;AACb,6EAA6B,OAA7B,EAAsC;AAAM,wFAA0B,uEAAwB,CAAxB,GAA0B,IAApD;AAAN,WAAtC;AACD;;AAEDC,wBAAe;AACb,iCAAU,OAAM;AAAM,qEAAY,IAAZ;AA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yB,iCAAwB;AACtB,4BAAO,IAAP;AACD;;AAEDC,+BAAuBC,OAAvB,EAA+B;AAAA;;AAC7B,sIAA0BA,OAA1B;AACD;;AAED,mBAAWC,cAAX,GAA2B;AACzB,8FAAOC,MAAP;AACD;;AAEDC,2BAAkB;AAChB,iBAAO,2BAAgB,IAAhB,OAAP;AACD;;AA1H6B;;yBAAXtC,U;;;;;;;;;;;;;;;;;AA8HrB;AACA;AACA;AACA,6IAA8BuC,cAAc;AAAA;;AACxC;AACA,uOAA2BvC,UAA3B;;AAEA;AACA,4OAAuBA,UAAvB;AACD,OANH","file":"Connection.js","sourcesContent":["\"enable aexpr\";\nimport {pt} from 'src/client/graphics.js';\n//import {uuid} from 'utils';\n\nwindow.allConnections = window.allConnections || new Set()\n\nexport default class Connection {\n  \n  static nextId(){\n    this._currentId = this._currentId || 1\n    return this._currentId++\n  }\n  \n  constructor(target, targetProperty, source, sourceProperty, isEvent) {\n    this.id = Connection.nextId();\n    window.allConnections.add(this);\n    \n    this.target = target;\n    this.targetProperty = targetProperty;\n    this.source = source;\n    this.sourceProperty = sourceProperty;\n    this.isEvent = isEvent;\n    this.isActive = false\n    this.valueModifyingCode = '+\"pt\"'\n  }\n  \n  activate(){\n    \n    if(this.isActive){\n       this.deactivate()\n    }\n    \n    if(this.isEvent){\n      this.activateEvent()\n    }\n    else {\n      this.activateAexpr()\n    }\n    this.isActive = true\n  }\n  \n  activateEvent(){\n    this.source.addEventListener('click', () => this.target.style.width = this.target.style.width*2+\"pt\")\n  }\n  \n  activateAexpr(){\n    this.ae = aexpr(() => this.source[this.sourceProperty]);\n    this.ae.onChange(svalue => this.connectionFunction(svalue));\n  }\n  \n  async connectionFunction(sourceValue){\n    /*let code = sourceValue + this.valueModifyingCode\n    let result = await code.boundEval()\n    this.target.style[this.targetProperty] = result*/\n    \n    let code = \"(target, sourceValue) => {target.style.height = sourceValue*1 + 'pt'}\"\n    let myFunction = await code.boundEval()\n    myFunction(this.target, sourceValue)\n  }\n  \n  drawConnectionLine(){\n    let line = [lively.getGlobalPosition(this.source), lively.getGlobalPosition(this.target)];\n    lively.showPath(line, \"rgba(80,180,80,1)\", true);\n  }\n  \n  setActive(shouldBeActive){\n    if(shouldBeActive){\n      this.activate()\n    }\n    else{\n       this.deactivate()\n    }\n  }\n  \n  deactivate(){\n    this.ae && this.ae.dispose()\n    this.isActive = false\n  }\n  \n  destroy(){\n    this.deactivate()\n    window.allConnections.delete(this)\n  }\n  \n  getSource(){\n    return this.source\n  }\n  \n  getTarget(){\n    return this.target\n  }\n  \n  getAexpr(){\n    return this.ae\n  }\n  \n  getSourceProperty(){\n    return this.sourceProperty\n  }\n  \n  setSourceProperty(newProperty){\n    this.sourceProperty = newProperty;\n    this.activate();\n  }\n  \n  getTargetProperty(){\n    return this.targetProperty\n  }\n  \n  setTargetProperty(newProperty){\n    this.targetProperty = newProperty;\n    this.activate();\n  }\n  \n  getModifyingCodeString(){\n    return this.valueModifyingCode\n  }\n  \n  setModifyingCodeString(newCode){\n    this.valueModifyingCode = newCode\n  }\n  \n  static get allConnections(){\n    return window.allConnections\n  }\n  \n  connectionString(){\n    return 'Connection ' + this.id\n  }\n  \n}\n\n// #UPDATE_INSTANCES\n// #TODO: idea: using a list of all object, we can make them become anew\n// go through all object reachable from window\nwindow.allConnections.forEach(connection => {\n    // evil live programming\n    connection.constructor === Connection\n\n    // we can fix this, so we can do live development again....\n    connection.__proto__ = Connection.prototype\n  });"]}