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L,CAAY,OAApC,CAAR;AACD;AAhOM,CAHoB,CAAtB;;;eAsOQ,aAAa,CAAC,MAAd,CAAqB;AAClC,EAAA,IAAI,EAAE,cAD4B;AAGlC,EAAA,OAHkC,qBAG3B;AACL,WAAO;AACL,MAAA,SAAS,EAAE;AADN,KAAP;AAGD;AAPiC,CAArB,C","sourcesContent":["// Styles\nimport './VItemGroup.sass'\n\n// Mixins\nimport Groupable from '../../mixins/groupable'\nimport Proxyable from '../../mixins/proxyable'\nimport Themeable from '../../mixins/themeable'\n\n// Utilities\nimport mixins from '../../util/mixins'\nimport { consoleWarn } from '../../util/console'\n\n// Types\nimport { VNode } from 'vue/types'\n\nexport type GroupableInstance = InstanceType<typeof Groupable> & {\n id?: string\n to?: any\n value?: any\n }\n\nexport const BaseItemGroup = mixins(\n Proxyable,\n Themeable\n).extend({\n name: 'base-item-group',\n\n props: {\n activeClass: {\n type: String,\n default: 'v-item--active',\n },\n mandatory: Boolean,\n max: {\n type: [Number, String],\n default: null,\n },\n multiple: Boolean,\n },\n\n data () {\n return {\n // As long as a value is defined, show it\n // Otherwise, check if multiple\n // to determine which default to provide\n internalLazyValue: this.value !== undefined\n ? this.value\n : this.multiple ? [] : undefined,\n items: [] as GroupableInstance[],\n }\n },\n\n computed: {\n classes (): Record<string, boolean> {\n return {\n 'v-item-group': true,\n ...this.themeClasses,\n }\n },\n selectedItem (): GroupableInstance | undefined {\n if (this.multiple) return undefined\n\n return this.items.find((item, index) => {\n return this.toggleMethod(this.getValue(item, index))\n })\n },\n selectedItems (): GroupableInstance[] {\n return this.items.filter((item, index) => {\n return this.toggleMethod(this.getValue(item, index))\n })\n },\n selectedValues (): any[] {\n if (this.internalValue == null) return []\n\n return Array.isArray(this.internalValue)\n ? this.internalValue\n : [this.internalValue]\n },\n toggleMethod (): (v: any) => boolean {\n if (!this.multiple) {\n return (v: any) => this.internalValue === v\n }\n\n const internalValue = this.internalValue\n if (Array.isArray(internalValue)) {\n return (v: any) => internalValue.includes(v)\n }\n\n return () => false\n },\n },\n\n watch: {\n internalValue () {\n // https://github.com/vuetifyjs/vuetify/issues/5352\n this.$nextTick(this.updateItemsState)\n },\n },\n\n created () {\n if (this.multiple && !Array.isArray(this.internalValue)) {\n consoleWarn('Model must be bound to an array if the multiple property is true.', this)\n }\n },\n\n methods: {\n genData (): object {\n return {\n class: this.classes,\n }\n },\n getValue (item: GroupableInstance, i: number): unknown {\n return item.value == null || item.value === ''\n ? i\n : item.value\n },\n onClick (item: GroupableInstance) {\n this.updateInternalValue(\n this.getValue(item, this.items.indexOf(item))\n )\n },\n register (item: GroupableInstance) {\n const index = this.items.push(item) - 1\n\n item.$on('change', () => this.onClick(item))\n\n // If no value provided and mandatory,\n // assign first registered item\n if (this.mandatory && this.internalLazyValue == null) {\n this.updateMandatory()\n }\n\n this.updateItem(item, index)\n },\n unregister (item: GroupableInstance) {\n if (this._isDestroyed) return\n\n const index = this.items.indexOf(item)\n const value = this.getValue(item, index)\n\n this.items.splice(index, 1)\n\n const valueIndex = this.selectedValues.indexOf(value)\n\n // Items is not selected, do nothing\n if (valueIndex < 0) return\n\n // If not mandatory, use regular update process\n if (!this.mandatory) {\n return this.updateInternalValue(value)\n }\n\n // Remove the value\n if (this.multiple && Array.isArray(this.internalValue)) {\n this.internalValue = this.internalValue.filter(v => v !== value)\n } else {\n this.internalValue = undefined\n }\n\n // If mandatory and we have no selection\n // add the last item as value\n /* istanbul ignore else */\n if (!this.selectedItems.length) {\n this.updateMandatory(true)\n }\n },\n updateItem (item: GroupableInstance, index: number) {\n const value = this.getValue(item, index)\n\n item.isActive = this.toggleMethod(value)\n },\n updateItemsState () {\n if (this.mandatory &&\n !this.selectedItems.length\n ) {\n return this.updateMandatory()\n }\n\n // TODO: Make this smarter so it\n // doesn't have to iterate every\n // child in an update\n this.items.forEach(this.updateItem)\n },\n updateInternalValue (value: any) {\n this.multiple\n ? this.updateMultiple(value)\n : this.updateSingle(value)\n },\n updateMandatory (last?: boolean) {\n if (!this.items.length) return\n\n const items = this.items.slice()\n\n if (last) items.reverse()\n\n const item = items.find(item => !item.disabled)\n\n // If no tabs are available\n // aborts mandatory value\n if (!item) return\n\n const index = this.items.indexOf(item)\n\n this.updateInternalValue(\n this.getValue(item, index)\n )\n },\n updateMultiple (value: any) {\n const defaultValue = Array.isArray(this.internalValue)\n ? this.internalValue\n : []\n const internalValue = defaultValue.slice()\n const index = internalValue.findIndex(val => val === value)\n\n if (\n this.mandatory &&\n // Item already exists\n index > -1 &&\n // value would be reduced below min\n internalValue.length - 1 < 1\n ) return\n\n if (\n // Max is set\n this.max != null &&\n // Item doesn't exist\n index < 0 &&\n // value would be increased above max\n internalValue.length + 1 > this.max\n ) return\n\n index > -1\n ? internalValue.splice(index, 1)\n : internalValue.push(value)\n\n this.internalValue = internalValue\n },\n updateSingle (value: any) {\n const isSame = value === this.internalValue\n\n if (this.mandatory && isSame) return\n\n this.internalValue = isSame ? undefined : value\n },\n },\n\n render (h): VNode {\n return h('div', this.genData(), this.$slots.default)\n },\n})\n\nexport default BaseItemGroup.extend({\n name: 'v-item-group',\n\n provide (): object {\n return {\n itemGroup: this,\n }\n },\n})\n"],"sourceRoot":"","file":"VItemGroup.js"} |