{"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","addEventListener","_applyGrouping","addListener","listener","push","initializeWithData","attributes","_setSelectionOptions","_clearSelectOptions","appendChild","Option","forEach","attribute","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,eAAKD,eAAL,CAAqBE,gBAArB,CAAsC,QAAtC,EAAgD,MAAM;AACpD,iBAAKC,cAAL;AACD,WAFD;AAGD;;AAED;AACA;AACA;;AAEAC,oBAAYC,QAAZ,EAAsB;AACpBd,kCAAwBc,QAAxB;AACA,eAAKP,SAAL,CAAeQ,IAAf,CAAoBD,QAApB;AACD;;AAEDE,2BAAmBC,UAAnB,EAA+B;AAC7B,eAAKC,oBAAL,CAA0BD,UAA1B;AACD;;AAED;AACA;AACA;;;AAGAC,6BAAqBD,UAArB,EAAiC;AAC/B,eAAKE,mBAAL,CAAyB,KAAKV,eAA9B;AACA,eAAKA,eAAL,CAAqBW,WAArB,CAAiC,IAAIC,MAAJ,CAAW,MAAX,CAAjC;AACAJ,qBAAWK,OAAX,CAAmBC,aAAa;AAC9B,iBAAKd,eAAL,CAAqBW,WAArB,CAAiC,IAAIC,MAAJ,CAAWE,SAAX,CAAjC;AACD,WAFD;AAGD;;AAEAJ,4BAAoBK,MAApB,EAA4B;AAC3B,iBAAMA,OAAOC,OAAP,CAAeC,MAAf,GAAwB,CAA9B,EAAiC;AAC/BF,mBAAOC,OAAP,CAAeE,MAAf,CAAsB,CAAtB;AACD;AACF;;AAEDf,yBAAiB;AACf;AACA,cAAIgB,cAAc,KAAKC,kBAAL,EAAlB;AACA,eAAKtB,SAAL,CAAee,OAAf,CAAyBR,QAAD,IAAc;AACpCA,qBAASgB,WAAT,CAAqBF,WAArB;AACD,WAFD;AAGD;;AAEDC,6BAAoB;AAClB,cAAIE,4BAA4B,KAAKC,0BAAL,EAAhC;AACA,iBAAO,IAAI/B,WAAJ,CAAgB8B,yBAAhB,EAA2C,KAAK1B,QAAhD,EAA0D,KAAKC,IAA/D,EAAqE,CAAC,QAAD,CAArE,CAAP;AACD;;AAED0B,qCAA6B;AAC3B,iBAAO,KAAKvB,eAAL,CAAqBgB,OAArB,CAA6B,KAAKhB,eAAL,CAAqBwB,aAAlD,EAAiEC,KAAxE;AACD;;AA9D4C;;yBAA1BhC,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.attributeSelect.addEventListener(\"change\", () => {\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(attributes) {\n    this._clearSelectOptions(this.attributeSelect);\n    this.attributeSelect.appendChild(new Option(\"none\"))\n    attributes.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    debugger\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}"]}