{"version":3,"sources":["https://lively-kernel.org/lively4/BP2019RH1/components/bp2019-group-widget.js"],"names":["Morph","assertListenerInterface","GroupAction","GroupWidget","initialize","name","isGlobal","axis","listeners","valuesByAttribute","attributeSelect","get","applyButton","addEventListener","_applyGrouping","addListener","listener","push","initializeWithData","attributes","_setSelectionOptions","data","_clearSelectOptions","forEach","attribute","appendChild","Option","select","options","length","remove","groupAction","_createGroupAction","applyAction","selectedGroupingAttribute","_getSelectedGroupAttribute","selectedIndex","value"],"mappings":";;;;;;AAAOA,W;;AACEC,6B,qDAAAA,uB;;AACAC,iB,kDAAAA,W;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEM,YAAMC,WAAN,SAA0BH,KAA1B,CAAgC;AAC7C,cAAMI,UAAN,GAAmB;AACjB,eAAKC,IAAL,GAAY,OAAZ;AACA,eAAKC,QAAL,GAAgB,KAAhB;AACA,eAAKC,IAAL,GAAY,GAAZ;;AAEA,eAAKC,SAAL,GAAiB,EAAjB;AACA,eAAKC,iBAAL,GAAyB,EAAzB;;AAEA,eAAKC,eAAL,GAAuB,KAAKC,GAAL,CAAS,kBAAT,CAAvB;AACA,eAAKC,WAAL,GAAmB,KAAKD,GAAL,CAAS,cAAT,CAAnB;;AAEA,eAAKC,WAAL,CAAiBC,gBAAjB,CAAkC,OAAlC,EAA2C,MAAM;AAC/C,iBAAKC,cAAL;AACD,WAFD;AAGD;;AAED;AACA;AACA;;AAEAC,oBAAYC,QAAZ,EAAsB;AACpBf,kCAAwBe,QAAxB;AACA,eAAKR,SAAL,CAAeS,IAAf,CAAoBD,QAApB;AACD;;AAEDE,2BAAmBC,UAAnB,EAA+B;AAC7B,eAAKC,oBAAL,CAA0BD,UAA1B;AACD;;AAED;AACA;AACA;;;AAGAC,6BAAqBC,IAArB,EAA2B;AACzB,eAAKC,mBAAL,CAAyB,KAAKZ,eAA9B;AACAW,eAAKE,OAAL,CAAeC,SAAD,IAAe;AAC3B,iBAAKd,eAAL,CAAqBe,WAArB,CAAiC,IAAIC,MAAJ,CAAWF,SAAX,CAAjC;AACD,WAFD;AAGD;;AAEAF,4BAAoBK,MAApB,EAA4B;AAC3B,iBAAMA,OAAOC,OAAP,CAAeC,MAAf,GAAwB,CAA9B,EAAiC;AAC/BF,mBAAOC,OAAP,CAAeE,MAAf,CAAsB,CAAtB;AACD;AACF;;AAEDhB,yBAAiB;AACf,cAAIiB,cAAc,KAAKC,kBAAL,EAAlB;AACA,eAAKxB,SAAL,CAAee,OAAf,CAAyBP,QAAD,IAAc;AACpCA,qBAASiB,WAAT,CAAqBF,WAArB;AACD,WAFD;AAGD;;AAEDC,6BAAoB;AAClB,cAAIE,4BAA4B,KAAKC,0BAAL,EAAhC;AACA,iBAAO,IAAIjC,WAAJ,CAAgBgC,yBAAhB,EAA2C,KAAK5B,QAAhD,EAA0D,KAAKC,IAA/D,EAAqE,CAAC,QAAD,CAArE,CAAP;AACD;;AAED4B,qCAA6B;AAC3B,iBAAO,KAAKzB,eAAL,CAAqBkB,OAArB,CAA6B,KAAKlB,eAAL,CAAqB0B,aAAlD,EAAiEC,KAAxE;AACD;;AA9D4C;;yBAA1BlC,W","file":"bp2019-group-widget.js","sourcesContent":["import Morph from 'src/components/widgets/lively-morph.js'\nimport { assertListenerInterface } from '../src/internal/individuals-as-points/common/interfaces.js'\nimport { GroupAction } from '../src/internal/individuals-as-points/common/actions.js'\n\nexport default class GroupWidget extends Morph {\n  async initialize() {\n    this.name = \"group\";\n    this.isGlobal = false;\n    this.axis = \"x\";\n    \n    this.listeners = [];\n    this.valuesByAttribute = {};\n    \n    this.attributeSelect = this.get(\"#attributeSelect\");\n    this.applyButton = this.get(\"#applyButton\");\n    \n    this.applyButton.addEventListener(\"click\", () => {\n      this._applyGrouping();\n    });\n  }\n  \n  // ------------------------------------------\n  // Public Methods\n  // ------------------------------------------\n  \n  addListener(listener) {\n    assertListenerInterface(listener);\n    this.listeners.push(listener);\n  }\n  \n  initializeWithData(attributes) {\n    this._setSelectionOptions(attributes);\n  }\n   \n  // ------------------------------------------\n  // Private Methods\n  // ------------------------------------------\n  \n  \n  _setSelectionOptions(data) {\n    this._clearSelectOptions(this.attributeSelect);\n    data.forEach( (attribute) => {\n      this.attributeSelect.appendChild(new Option(attribute));\n    });\n  }\n  \n   _clearSelectOptions(select) {\n    while(select.options.length > 0) {\n      select.options.remove(0);\n    }\n  }\n  \n  _applyGrouping() {\n    let groupAction = this._createGroupAction();\n    this.listeners.forEach( (listener) => {\n      listener.applyAction(groupAction);\n    });\n  }\n  \n  _createGroupAction(){\n    let selectedGroupingAttribute = this._getSelectedGroupAttribute();\n    return new GroupAction(selectedGroupingAttribute, this.isGlobal, this.axis, [\"themes\"]);\n  }\n  \n  _getSelectedGroupAttribute() {\n    return this.attributeSelect.options[this.attributeSelect.selectedIndex].value\n  }\n  \n \n}"]}