'use strict'; /** @polymer @mixinFunction */ let ArraySelectorMixin$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector = module$third_party$javascript$polymer$v2$polymer$lib$utils$mixin.dedupingMixin((superClass) => { /** @private @constructor @implements {Polymer_ElementMixin} */ let elementBase = module$third_party$javascript$polymer$v2$polymer$lib$mixins$element_mixin.ElementMixin(superClass); /** @unrestricted @implements {Polymer_ArraySelectorMixin} @polymer @mixinClass */ class ArraySelectorMixin extends elementBase { /** @return {PolymerElementProperties} */ static get properties() { return $jscomp.reflectObject(ArraySelectorMixin, {items:{type:Array}, multi:{type:Boolean, value:false}, selected:{type:Object, notify:true}, selectedItem:{type:Object, notify:true}, toggle:{type:Boolean, value:false}}); } /** @return {!Array} */ static get observers() { return [$jscomp.reflectProperty("__updateSelection", /** @type {!ArraySelectorMixin} */ ({})) + "(" + $jscomp.reflectProperty("multi", /** @type {!ArraySelectorMixin} */ ({})) + "," + $jscomp.reflectProperty("items", /** @type {!ArraySelectorMixin} */ ({})) + ".*" + ")"]; } constructor() { super(); this.__lastItems = null; this.__lastMulti = null; this.__selectedMap = null; } __updateSelection(multi, itemsInfo) { let path = itemsInfo.path; if (path == "items") { let newItems = itemsInfo.base || []; let lastItems = this.__lastItems; let lastMulti = this.__lastMulti; if (multi !== lastMulti) { this.clearSelection(); } if (lastItems) { let splices = module$third_party$javascript$polymer$v2$polymer$lib$utils$array_splice.calculateSplices(newItems, lastItems); this.__applySplices(splices); } this.__lastItems = newItems; this.__lastMulti = multi; } else { if (itemsInfo.path == "items.splices") { this.__applySplices(itemsInfo.value.indexSplices); } else { let part = path.slice("items.".length); let idx = parseInt(part, 10); if (part.indexOf(".") < 0 && part == idx) { this.__deselectChangedIdx(idx); } } } } __applySplices(splices) { let selected = this.__selectedMap; for (let i = 0; i < splices.length; i++) { let s = splices[i]; selected.forEach((idx, item) => { if (idx < s.index) { } else { if (idx >= s.index + s.removed.length) { selected.set(item, idx + s.addedCount - s.removed.length); } else { selected.set(item, -1); } } }); for (let j = 0; j < s.addedCount; j++) { let idx = s.index + j; if (selected.has(this.items[idx])) { selected.set(this.items[idx], idx); } } } this.__updateLinks(); let sidx = 0; selected.forEach((idx, item) => { if (idx < 0) { if (this.multi) { this.splice("selected", sidx, 1); } else { this.selected = this.selectedItem = null; } selected.delete(item); } else { sidx++; } }); } __updateLinks() { this.__dataLinkedPaths = {}; if (this.multi) { let sidx = 0; this.__selectedMap.forEach((idx) => { if (idx >= 0) { this.linkPaths("items." + idx, "selected." + sidx++); } }); } else { this.__selectedMap.forEach((idx) => { this.linkPaths("selected", "items." + idx); this.linkPaths("selectedItem", "items." + idx); }); } } /** @return {void} @override */ clearSelection() { this.__dataLinkedPaths = {}; this.__selectedMap = new Map; this.selected = this.multi ? [] : null; this.selectedItem = null; } /** @param {*} item @return {boolean} @override */ isSelected(item) { return this.__selectedMap.has(item); } /** @param {number} idx @return {boolean} @override */ isIndexSelected(idx) { return this.isSelected(this.items[idx]); } __deselectChangedIdx(idx) { let sidx = this.__selectedIndexForItemIndex(idx); if (sidx >= 0) { let i = 0; this.__selectedMap.forEach((idx, item) => { if (sidx == i++) { this.deselect(item); } }); } } __selectedIndexForItemIndex(idx) { let selected = this.__dataLinkedPaths["items." + idx]; if (selected) { return parseInt(selected.slice("selected.".length), 10); } } /** @param {*} item @return {void} @override */ deselect(item) { let idx = this.__selectedMap.get(item); if (idx >= 0) { this.__selectedMap.delete(item); let sidx; if (this.multi) { sidx = this.__selectedIndexForItemIndex(idx); } this.__updateLinks(); if (this.multi) { this.splice("selected", sidx, 1); } else { this.selected = this.selectedItem = null; } } } /** @param {number} idx @return {void} @override */ deselectIndex(idx) { this.deselect(this.items[idx]); } /** @param {*} item @return {void} @override */ select(item) { this.selectIndex(this.items.indexOf(item)); } /** @param {number} idx @return {void} @override */ selectIndex(idx) { let item = this.items[idx]; if (!this.isSelected(item)) { if (!this.multi) { this.__selectedMap.clear(); } this.__selectedMap.set(item, idx); this.__updateLinks(); if (this.multi) { this.push("selected", item); } else { this.selected = this.selectedItem = item; } } else { if (this.toggle) { this.deselectIndex(idx); } } } } /** @type {!Array} */ ArraySelectorMixin.prototype.items; /** @type {boolean} */ ArraySelectorMixin.prototype.multi; /** @type {(?Object|?Array)} */ ArraySelectorMixin.prototype.selected; /** @type {?Object} */ ArraySelectorMixin.prototype.selectedItem; /** @type {boolean} */ ArraySelectorMixin.prototype.toggle; /** @suppress {uselessCode} */ (function() { ArraySelectorMixin.prototype.__updateSelection; ArraySelectorMixin.prototype.multi; ArraySelectorMixin.prototype.items; })(); return ArraySelectorMixin; }); /** @private @constructor @extends {module$third_party$javascript$polymer$v2$polymer$polymer_element.PolymerElement} @implements {Polymer_ArraySelectorMixin} */ let baseArraySelector$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector = ArraySelectorMixin$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector(module$third_party$javascript$polymer$v2$polymer$polymer_element.PolymerElement); /** @extends {baseArraySelector$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector} @polymer @customElement */ class ArraySelector$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector extends baseArraySelector$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector { /** @return {string} */ static get is() { return "array-selector"; } static get template() { return null; } } customElements.define(ArraySelector$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector.is, ArraySelector$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector); /** @const */ var module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector = {}; /** @const */ module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector.ArraySelectorMixin = ArraySelectorMixin$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector; /** @const */ module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector.ArraySelector = ArraySelector$$module$third_party$javascript$polymer$v2$polymer$lib$elements$array_selector;