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,cAD4B;;AAGlC,EAAA,OAAO,GAAA;AACL,WAAO;AACL,MAAA,SAAS,EAAE;AADN,KAAP;AAGD;;AAPiC,CAArB,CAAf","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"} |