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OAEjCC,EAAkB,kBAClBC,EAAmBJ,EAAoBK,IACvCC,EAAmBN,EAAoBO,UAAUJ,GAIrDF,EAAerE,OAAQ,UAAU,SAAU4E,GACzCJ,EAAiBtD,KAAM,CACrB2D,KAAMN,EACNO,OAAQX,EAASS,GACjBG,MAAO,GAIX,IAAG,WACD,IAGIC,EAHAC,EAAQP,EAAiBxD,MACzB4D,EAASG,EAAMH,OACfC,EAAQE,EAAMF,MAElB,OAAIA,GAASD,EAAO9F,OAAesF,OAAuB3E,GAAW,IACrEqF,EAAQd,EAAOY,EAAQC,GACvBE,EAAMF,OAASC,EAAMhG,OACdsF,EAAuBU,GAAO,GACvC,G","sources":["webpack://mucklet-client/./node_modules/modapp-base-component/es/Html.js","webpack://mucklet-client/./node_modules/modapp-base-component/es/Transition.js","webpack://mucklet-client/./node_modules/modapp-resource/es/Collection.js","webpack://mucklet-client/./node_modules/modapp-resource/es/CollectionWrapper.js","webpack://mucklet-client/./node_modules/modapp-resource/es/CollectionToModel.js","webpack://mucklet-client/./node_modules/modapp-resource/es/ModelToCollection.js","webpack://mucklet-client/./node_modules/core-js/modules/es.string.iterator.js"],"sourcesContent":["function _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\nfunction _toPropertyKey(arg) { var key = _toPrimitive(arg, \"string\"); return _typeof(key) === \"symbol\" ? key : String(key); }\nfunction _toPrimitive(input, hint) { if (_typeof(input) !== \"object\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \"default\"); if (_typeof(res) !== \"object\") return res; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (hint === \"string\" ? String : Number)(input); }\nfunction _get() { if (typeof Reflect !== \"undefined\" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }\nfunction _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, \"prototype\", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } else if (call !== void 0) { throw new TypeError(\"Derived constructors may only return object or undefined\"); } return _assertThisInitialized(self); }\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\nimport { anim } from 'modapp-utils';\nimport RootElem from './RootElem';\nimport { translate, onLocaleUpdate, offLocaleUpdate } from './utils/l10n';\n\n/**\n * A html component\n */\nvar Html = /*#__PURE__*/function (_RootElem) {\n  _inherits(Html, _RootElem);\n  var _super = _createSuper(Html);\n  /**\n   * Creates an instance of Html\n   * @param {string|LocaleString} html HTML string\n   * @param {object} [opt] Optional parameters.\n   * @param {string} [opt.tagName] Tag name (eg. 'span') for the element. Defaults to 'div'.\n   * @param {string} [opt.className] Class name\n   * @param {object} [opt.attributes] Key/value attributes object\n   * @param {object} [opt.events] Key/value events object, where the key is the event name, and value is the callback.\n   */\n  function Html(html, opt) {\n    var _this;\n    _classCallCheck(this, Html);\n    opt = Object.assign({\n      tagName: 'div'\n    }, opt);\n    _this = _super.call(this, opt.tagName, opt);\n    _this.html = html || \"\";\n    _this.animId = null;\n    _this.rendered = null;\n\n    // Bind callbacks\n    _this._handleChange = _this._handleChange.bind(_assertThisInitialized(_this));\n    return _this;\n  }\n\n  /**\n   * Sets the html\n   * @param {string} html HTML string\n   * @returns {this}\n   */\n  _createClass(Html, [{\n    key: \"setHtml\",\n    value: function setHtml(html) {\n      html = html || \"\";\n      if (this.html !== html) {\n        var tmp = this.html;\n        this.html = html;\n        if (_get(_getPrototypeOf(Html.prototype), \"getElement\", this).call(this)) {\n          offLocaleUpdate(tmp);\n          this._handleChange();\n          onLocaleUpdate(this.html);\n        }\n      }\n      return this;\n    }\n  }, {\n    key: \"render\",\n    value: function render(el) {\n      var nodeEl = _get(_getPrototypeOf(Html.prototype), \"render\", this).call(this, el);\n      this.rendered = translate(this.html);\n      nodeEl.innerHTML = this.rendered;\n      onLocaleUpdate(this.html, this._handleChange);\n      return nodeEl;\n    }\n  }, {\n    key: \"unrender\",\n    value: function unrender() {\n      offLocaleUpdate(this.html, this._handleChange);\n      anim.stop(this.animId);\n      _get(_getPrototypeOf(Html.prototype), \"unrender\", this).call(this);\n      this.rendered = null;\n    }\n  }, {\n    key: \"_handleChange\",\n    value: function _handleChange() {\n      var _this2 = this;\n      var el = _get(_getPrototypeOf(Html.prototype), \"getElement\", this).call(this);\n      if (!el) {\n        return;\n      }\n      anim.stop(this.animId);\n      var next = translate(this.html);\n      if (this.rendered === next) {\n        this.animId = anim.fade(el, 1);\n        return;\n      }\n      this.animId = anim.fade(el, 0, {\n        callback: function callback() {\n          var el = _get(_getPrototypeOf(Html.prototype), \"getElement\", _this2).call(_this2);\n          if (!el) {\n            return;\n          }\n          _this2.rendered = next;\n          el.innerHTML = next;\n          _this2.animId = anim.fade(el, 1);\n        }\n      });\n    }\n  }]);\n  return Html;\n}(RootElem);\nexport default Html;","function _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\nfunction _toPropertyKey(arg) { var key = _toPrimitive(arg, \"string\"); return _typeof(key) === \"symbol\" ? key : String(key); }\nfunction _toPrimitive(input, hint) { if (_typeof(input) !== \"object\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \"default\"); if (_typeof(res) !== \"object\") return res; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (hint === \"string\" ? String : Number)(input); }\nimport { anim, elem } from 'modapp-utils';\n\n/**\n * A component used for doing transition between one component to another.\n * @module component/Transition\n */\nvar Transition = /*#__PURE__*/function () {\n  /**\n   * Creates a Transition\n   * @constructor\n   * @alias module:component/Transition\n   * @param {object} [opt] Optional parameters\n   * @param {string} [opt.className] Classname.\n   * @param {number} [opt.distance] Swipe distance in pixels. Defaults to 64.\n   * @param {number} [opt.duration] Swipe duration in milliseconds. Defaults to 150.\n   * @param {string} [opt.mode] Transition container mode. Defaults to 'flex'.\n   */\n  function Transition() {\n    var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n    _classCallCheck(this, Transition);\n    this.opt = Object.assign({\n      mode: 'flex'\n    }, opt);\n    this.div = null;\n    this.animId = null;\n    this.current = null;\n    this.rendered = null;\n    this.contDiv = null;\n  }\n  _createClass(Transition, [{\n    key: \"id\",\n    get: function get() {\n      return this.current ? this.current.id : undefined;\n    }\n  }, {\n    key: \"render\",\n    value: function render(el) {\n      if (this.div) throw \"Component already rendered\";\n      this.div = elem.create('div', {\n        className: this.opt.className,\n        attributes: {\n          style: 'position: relative; overflow: hidden;' + (this.opt.mode == 'flex' ? ' flex: 1 1 0px;' : '')\n        }\n      });\n      elem.append(el, this.div);\n      this._renderComponent();\n      return this.div;\n    }\n  }, {\n    key: \"unrender\",\n    value: function unrender() {\n      if (!this.div) return;\n      anim.stop(this.animId);\n      this.animId = null;\n      this._unrenderComponent();\n      elem.remove(this.div);\n      this.div = null;\n    }\n\n    /**\n     * Get the current component\n     * @returns {object}\n     */\n  }, {\n    key: \"getComponent\",\n    value: function getComponent() {\n      return this.current;\n    }\n\n    /**\n     * Fade to a new component\n     * @param {object} component The component to fade to\n     * @returns {this}\n     */\n  }, {\n    key: \"fade\",\n    value: function fade(component) {\n      this._setComponent(component, 0);\n      return this;\n    }\n\n    /**\n     * Slide left to a new component\n     * @param {object} component The component to slide to\n     * @returns {this}\n     */\n  }, {\n    key: \"slideLeft\",\n    value: function slideLeft(component) {\n      this._setComponent(component, -1);\n      return this;\n    }\n\n    /**\n     * Slide right to a new component\n     * @param {object} component The component to slide to\n     * @returns {this}\n     */\n  }, {\n    key: \"slideRight\",\n    value: function slideRight(component) {\n      this._setComponent(component, 1);\n      return this;\n    }\n\n    /**\n     * Set a new component\n     * @param {object} component The component to use\n     * @returns {this}\n     */\n  }, {\n    key: \"set\",\n    value: function set(component) {\n      component = component || null;\n\n      // Is the component already current?\n      if (this._isEqual(this.current, component)) return this;\n      this.current = component;\n      if (!this.div) return this;\n      this.animId = anim.stop(this.animId);\n\n      // Is the component already rendered?\n      if (this._isEqual(this.rendered, component)) {\n        this.contDiv.style.opacity = '';\n        this.contDiv.style.left = '';\n      } else {\n        // Unrender previously rendered component\n        this._unrenderComponent();\n        // Render the current component\n        this._renderComponent();\n      }\n      return this;\n    }\n  }, {\n    key: \"_setComponent\",\n    value: function _setComponent(component, direction) {\n      var _this = this;\n      component = component || null;\n\n      // Is the component already current?\n      if (this._isEqual(this.current, component)) return;\n      this.current = component;\n      if (!this.div) return;\n      this.animId = anim.stop(this.animId);\n\n      // Check if the rendered page matches the one we want\n      if (this._isEqual(this.rendered, this.current)) {\n        // Swipe it back in from current state\n        this.animId = anim.swipeIn(this.contDiv, direction, {\n          reset: false,\n          callback: function callback() {\n            return _this.animId = null;\n          },\n          duration: this.opt.duration,\n          distance: this.opt.distance\n        });\n        return;\n      }\n\n      // No rendered component. We can just render the new one.\n      if (!this.rendered) {\n        this._renderComponent(direction);\n        return;\n      }\n\n      // Unrender the currently rendered tab\n      this.animId = anim.swipeOut(this.contDiv, direction, {\n        reset: false,\n        callback: function callback() {\n          _this._unrenderComponent();\n          _this._renderComponent(direction);\n        },\n        duration: this.opt.duration,\n        distance: this.opt.distance\n      });\n    }\n  }, {\n    key: \"_isEqual\",\n    value: function _isEqual(componentA, componentB) {\n      if (componentA === componentB) return true;\n      if (!componentA || !componentB) return false;\n      if (!componentA.hasOwnProperty('id') || !componentB.hasOwnProperty('id')) return false;\n      return componentA.id === componentB.id;\n    }\n  }, {\n    key: \"_unrenderComponent\",\n    value: function _unrenderComponent() {\n      if (!this.rendered) return;\n      if (this.rendered.unrender) {\n        this.rendered.unrender();\n      }\n      this.contDiv = null;\n      this.rendered = null;\n      elem.empty(this.div);\n    }\n  }, {\n    key: \"_renderComponent\",\n    value: function _renderComponent(direction) {\n      var _this2 = this;\n      if (!this.current) return;\n\n      // Create container div in which content will be rendered\n      var div = elem.append(this.div, elem.create('div', {\n        attributes: {\n          style: 'width: 100%; height: 100%; position: relative; overflow: auto;'\n        }\n      }));\n      this.current.render(div);\n      this.rendered = this.current;\n      this.contDiv = div;\n      if (typeof direction == 'number') {\n        this.animId = anim.swipeIn(this.contDiv, direction, {\n          callback: function callback() {\n            return _this2.animId = null;\n          },\n          duration: this.opt.duration,\n          distance: this.opt.distance\n        });\n      }\n    }\n  }]);\n  return Transition;\n}();\nexport default Transition;","function _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it[\"return\"] != null) it[\"return\"](); } finally { if (didErr) throw err; } } }; }\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\nfunction _toPropertyKey(arg) { var key = _toPrimitive(arg, \"string\"); return _typeof(key) === \"symbol\" ? key : String(key); }\nfunction _toPrimitive(input, hint) { if (_typeof(input) !== \"object\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \"default\"); if (_typeof(res) !== \"object\") return res; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (hint === \"string\" ? String : Number)(input); }\nimport SortedMap from './SortedMap';\nimport eventBus from 'modapp-eventbus';\nimport { obj } from 'modapp-utils';\n\n/**\n * Collection is a generic data collection.\n * @implements {module:modapp~Collection}\n */\nvar Collection = /*#__PURE__*/function (_Symbol$iterator) {\n  /**\n   * Creates a Collection instance\n   * @param {object} [opt] Optional settings.\n   * @param {Array.<object>} [opt.data] Collection data array.\n   * @param {function} [opt.compare] Compare function for sort order. Defaults to insert order.\n   * @param {function} [opt.modelFactory] Model factory function. Defaults to using added objects as is.\n   * @param {function} [opt.idAttribute] Id attribute callback function. Defaults to returning the object.id property.\n   * @param {string} [opt.namespace] Event bus namespace. Defaults to 'collection'.\n   * @param {module:modapp~EventBus} [opt.eventBus] Event bus.\n   */\n  function Collection(opt) {\n    _classCallCheck(this, Collection);\n    opt = obj.copy(opt, {\n      compare: {\n        type: '?function'\n      },\n      modelFactory: {\n        type: '?function'\n      },\n      idAttribute: {\n        type: '?function',\n        \"default\": function _default(m) {\n          return m.id;\n        }\n      },\n      data: {\n        type: '?object'\n      },\n      namespace: {\n        type: 'string',\n        \"default\": 'collection'\n      },\n      eventBus: {\n        type: 'object',\n        \"default\": eventBus\n      }\n    });\n    this._modelFactory = opt.modelFactory;\n    this._idAttribute = opt.idAttribute;\n    this._namespace = opt.namespace;\n    this._eventBus = opt.eventBus;\n    this._map = opt.idAttribute ? new SortedMap(opt.compare) : [];\n\n    // Populate map with initial data\n    if (opt.data) {\n      var _iterator = _createForOfIteratorHelper(opt.data),\n        _step;\n      try {\n        for (_iterator.s(); !(_step = _iterator.n()).done;) {\n          var item = _step.value;\n          this._addItem(item, false);\n        }\n      } catch (err) {\n        _iterator.e(err);\n      } finally {\n        _iterator.f();\n      }\n    }\n  }\n\n  /**\n   * Attach an event handler function for one or more instance events.\n   * Available events are 'add', 'remove', and 'move'.\n   * @param {?string} events One or more space-separated events. Null means any event.\n   * @param {EventBus~eventCallback} [handler] A function to execute when the event is emitted.\n   * @returns {this}\n   */\n  _createClass(Collection, [{\n    key: \"on\",\n    value: function on(events, handler) {\n      this._eventBus.on(this, events, handler, this._namespace);\n      return this;\n    }\n\n    /**\n    * Remove an instance event handler.\n    * Available events are 'add', 'remove', and 'move'.\n    * @param {?string} events One or more space-separated events. Null means any event.\n    * @param {EventBus~eventCallback} [handler] An option handler function. The handler will only be remove if it is the same handler.\n    * @returns {this}\n    */\n  }, {\n    key: \"off\",\n    value: function off(events, handler) {\n      this._eventBus.off(this, events, handler, this._namespace);\n      return this;\n    }\n\n    /**\n     * Add an item to the collection.\n     * @param {*} item Item to add\n     * @param {idx} [idx] Index value of where to insert the item. Ignored if the collection has a compare function.\n     * @returns {number} Index value of where the item was inserted in the list\n     */\n  }, {\n    key: \"add\",\n    value: function add(item, idx) {\n      return this._addItem(item, true, idx);\n    }\n\n    /**\n     * Remove an item from the collection.\n     * @param {string} id Id of the item.\n     * @returns {number} Order index of the item before removal. -1 if the item id doesn't exist\n     */\n  }, {\n    key: \"remove\",\n    value: function remove(id) {\n      if (!this._idAttribute) {\n        throw new Error(\"No id attribute set.\");\n      }\n      var item = this.get(id);\n      if (!item) return -1;\n      var idx = this._map.remove(id);\n\n      // Emit event if an item was removed\n      if (idx >= 0) {\n        this._eventBus.emit(this, this._namespace + '.remove', {\n          item: item,\n          idx: idx\n        });\n      }\n      return idx;\n    }\n\n    /**\n     * Remove an item at a given index.\n     * @param {*} idx Index value of the item to remove.\n     * @returns {*} Removed item.\n     */\n  }, {\n    key: \"removeAtIndex\",\n    value: function removeAtIndex(idx) {\n      if (idx < 0 || idx >= this._map.length) {\n        throw new Error(\"Index out of bounds.\");\n      }\n      var item = this._map[idx];\n      if (this._idAttribute) {\n        this._map.remove(this._idAttribute(item));\n      } else {\n        this._map.splice(idx, 1);\n      }\n      this._eventBus.emit(this, this._namespace + '.remove', {\n        item: item,\n        idx: idx\n      });\n      return item;\n    }\n\n    /**\n     * Get an item from the collection by id\n     * @param {string} id Id of the item\n     * @returns {*} Stored item. Undefined if key doesn't exist\n     */\n  }, {\n    key: \"get\",\n    value: function get(id) {\n      if (!this._idAttribute) {\n        throw new Error(\"No id attribute set.\");\n      }\n      return this._map.get(id);\n    }\n\n    /**\n     * Move an item within the collection.\n     * Invalid if the collection has a compare function.\n     * @param {string} id Id of the item\n     * @param {*} idx Index to move the item to\n     * returns {number} Order index of the item before moving. -1 if the item id doesn't exist.\n     */\n  }, {\n    key: \"move\",\n    value: function move(id, idx) {\n      if (this.compare) throw \"Cannot use move in list with compare\";\n      throw \"Not implemented\";\n    }\n\n    /**\n     * Retrieves the order index of an item.\n     * @param {string|object} item Item or id of the item\n     * @returns {number} Order index of the item. -1 if the item id doesn't exist.\n     */\n  }, {\n    key: \"indexOf\",\n    value: function indexOf(item) {\n      if (typeof item === 'string') {\n        item = this._map.get(item);\n        if (!item) {\n          return -1;\n        }\n      }\n      return this._map.indexOf(item);\n    }\n  }, {\n    key: \"atIndex\",\n    value: function atIndex(idx) {\n      return this._map[idx];\n    }\n  }, {\n    key: \"length\",\n    get: function get() {\n      return this._map.length;\n    }\n  }, {\n    key: \"toArray\",\n    value: function toArray() {\n      return this._map.slice();\n    }\n  }, {\n    key: \"_addItem\",\n    value: function _addItem(item, emit, idx) {\n      if (this._modelFactory) {\n        item = this._modelFactory(item);\n      }\n      if (this._idAttribute) {\n        idx = this._map.add(this._idAttribute(item), item, idx);\n      } else {\n        if (typeof idx != 'number') {\n          idx = this._map.length;\n        } else if (idx < 0 || idx > this._map.length) {\n          throw new Error(\"Index out of bounds.\");\n        }\n        this._map.splice(idx, 0, item);\n      }\n      if (emit) {\n        this._eventBus.emit(this, this._namespace + '.add', {\n          item: item,\n          idx: idx\n        });\n      }\n      return idx;\n    }\n  }, {\n    key: _Symbol$iterator,\n    value: function value() {\n      var i = 0,\n        a = this._map,\n        l = a.length;\n      return {\n        next: function next() {\n          return {\n            value: a[i++],\n            done: i > l\n          };\n        }\n      };\n    }\n  }]);\n  return Collection;\n}(Symbol.iterator);\nexport default Collection;\nexport function sortOrderCompare(a, b) {\n  return a.sortOrder - b.sortOrder;\n}\n;","function _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it[\"return\"] != null) it[\"return\"](); } finally { if (didErr) throw err; } } }; }\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\nfunction _toPropertyKey(arg) { var key = _toPrimitive(arg, \"string\"); return _typeof(key) === \"symbol\" ? key : String(key); }\nfunction _toPrimitive(input, hint) { if (_typeof(input) !== \"object\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \"default\"); if (_typeof(res) !== \"object\") return res; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (hint === \"string\" ? String : Number)(input); }\nimport eventBus from 'modapp-eventbus';\nimport { array, obj } from 'modapp-utils';\nimport { toArray, patchDiff } from './utils';\n\n/**\n * A wrapper for a {@link module:modapp~Collection}, exposing the underlaying\n * data but can provide a different sort order, mapping of items, filtering of\n * items, or slicing of the collection. It will transparently propagate emitted\n * add and remove events.\n * @implements {module:modapp~Collection}\n */\nvar CollectionWrapper = /*#__PURE__*/function (_Symbol$iterator) {\n  /**\n   * Creates an CollectionWrapper instance.\n   * @param {object} collection Collection object to wrap.\n   * @param {object} [opt] Optional parameters.\n   * @param {function} [opt.map] Model map callback. If not provided, item objects will be stored as is.\n   * @param {function} [opt.filter] Model filter callback. Parameter is a item of the underlying collection.\n   * @param {number} [opt.begin] Zero-based index at which to begin extraction, similar to Array.slice.\n   * @param {?number} [opt.end] Zero-based index before which to end extraction, similar to Array.slice. Null extracts until the end of the collection.\n   * @param {function} [opt.compare] Sort compare function.\n   * @param {string} [opt.namespace] Event bus namespace. Defaults to 'collectionWrapper'.\n   * @param {module:modapp~EventBus} [opt.eventBus] Event bus.\n   * @param {?number} [opt.autoDispose] Milliseconds until dispose is called after the number of listeners reaches zero. Default is never.\n   */\n  function CollectionWrapper(collection) {\n    var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n    _classCallCheck(this, CollectionWrapper);\n    this._collection = collection || null;\n    obj.update(this, opt, {\n      map: {\n        type: '?function',\n        property: '_map'\n      },\n      filter: {\n        type: '?function',\n        property: '_filter'\n      },\n      begin: {\n        type: 'number',\n        \"default\": 0,\n        property: '_begin'\n      },\n      end: {\n        type: '?number',\n        property: '_end'\n      },\n      compare: {\n        type: '?function',\n        property: '_compare'\n      },\n      namespace: {\n        type: 'string',\n        \"default\": 'collectionWrapper',\n        property: '_namespace'\n      },\n      eventBus: {\n        type: 'object',\n        \"default\": eventBus,\n        property: '_eventBus'\n      },\n      autoDispose: {\n        type: '?number',\n        property: '_autoDispose'\n      }\n    });\n    if (this._map) {\n      this._weakMap = new WeakMap();\n    }\n\n    // Bind callbacks\n    this._onAdd = this._onAdd.bind(this);\n    this._onRemove = this._onRemove.bind(this);\n    this._listen = !!(this._filter || this._map || this._compare);\n    if (this._listen) {\n      this._onChange = this._onChange.bind(this);\n    }\n    this._onCount = 0;\n    this._timeout = null;\n    this._disposed = false;\n    this._initList();\n    this._setEventListeners(true);\n    this._checkAutoDispose(0);\n  }\n  _createClass(CollectionWrapper, [{\n    key: \"_initList\",\n    value: function _initList() {\n      var _this = this;\n      this._list = [];\n      this._len = 0;\n      if (!this._collection) {\n        return;\n      }\n      var getModel = this._map ? function (item) {\n        var m = _this._map(item, _this._collection);\n        _this._weakMap.set(item, m);\n        return m;\n      } : function (item) {\n        return item;\n      };\n      var add = this._filter ? function (item, m) {\n        var c = _this._wrapModel(m, item);\n        if (c.f) _this._len++;\n        _this._list.push(c);\n      } : function (item, m) {\n        _this._list.push(_this._wrapModel(m, item));\n        _this._len++;\n      };\n      var _iterator = _createForOfIteratorHelper(this._collection),\n        _step;\n      try {\n        for (_iterator.s(); !(_step = _iterator.n()).done;) {\n          var item = _step.value;\n          var m = getModel(item);\n          if (this._listen && item.on) {\n            item.on('change', this._onChange);\n          }\n          add(item, m);\n        }\n      } catch (err) {\n        _iterator.e(err);\n      } finally {\n        _iterator.f();\n      }\n      if (this._compare) {\n        this._list.sort(function (a, b) {\n          return _this._compare(a.m, b.m);\n        });\n      }\n    }\n\n    /**\n     * Length of the collection.\n     */\n  }, {\n    key: \"length\",\n    get: function get() {\n      var s = this._beginIdx();\n      var e = this._endIdx();\n      return s > e ? 0 : e - s;\n    }\n\n    /**\n     * Returns the wrapped collection.\n     * @returns {object}\n     */\n  }, {\n    key: \"getCollection\",\n    value: function getCollection() {\n      return this.collection;\n    }\n  }, {\n    key: \"toJSON\",\n    value: function toJSON() {\n      return this._array().map(function (m) {\n        return m.toJSON ? m.toJSON() : m;\n      });\n    }\n\n    /**\n     * Returns an array of the collection items.\n     * @returns {Array.<*>} An array of items.\n     */\n  }, {\n    key: \"toArray\",\n    value: function toArray() {\n      return this._array();\n    }\n\n    /**\n     * Creates an array filled with all array elements that pass a test.\n     *\n     * Short hand for CollectionWrapper.toArray().filter(filter).\n     * @param {function} filter Filter predicate function.\n     * @returns {Array} A new array with the elements that pass the test.\n     */\n  }, {\n    key: \"filter\",\n    value: function filter(_filter) {\n      return this._array().filter(_filter);\n    }\n\n    /**\n     * Creates a new array populated with the results of calling a provided\n     * function on every element in the calling array.\n     *\n     * Short hand for CollectionWrapper.toArray().map(callback)\n     * @param {function} callback Function that is called for every item of the collection.\n     * @returns {Array} A new array with each element being the result of the callback function.\n     */\n  }, {\n    key: \"map\",\n    value: function map(callback) {\n      return this._array().map(callback);\n    }\n  }, {\n    key: \"setCollection\",\n    value: function setCollection(collection) {\n      var _this2 = this;\n      collection = collection || null;\n      if (this._collection === collection) {\n        return;\n      }\n      var oldList = toArray(this._collection);\n      var newList = toArray(collection);\n      this._setEventListeners(false);\n      this._collection = collection || null;\n      this._setEventListeners(true);\n      patchDiff(oldList, newList, function (item, n, idx) {\n        return _this2._onAdd({\n          item: item,\n          idx: idx\n        });\n      }, function (item, m, idx) {\n        return _this2._onRemove({\n          item: item,\n          idx: idx\n        });\n      });\n    }\n\n    /**\n     * Attach an event handler function for one or more session events.\n     * @param {?string} events One or more space-separated events. Null means any event.\n     * @param {Event~eventCallback} handler A function to execute when the event is emitted.\n     */\n  }, {\n    key: \"on\",\n    value: function on(events, handler) {\n      this._checkAutoDispose(1);\n      this._eventBus.on(this, events, handler, this._namespace);\n    }\n\n    /**\n     * Remove an event handler.\n     * @param {?string} events One or more space-separated events. Null means any event.\n     * @param {Event~eventCallback} [handler] An option handler function. The handler will only be remove if it is the same handler.\n     */\n  }, {\n    key: \"off\",\n    value: function off(events, handler) {\n      this._checkAutoDispose(-1);\n      this._eventBus.off(this, events, handler, this._namespace);\n    }\n\n    /**\n     * Returns the item at a given index, or undefined if the index is out of bounds.\n     * @param {number} idx Zero-based index.\n     * @returns {*} Item located at the given index.\n     */\n  }, {\n    key: \"atIndex\",\n    value: function atIndex(idx) {\n      var s = this._beginIdx();\n      var e = this._endIdx();\n      // Check out of bounds\n      if (idx < 0 || idx >= e - s) return undefined;\n\n      // Set idx to the filtered internal index\n      idx += s;\n      if (this._filter) {\n        // Find the idx:th item\n        var _iterator2 = _createForOfIteratorHelper(this._list),\n          _step2;\n        try {\n          for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {\n            var c = _step2.value;\n            if (c.f) {\n              if (!idx) {\n                return c.m;\n              }\n              idx--;\n            }\n          }\n        } catch (err) {\n          _iterator2.e(err);\n        } finally {\n          _iterator2.f();\n        }\n      }\n      return this._list[idx].m;\n    }\n\n    /**\n     * Returns a zero-based index value of an item in the collection.\n     * @param {*} item Collection item.\n     * @returns {number} Zero-based index of the item, or -1 if the item is not found.\n     */\n  }, {\n    key: \"indexOf\",\n    value: function indexOf(item) {\n      var s = this._beginIdx();\n      var e = this._endIdx();\n      if (e > s) {\n        if (this._filter) {\n          var i = 0;\n          var _iterator3 = _createForOfIteratorHelper(this._list),\n            _step3;\n          try {\n            for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {\n              var c = _step3.value;\n              if (c.f) {\n                if (c.m === item) {\n                  return i >= s ? i - s : -1;\n                }\n                i++;\n                if (i >= e) break;\n              } else {\n                if (c.m === item) {\n                  return -1;\n                }\n              }\n            }\n          } catch (err) {\n            _iterator3.e(err);\n          } finally {\n            _iterator3.f();\n          }\n        } else {\n          for (var _i = s; _i < e; _i++) {\n            if (this._list[_i].m === item) {\n              return _i - s;\n            }\n          }\n        }\n      }\n      return -1;\n    }\n\n    /**\n     * Refreshes the collection in case sorting, filtering, or mapping has been\n     * affected by changes.\n     */\n  }, {\n    key: \"refresh\",\n    value: function refresh() {\n      if (this._collection) {\n        var _iterator4 = _createForOfIteratorHelper(this._collection),\n          _step4;\n        try {\n          for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {\n            var item = _step4.value;\n            this._onChange(null, item);\n          }\n        } catch (err) {\n          _iterator4.e(err);\n        } finally {\n          _iterator4.f();\n        }\n      }\n    }\n  }, {\n    key: \"_indexOf\",\n    value: function _indexOf(item) {\n      if (this._filter) {\n        return this._fIndexOf(item);\n      }\n      for (var i = 0; i < this._list.length; i++) {\n        var c = this._list[i];\n        if (c.m === item) {\n          return {\n            cont: c,\n            idx: i,\n            fidx: i\n          };\n        }\n      }\n      return {\n        cont: null,\n        idx: -1,\n        fidx: -1\n      };\n    }\n  }, {\n    key: \"_fIndexOf\",\n    value: function _fIndexOf(item) {\n      var fi = 0;\n      for (var i = 0; i < this._list.length; i++) {\n        var c = this._list[i];\n        if (c.m === item) {\n          return {\n            cont: c,\n            idx: i,\n            fidx: fi\n          };\n        }\n        if (c.f) fi++;\n      }\n      return {\n        cont: null,\n        idx: -1,\n        fidx: -1\n      };\n    }\n  }, {\n    key: \"_atFIndex\",\n    value: function _atFIndex(fidx) {\n      if (this._filter) {\n        // Find the fidx:th item\n        var _iterator5 = _createForOfIteratorHelper(this._list),\n          _step5;\n        try {\n          for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {\n            var c = _step5.value;\n            if (c.f) {\n              if (!fidx) {\n                return c.m;\n              }\n              fidx--;\n            }\n          }\n        } catch (err) {\n          _iterator5.e(err);\n        } finally {\n          _iterator5.f();\n        }\n      }\n      return this._list[fidx].m;\n    }\n\n    // Returns the begin index based of the filtered internal list.\n    // Optionally with the length to calculate from.\n  }, {\n    key: \"_beginIdx\",\n    value: function _beginIdx(l) {\n      if (l === undefined) l = this._len;\n      var o = this._begin;\n      return o < 0 ? Math.max(0, l + o) : Math.min(l, o);\n    }\n\n    // Returns the end index based of the filtered internal list.\n    // Optionally with the length to calculate from.\n  }, {\n    key: \"_endIdx\",\n    value: function _endIdx(l) {\n      if (l === undefined) l = this._len;\n      var o = this._end;\n      if (o === null) return l;\n      return o < 0 ? Math.max(0, l + o) : Math.min(l, o);\n    }\n  }, {\n    key: \"_array\",\n    value: function _array() {\n      var arr = this._filter ? this._list.filter(function (c) {\n        return c.f;\n      }) : this._list;\n      var s = this._beginIdx();\n      var e = this._endIdx();\n      if (s == 0 && e == this._len) {\n        return arr.map(function (c) {\n          return c.m;\n        });\n      }\n      return arr.slice(s, e).map(function (c) {\n        return c.m;\n      });\n    }\n  }, {\n    key: \"_wrapModel\",\n    value: function _wrapModel(m, item) {\n      return this._filter ? {\n        m: m,\n        f: this._filter(item),\n        i: item\n      } : {\n        m: m,\n        i: item\n      };\n    }\n  }, {\n    key: \"_setEventListeners\",\n    value: function _setEventListeners(on) {\n      var c = this._collection;\n      if (!c || typeof c.on !== 'function') {\n        return;\n      }\n      var cb = on ? 'on' : 'off';\n      c[cb]('add', this._onAdd);\n      c[cb]('remove', this._onRemove);\n    }\n  }, {\n    key: \"_binarySearch\",\n    value: function _binarySearch(m) {\n      var _this3 = this;\n      return array.binarySearch(this._list, {\n        m: m\n      }, function (a, b) {\n        return _this3._compare(a.m, b.m);\n      });\n    }\n  }, {\n    key: \"_onChange\",\n    value: function _onChange(_, item) {\n      var m = this._weakMap ? this._weakMap.get(item) : item;\n\n      // Get current idx of the item.\n      var _this$_indexOf = this._indexOf(m),\n        cont = _this$_indexOf.cont,\n        idx = _this$_indexOf.idx,\n        fidx = _this$_indexOf.fidx;\n      if (!cont) {\n        return;\n      }\n\n      // Get filtered and new filter value\n      var f = true;\n      var nf = true;\n      if (this._filter) {\n        f = cont.f;\n        nf = this._filter(item);\n        cont.f = nf;\n      }\n\n      // Get new mapped item\n      var nm = m;\n      if (this._map) {\n        nm = this._map(item, this._collection);\n        if (m !== nm) {\n          cont.m = nm;\n          this._weakMap.set(item, nm);\n        }\n      }\n\n      // Check if item moved\n      var nfidx = fidx;\n      var moved = this._compare && !((idx === 0 || this._compare(this._list[idx - 1].m, nm) < 0) && (idx === this._list.length - 1 || this._compare(nm, this._list[idx + 1].m) < 0));\n      if (moved) {\n        // Remove from last position\n        this._list.splice(idx, 1);\n        idx = this._binarySearch(nm);\n        if (idx < 0) {\n          // If idx < 0, the value contains the bitwise compliment of where the\n          // item would fit.\n          idx = ~idx;\n        }\n        // Insert in new position\n        this._list.splice(idx, 0, cont);\n        nfidx = this._filter ? nf ? this._fIndexOf(m).fidx : fidx : idx;\n      }\n\n      // Early exit if visibility, mapped value, and index is unchanged.\n      if (f === nf && m === nm && fidx === nfidx) {\n        return;\n      }\n\n      // Remove unless it was previously hidden\n      if (f) {\n        this._len--;\n        this._trySendRemove(m, fidx);\n      }\n\n      // Add unless it is now hidden\n      if (nf) {\n        this._len++;\n        this._trySendAdd(nm, nfidx);\n      }\n    }\n  }, {\n    key: \"_trySendAdd\",\n    value: function _trySendAdd(m, i) {\n      var l = this._len;\n      var cur_s = this._beginIdx(l);\n      var pre_s = this._beginIdx(l - 1);\n      var cur_e = this._endIdx(l);\n      var pre_e = this._endIdx(l - 1);\n\n      // Quick escape\n      if (pre_s >= pre_e && cur_s >= cur_e) {\n        return;\n      }\n      if (cur_s > pre_s) {\n        if (i >= cur_s) {\n          this._sendRemove(this._atFIndex(pre_s), 0);\n        }\n      } else {\n        if (i < cur_s) {\n          this._sendAdd(this._atFIndex(cur_s), 0);\n        }\n      }\n      if (i >= cur_s && i < cur_e) {\n        this._sendAdd(m, i - cur_s);\n      }\n      if (cur_e > pre_e) {\n        if (i >= cur_e) {\n          this._sendAdd(this._atFIndex(cur_e - 1), cur_e - cur_s - 1);\n        }\n      } else {\n        if (i < cur_e) {\n          this._sendRemove(this._atFIndex(cur_e), cur_e - cur_s);\n        }\n      }\n    }\n  }, {\n    key: \"_trySendRemove\",\n    value: function _trySendRemove(m, i) {\n      var l = this._len;\n      var cur_s = this._beginIdx(l);\n      var pre_s = this._beginIdx(l + 1);\n      var cur_e = this._endIdx(l);\n      var pre_e = this._endIdx(l + 1);\n\n      // Quick escape\n      if (pre_s >= pre_e && cur_s >= cur_e) {\n        return;\n      }\n      if (cur_e < pre_e) {\n        if (i >= pre_e) {\n          this._sendRemove(this._atFIndex(pre_e - 1), pre_e - pre_s - 1);\n        }\n      } else {\n        if (i < pre_e) {\n          this._sendAdd(this._atFIndex(pre_e - 1), pre_e - pre_s);\n        }\n      }\n      if (i >= pre_s && i < pre_e) {\n        this._sendRemove(m, i - pre_s);\n      }\n      if (cur_s < pre_s) {\n        if (i > cur_s) {\n          this._sendAdd(this._atFIndex(cur_s), 0);\n        }\n      } else {\n        if (i < cur_s) {\n          this._sendRemove(this._atFIndex(cur_s - 1), 0);\n        }\n      }\n    }\n  }, {\n    key: \"_sendAdd\",\n    value: function _sendAdd(item, idx) {\n      this._eventBus.emit(this, this._namespace + '.add', {\n        item: item,\n        idx: idx\n      });\n    }\n  }, {\n    key: \"_sendRemove\",\n    value: function _sendRemove(item, idx) {\n      this._eventBus.emit(this, this._namespace + '.remove', {\n        item: item,\n        idx: idx\n      });\n    }\n  }, {\n    key: \"_onAdd\",\n    value: function _onAdd(e) {\n      if (this._disposed) {\n        return;\n      }\n      var m = this._map ? this._map(e.item, this._collection) : e.item;\n      var idx = this._compare ? this._binarySearch(m) : e.idx;\n      if (this._weakMap) {\n        this._weakMap.set(e.item, m);\n      }\n      if (idx < 0) {\n        // If idx < 0, the value contains the bitwise compliment of where the\n        // item would fit.\n        idx = ~idx;\n      }\n      var cont = this._wrapModel(m, e.item);\n      this._list.splice(idx, 0, cont);\n      if (this._listen && e.item.on) {\n        e.item.on('change', this._onChange);\n      }\n      if (this._filter) {\n        if (!cont.f) {\n          return;\n        }\n        idx = this._fIndexOf(m).fidx;\n      }\n      this._len++;\n      this._trySendAdd(m, idx);\n    }\n  }, {\n    key: \"_onRemove\",\n    value: function _onRemove(e) {\n      if (this._disposed) {\n        return;\n      }\n      var m = this._weakMap && this._compare ? this._weakMap.get(e.item) : e.item;\n      var idx = this._compare ? this._binarySearch(m) : e.idx;\n      var cont = this._list[idx];\n      if (this._weakMap) {\n        this._weakMap[\"delete\"](e.item);\n      }\n      var fidx = idx;\n      if (this._listen && e.item.on) {\n        e.item.off('change', this._onChange);\n      }\n      if (this._filter) {\n        // Quick exit if a filtered item was removed.\n        if (!cont.f) {\n          return this._list.splice(idx, 1);\n        }\n        var r = this._fIndexOf(m);\n        if (!r.cont) {\n          return;\n        }\n        fidx = r.fidx;\n      }\n      this._list.splice(idx, 1);\n      this._len--;\n      this._trySendRemove(m, fidx);\n    }\n  }, {\n    key: \"_checkAutoDispose\",\n    value: function _checkAutoDispose(dt) {\n      var _this4 = this;\n      var ms = this._autoDispose;\n      if (ms === null) {\n        return;\n      }\n      this._onCount += dt;\n      if (this._onCount > 0) {\n        if (this._timeout) {\n          clearTimeout(this._timeout);\n          this._timeout = null;\n        }\n      } else {\n        this._timeout = setTimeout(function () {\n          return _this4.dispose();\n        }, ms);\n      }\n    }\n  }, {\n    key: \"dispose\",\n    value: function dispose() {\n      if (this._disposed) {\n        return;\n      }\n      if (this._listen) {\n        var _iterator6 = _createForOfIteratorHelper(this._list),\n          _step6;\n        try {\n          for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {\n            var cont = _step6.value;\n            var item = cont.i;\n            if (item && item.on) {\n              item.off('change', this._onChange);\n            }\n          }\n        } catch (err) {\n          _iterator6.e(err);\n        } finally {\n          _iterator6.f();\n        }\n      }\n      this._setEventListeners(false);\n      delete this._collection;\n      delete this._weakMap;\n      this.disposed = false;\n    }\n  }, {\n    key: _Symbol$iterator,\n    value: function value() {\n      var i = 0;\n      var a;\n      var arr = this._list;\n      var done = {\n        done: true\n      };\n      var s = this._beginIdx();\n      var e = this._endIdx();\n      var si = 0;\n      if (e <= s) {\n        return {\n          next: function next() {\n            return done;\n          }\n        };\n      }\n      if (this._filter) {\n        return {\n          next: function next() {\n            while (si < e) {\n              a = arr[i];\n              i++;\n              if (a.f) {\n                si++;\n                if (si > s) {\n                  return {\n                    value: a.m,\n                    done: false\n                  };\n                }\n              }\n            }\n            return done;\n          }\n        };\n      }\n      i = s;\n      return {\n        next: function next() {\n          return i < e ? {\n            value: arr[i++].m,\n            done: false\n          } : done;\n        }\n      };\n    }\n  }]);\n  return CollectionWrapper;\n}(Symbol.iterator);\nexport default CollectionWrapper;","function _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\nfunction _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it[\"return\"] != null) it[\"return\"](); } finally { if (didErr) throw err; } } }; }\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\nfunction _toPropertyKey(arg) { var key = _toPrimitive(arg, \"string\"); return _typeof(key) === \"symbol\" ? key : String(key); }\nfunction _toPrimitive(input, hint) { if (_typeof(input) !== \"object\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \"default\"); if (_typeof(res) !== \"object\") return res; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (hint === \"string\" ? String : Number)(input); }\nimport eventBus from 'modapp-eventbus';\nimport { obj } from 'modapp-utils';\n\n/**\n * Model key callback\n * @callback CollectionToModel~modelKeyCallback\n * @param {*} item Collection item\n * @returns {string} Model key for the item. Must be unique for all items in the collection, and should be based on immutable values.\n */\n\n/**\n * A wrapper for a {@link module:modapp~Collection} that exposes an object that implements the {@link module:modapp~Model}\n * interface. It will transparently propagate emitted add and remove events and turn them to change events.\n * @implements {module:modapp~Model}\n */\nvar CollectionToModel = /*#__PURE__*/function () {\n  /**\n   * Creates an CollectionToModel instance.\n   * @param {object} collection Collection object to wrap.\n   * @param {CollectionToModel~modelKeyCallback} keyCallback Model key callback function.\n   * @param {object} [opt] Optional parameters.\n   * @param {function} [opt.map] Model value map callback. If not provided, model values will be the same as collection items: func(item) -> value\n   * @param {string} [opt.namespace] Event bus namespace. Defaults to 'collectionToModel'.\n   * @param {module:modapp~EventBus} [opt.eventBus] Event bus.\n   */\n  function CollectionToModel(collection, keyCallback) {\n    var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n    _classCallCheck(this, CollectionToModel);\n    this._collection = null;\n    this._props = {};\n    this._keyCallback = keyCallback;\n    obj.update(this, opt, {\n      map: {\n        type: 'function',\n        \"default\": function _default(v) {\n          return v;\n        },\n        property: '_map'\n      },\n      namespace: {\n        type: 'string',\n        \"default\": 'collectionToModel',\n        property: '_namespace'\n      },\n      eventBus: {\n        type: 'object',\n        \"default\": eventBus,\n        property: '_eventBus'\n      }\n    });\n\n    // Bind callbacks\n    this._onAdd = this._onAddRemove.bind(this, true);\n    this._onRemove = this._onAddRemove.bind(this, false);\n    this.setCollection(collection, true);\n  }\n\n  /**\n   * Model properties.\n   * @returns {object} Anonymous object with all model properties.\n   */\n  _createClass(CollectionToModel, [{\n    key: \"props\",\n    get: function get() {\n      return this._props;\n    }\n\n    /**\n     * Set wrapped collection.\n     * @param {Collection|Array?} collection Collection to wrap.\n     * @param {boolean} noEvents If true, no events should be emitted.\n     * @returns {this}\n     */\n  }, {\n    key: \"setCollection\",\n    value: function setCollection(collection, noEvents) {\n      collection = collection || null;\n      if (this._collection === collection) {\n        return;\n      }\n      this._setEventListeners(false);\n      this._collection = collection;\n\n      // Init props\n      var o = {};\n      var _iterator = _createForOfIteratorHelper(this._collection),\n        _step;\n      try {\n        for (_iterator.s(); !(_step = _iterator.n()).done;) {\n          var v = _step.value;\n          var _k2 = this._keyCallback(v);\n          o[_k2] = this._map(v);\n        }\n      } catch (err) {\n        _iterator.e(err);\n      } finally {\n        _iterator.f();\n      }\n      var change = {};\n      for (var k in o) {\n        var mv = o[k];\n        if (mv !== this._props[k]) {\n          change[k] = this._props[k];\n          this._props[k] = mv;\n          if (this._promote(k)) {\n            this[k] = mv;\n          }\n        }\n      }\n      for (var _k in this._props) {\n        if (!o.hasOwnProperty(_k)) {\n          change[_k] = this._props[_k];\n          delete this._props[_k];\n          if (this._promote(_k)) {\n            delete this[_k];\n          }\n        }\n      }\n      this._setEventListeners(true);\n      if (!noEvents) {\n        this._eventBus.emit(this, this._namespace + '.change', change);\n      }\n      return this;\n    }\n\n    /**\n     * Get wrapped collection\n     * @returns {Collection?} Collection\n     */\n  }, {\n    key: \"getCollection\",\n    value: function getCollection() {\n      return this._collection;\n    }\n\n    /**\n     * Attach an event handler function for one or more session events.\n     * @param {?string} events One or more space-separated events. Null means any event.\n     * @param {Event~eventCallback} handler A function to execute when the event is emitted.\n     */\n  }, {\n    key: \"on\",\n    value: function on(events, handler) {\n      this._eventBus.on(this, events, handler, this._namespace);\n    }\n\n    /**\n     * Remove an event handler.\n     * @param {?string} events One or more space-separated events. Null means any event.\n     * @param {Event~eventCallback} [handler] An option handler function. The handler will only be remove if it is the same handler.\n     */\n  }, {\n    key: \"off\",\n    value: function off(events, handler) {\n      this._eventBus.off(this, events, handler, this._namespace);\n    }\n  }, {\n    key: \"_setEventListeners\",\n    value: function _setEventListeners(on) {\n      if (!this._collection || !this._collection.on) {\n        return;\n      }\n      if (on) {\n        this._collection.on('add', this._onAdd);\n        this._collection.on('remove', this._onRemove);\n      } else {\n        this._collection.off('add', this._onAdd);\n        this._collection.off('remove', this._onRemove);\n      }\n    }\n  }, {\n    key: \"_onAddRemove\",\n    value: function _onAddRemove(isAdd, e) {\n      if (!this._collection) {\n        return;\n      }\n      var v = e.item;\n      var k = this._keyCallback(v);\n      var ov = this._props[k];\n      var mv = this._map(v);\n      if (isAdd) {\n        this._props[k] = mv;\n        if (this._promote(k)) {\n          this[k] = mv;\n        }\n      } else {\n        delete this._props[k];\n        if (this._promote(k)) {\n          delete this[k];\n        }\n      }\n      this._eventBus.emit(this, this._namespace + '.change', _defineProperty({}, k, ov));\n    }\n  }, {\n    key: \"_promote\",\n    value: function _promote(key) {\n      return (this.hasOwnProperty(key) || typeof this[key] == 'undefined') && key[0] !== '_';\n    }\n  }, {\n    key: \"toJSON\",\n    value: function toJSON() {\n      var o = Object.assign({}, this._props);\n      for (var k in o) {\n        var v = o[k];\n        if (_typeof(v) === 'object' && v !== null && v.toJSON) {\n          o[k] = v.toJSON();\n        }\n      }\n      return o;\n    }\n  }, {\n    key: \"dispose\",\n    value: function dispose() {\n      if (!this._collection) {\n        return;\n      }\n      this._setEventListeners(false);\n      delete this._props;\n      delete this._collection;\n    }\n  }]);\n  return CollectionToModel;\n}();\nexport default CollectionToModel;","function _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\nfunction _toPropertyKey(arg) { var key = _toPrimitive(arg, \"string\"); return _typeof(key) === \"symbol\" ? key : String(key); }\nfunction _toPrimitive(input, hint) { if (_typeof(input) !== \"object\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \"default\"); if (_typeof(res) !== \"object\") return res; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (hint === \"string\" ? String : Number)(input); }\nimport eventBus from 'modapp-eventbus';\nimport { array } from 'modapp-utils';\nimport { getProps, patchDiff } from './utils';\nfunction compare(a, b) {\n  return a.key.localeCompare(b.key);\n}\n\n/**\n * ModelToCollection turns a model into a collection.\n */\nvar ModelToCollection = /*#__PURE__*/function (_Symbol$iterator) {\n  /**\n   * Creates a ModelToCollection instance.\n   * @param {object|Model} model Model\n   * @param {object} [opt] Optional parameters.\n   * @param {function} [opt.compare] Compare function with receives two objects { key, value }. Defaults to: (a, b) => a.key.localeCompare(b.key)\n   * @param {function} [opt.filter] Filter function filtering which key/values to show: function(key, value) -> boolean\n   * @param {string} [opt.namespace] Event bus namespace. Defaults to 'modelToCollection'.\n   * @param {module:modapp~EventBus} [opt.eventBus] Event bus.\n   */\n  function ModelToCollection(model, opt) {\n    _classCallCheck(this, ModelToCollection);\n    opt = opt || {};\n    this._compare = opt.compare || compare;\n    this._namespace = opt.namespace || 'modelToCollection';\n    this._eventBus = opt.eventBus || eventBus;\n    this._filter = opt.filter || null;\n\n    // Bind callbacks\n    this._onChange = this._onChange.bind(this);\n\n    // Init list\n    this._list = [];\n    this._props = {};\n    if (this._filter) {\n      this._filtered = {};\n    }\n    this.setModel(model, false);\n  }\n  _createClass(ModelToCollection, [{\n    key: \"length\",\n    get: function get() {\n      return this._list.length;\n    }\n\n    /**\n     * Get wrapped model.\n     * @returns {object|Model} Model\n     */\n  }, {\n    key: \"getModel\",\n    value: function getModel() {\n      return this._model;\n    }\n\n    /**\n     * Attach an event handler function for one or more session events.\n     * @param {?string} events One or more space-separated events. Null means any event.\n     * @param {Event~eventCallback} handler A function to execute when the event is emitted.\n     */\n  }, {\n    key: \"on\",\n    value: function on(events, handler) {\n      this._eventBus.on(this, events, handler, this._namespace);\n    }\n\n    /**\n     * Remove an event handler.\n     * @param {?string} events One or more space-separated events. Null means any event.\n     * @param {Event~eventCallback} [handler] An option handler function. The handler will only be remove if it is the same handler.\n     */\n  }, {\n    key: \"off\",\n    value: function off(events, handler) {\n      this._eventBus.off(this, events, handler, this._namespace);\n    }\n\n    /**\n     * Retrieves the order index of an item.\n     * @param {*} item Collection item.\n     * @returns {number} Order index of the item. -1 if the item id doesn't exist.\n     */\n  }, {\n    key: \"indexOf\",\n    value: function indexOf(item) {\n      for (var i = 0; i < this._list.length; i++) {\n        if (this._list[i].value === item) {\n          return i;\n        }\n      }\n      return -1;\n    }\n\n    /**\n     * Returns the item at a given index.\n     * @param {number} idx Index position\n     * @returns {*} Item or undefined if idx is out of bounds.\n     */\n  }, {\n    key: \"atIndex\",\n    value: function atIndex(idx) {\n      return idx < 0 || idx >= this._list.length ? undefined : this._list[idx];\n    }\n\n    /**\n     * Returns the collection as an array.\n     * @returns {Array} Array of items.\n     */\n  }, {\n    key: \"toArray\",\n    value: function toArray() {\n      return this._list.map(function (o) {\n        return o.value;\n      });\n    }\n\n    /**\n     * Sets the wrapped model.\n     * @param {?object} model Model or object to set.\n     * @param {boolean} noEvents Flag telling if no collection events should be triggered during set.\n     * @returns {this}\n     */\n  }, {\n    key: \"setModel\",\n    value: function setModel(model, noEvents) {\n      model = model || null;\n      if (model === this._model) return this;\n      for (var k in this._props) {\n        this._unlistenItem(this._props[k]);\n      }\n      this._listen(false);\n      this._model = model;\n      this._listen(true);\n      var oldList = this._list;\n      this._list = [];\n      this._props = {};\n      if (this._filter) {\n        this._filtered = {};\n      }\n      if (this._model) {\n        // Iterate over props object if available, otherwise the model itself.\n        var p = getProps(this._model);\n        for (var _k in p) {\n          var v = p[_k];\n          var o = {\n            key: _k,\n            value: v\n          };\n          if (!this._filter || this._filter(_k, v)) {\n            this._list.push(o);\n          } else {\n            this._filtered[_k] = o;\n          }\n          this._listenItem(o);\n        }\n        this._list.sort(this._compare);\n      }\n      if (!noEvents) {\n        this._sendSyncEvents(oldList, this._list);\n      }\n      return this;\n    }\n  }, {\n    key: \"_sendSyncEvents\",\n    value: function _sendSyncEvents(oldList, newList) {\n      var _this = this;\n      patchDiff(oldList, newList, function (o, n, idx) {\n        return _this._eventBus.emit(_this, _this._namespace + '.add', {\n          item: o.value,\n          idx: idx\n        });\n      }, function (o, m, idx) {\n        return _this._eventBus.emit(_this, _this._namespace + '.remove', {\n          item: o.value,\n          idx: idx\n        });\n      });\n    }\n\n    /**\n     * Refresh scans through all items to ensure filtering and sorting is\n     * correct.\n     * @param {string} [key] Optional key of a single item to refresh.\n     */\n  }, {\n    key: \"refresh\",\n    value: function refresh(key) {\n      if (!this._model) return;\n\n      // Start by sorting list, in case the compare is altered.\n      var oldList = this._list.slice();\n      this._list.sort(this._compare);\n      if (key) {\n        var o = this._props[key];\n        if (o) {\n          this._onItemChange(o);\n        }\n      } else {\n        for (var k in this._props) {\n          this._onItemChange(this._props[k]);\n        }\n      }\n      this._sendSyncEvents(oldList, this._list);\n    }\n  }, {\n    key: \"_listen\",\n    value: function _listen(on) {\n      var cb = on ? 'on' : 'off';\n      if (this._model && this._model[cb]) {\n        this._model[cb]('change', this._onChange);\n      }\n    }\n  }, {\n    key: \"_listenItem\",\n    value: function _listenItem(o) {\n      var _this2 = this;\n      this._props[o.key] = o;\n      var m = o.value;\n      if (_typeof(m) === 'object' && m !== null && typeof m.on == 'function') {\n        o.cb = function (m, change) {\n          if (_this2._props[o.key] != o) {\n            return;\n          }\n          var oldList = _this2._list.slice();\n          _this2._list.sort(_this2._compare);\n          _this2._onItemChange(o);\n          _this2._sendSyncEvents(oldList, _this2._list);\n        };\n        m.on('change', o.cb);\n      }\n    }\n  }, {\n    key: \"_unlistenItem\",\n    value: function _unlistenItem(o) {\n      if (o.cb) {\n        o.value.off('change', o.cb);\n        o.cb = null;\n      }\n    }\n  }, {\n    key: \"_onChange\",\n    value: function _onChange(change, m) {\n      if (m !== this._model) return;\n      var oldList = this._list.slice();\n      this._list.sort(this._compare);\n      var p = getProps(m);\n      for (var k in change) {\n        var nv = p[k];\n        var o = this._props[k];\n        var ov = o ? o.value : undefined;\n        if (ov === nv) continue;\n\n        // Old value undefined means a value was added\n        if (typeof ov == 'undefined') {\n          this._addItem(k, nv);\n        } else if (typeof nv == 'undefined') {\n          this._removeItem(k);\n        } else {\n          this._removeItem(k);\n          this._addItem(k, nv);\n        }\n      }\n      this._sendSyncEvents(oldList, this._list);\n    }\n  }, {\n    key: \"_onItemChange\",\n    value: function _onItemChange(o) {\n      var k = o.key;\n      var v = o.value;\n      var show = !this._filter || this._filter(k, v);\n      // Check if it is filtered\n      var f = this._filtered && this._filtered[k];\n      if (f) {\n        if (show) {\n          delete this._filtered[k];\n          this._list.splice(this._insertIdx(o), 0, o);\n        }\n      } else {\n        if (!show) {\n          var idx = this._indexOfItem(o.key, v);\n          if (idx < 0) {\n            console.error(\"Item not in list: \", k, v);\n            return;\n          }\n          this._list.splice(idx, 1);\n          this._filtered[k] = o;\n        }\n      }\n    }\n  }, {\n    key: \"_addItem\",\n    value: function _addItem(k, item) {\n      var o = {\n        key: k,\n        value: item\n      };\n      this._listenItem(o);\n      if (!this._filter || this._filter(k, item)) {\n        this._list.splice(this._insertIdx(o), 0, o);\n      } else {\n        this._filtered[k] = o;\n      }\n    }\n  }, {\n    key: \"_removeItem\",\n    value: function _removeItem(k) {\n      var o = this._props[k];\n      if (!o) {\n        console.error(\"Item key not found: \", k);\n        return;\n      }\n      delete this._props[k];\n      this._unlistenItem(o);\n\n      // Handle hidden item\n      if (this._filtered && this._filtered[k]) {\n        delete this._filtered[k];\n        return;\n      }\n      // Handle visible item\n      var idx = this._indexOfItem(k, o.value);\n      if (idx < 0) {\n        console.error(\"Item not in list: \", k, o.value);\n        return;\n      }\n      this._list.splice(idx, 1);\n    }\n  }, {\n    key: \"_insertIdx\",\n    value: function _insertIdx(o) {\n      var idx = array.binarySearch(this._list, o, this._compare);\n      return idx < 0 ? ~idx : idx; // Use the bitwise complement to get insert index.\n    }\n  }, {\n    key: \"_indexOfItem\",\n    value: function _indexOfItem(k, item) {\n      var idx = array.binarySearch(this._list, {\n        key: k,\n        value: item\n      }, this._compare);\n      // Verify we found it\n      if (idx >= 0 && this._list[idx].key === k) {\n        return idx;\n      }\n\n      // Binary search failed. Let's scan it instead.\n      return this._indexOfKey(k);\n    }\n  }, {\n    key: \"_indexOfKey\",\n    value: function _indexOfKey(k) {\n      for (var i = this._list.length - 1; i >= 0; i--) {\n        if (this._list[i].key === k) return i;\n      }\n      return -1;\n    }\n  }, {\n    key: \"dispose\",\n    value: function dispose() {\n      this.setModel(null, true);\n    }\n  }, {\n    key: _Symbol$iterator,\n    value: function value() {\n      var i = 0;\n      var a = this._list;\n      var l = a.length;\n      return {\n        next: function next() {\n          return i >= l ? {\n            done: true\n          } : {\n            value: a[i++].value,\n            done: false\n          };\n        }\n      };\n    }\n  }]);\n  return ModelToCollection;\n}(Symbol.iterator);\nexport default ModelToCollection;","'use strict';\nvar charAt = require('../internals/string-multibyte').charAt;\nvar toString = require('../internals/to-string');\nvar InternalStateModule = require('../internals/internal-state');\nvar defineIterator = require('../internals/iterator-define');\nvar createIterResultObject = require('../internals/create-iter-result-object');\n\nvar STRING_ITERATOR = 'String Iterator';\nvar setInternalState = InternalStateModule.set;\nvar getInternalState = InternalStateModule.getterFor(STRING_ITERATOR);\n\n// `String.prototype[@@iterator]` method\n// https://tc39.es/ecma262/#sec-string.prototype-@@iterator\ndefineIterator(String, 'String', function (iterated) {\n  setInternalState(this, {\n    type: STRING_ITERATOR,\n    string: toString(iterated),\n    index: 0\n  });\n// `%StringIteratorPrototype%.next` method\n// https://tc39.es/ecma262/#sec-%stringiteratorprototype%.next\n}, function next() {\n  var state = getInternalState(this);\n  var string = state.string;\n  var index = state.index;\n  var point;\n  if (index >= string.length) return createIterResultObject(undefined, true);\n  point = charAt(string, index);\n  state.index += point.length;\n  return createIterResultObject(point, false);\n});\n"],"names":["_typeof","o","Symbol","iterator","constructor","prototype","_defineProperties","target","props","i","length","descriptor","enumerable","configurable","writable","Object","defineProperty","key","input","prim","toPrimitive","undefined","res","call","hint","TypeError","String","_toPrimitive","_get","Reflect","get","bind","property","receiver","base","object","hasOwnProperty","_getPrototypeOf","_superPropBase","desc","getOwnPropertyDescriptor","arguments","value","apply","this","_setPrototypeOf","p","setPrototypeOf","__proto__","_assertThisInitialized","self","ReferenceError","getPrototypeOf","_RootElem","subClass","superClass","create","_inherits","Html","Constructor","protoProps","Derived","hasNativeReflectConstruct","_super","construct","sham","Proxy","Boolean","valueOf","e","_isNativeReflectConstruct","result","Super","NewTarget","_possibleConstructorReturn","html","opt","_this","instance","_classCallCheck","assign","tagName","animId","rendered","_handleChange","tmp","el","nodeEl","innerHTML","_this2","next","callback","charAt","toString","InternalStateModule","defineIterator","createIterResultObject","STRING_ITERATOR","setInternalState","set","getInternalState","getterFor","iterated","type","string","index","point","state"],"sourceRoot":""}