This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+64
View File
@@ -0,0 +1,64 @@
// Mixins
import { factory as GroupableFactory } from '../../mixins/groupable'; // Utilities
import mixins from '../../util/mixins';
import { consoleWarn } from '../../util/console'; // Types
import Vue from 'vue';
/* @vue/component */
export const BaseItem = Vue.extend({
props: {
activeClass: String,
value: {
required: false
}
},
data: () => ({
isActive: false
}),
methods: {
toggle() {
this.isActive = !this.isActive;
}
},
render() {
if (!this.$scopedSlots.default) {
consoleWarn('v-item is missing a default scopedSlot', this);
return null;
}
let element;
/* istanbul ignore else */
if (this.$scopedSlots.default) {
element = this.$scopedSlots.default({
active: this.isActive,
toggle: this.toggle
});
}
if (Array.isArray(element) && element.length === 1) {
element = element[0];
}
if (!element || Array.isArray(element) || !element.tag) {
consoleWarn('v-item should only contain a single element', this);
return element;
}
element.data = this._b(element.data || {}, element.tag, {
class: {
[this.activeClass]: this.isActive
}
});
return element;
}
});
export default mixins(BaseItem, GroupableFactory('itemGroup', 'v-item', 'v-item-group')).extend({
name: 'v-item'
});
//# sourceMappingURL=VItem.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/components/VItemGroup/VItem.ts"],"names":[],"mappings":"AAAA;AACA,SAAS,OAAO,IAAI,gBAApB,QAA4C,wBAA5C,C,CAEA;;AACA,OAAO,MAAP,MAAmB,mBAAnB;AACA,SAAS,WAAT,QAA4B,oBAA5B,C,CAEA;;AACA,OAAO,GAAP,MAAgB,KAAhB;AAGA;;AACA,OAAO,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAJ,CAAW;AACjC,EAAA,KAAK,EAAE;AACL,IAAA,WAAW,EAAE,MADR;AAEL,IAAA,KAAK,EAAE;AACL,MAAA,QAAQ,EAAE;AADL;AAFF,GAD0B;AAQjC,EAAA,IAAI,EAAE,OAAO;AACX,IAAA,QAAQ,EAAE;AADC,GAAP,CAR2B;AAYjC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\nimport { factory as GroupableFactory } from '../../mixins/groupable'\n\n// Utilities\nimport mixins from '../../util/mixins'\nimport { consoleWarn } from '../../util/console'\n\n// Types\nimport Vue from 'vue'\nimport { VNode, ScopedSlotChildren } from 'vue/types/vnode'\n\n/* @vue/component */\nexport const BaseItem = Vue.extend({\n props: {\n activeClass: String,\n value: {\n required: false,\n },\n },\n\n data: () => ({\n isActive: false,\n }),\n\n methods: {\n toggle () {\n this.isActive = !this.isActive\n },\n },\n\n render (): VNode {\n if (!this.$scopedSlots.default) {\n consoleWarn('v-item is missing a default scopedSlot', this)\n\n return null as any\n }\n\n let element: VNode | ScopedSlotChildren\n\n /* istanbul ignore else */\n if (this.$scopedSlots.default) {\n element = this.$scopedSlots.default({\n active: this.isActive,\n toggle: this.toggle,\n })\n }\n\n if (Array.isArray(element) && element.length === 1) {\n element = element[0]\n }\n\n if (!element || Array.isArray(element) || !element.tag) {\n consoleWarn('v-item should only contain a single element', this)\n\n return element as any\n }\n\n element.data = this._b(element.data || {}, element.tag!, {\n class: { [this.activeClass]: this.isActive },\n })\n\n return element\n },\n})\n\nexport default mixins(\n BaseItem,\n GroupableFactory('itemGroup', 'v-item', 'v-item-group')\n).extend({\n name: 'v-item',\n})\n"],"sourceRoot":"","file":"VItem.js"}
+216
View File
@@ -0,0 +1,216 @@
// Styles
import "../../../src/components/VItemGroup/VItemGroup.sass";
import Proxyable from '../../mixins/proxyable';
import Themeable from '../../mixins/themeable'; // Utilities
import mixins from '../../util/mixins';
import { consoleWarn } from '../../util/console';
export const BaseItemGroup = mixins(Proxyable, Themeable).extend({
name: 'base-item-group',
props: {
activeClass: {
type: String,
default: 'v-item--active'
},
mandatory: Boolean,
max: {
type: [Number, String],
default: null
},
multiple: Boolean
},
data() {
return {
// As long as a value is defined, show it
// Otherwise, check if multiple
// to determine which default to provide
internalLazyValue: this.value !== undefined ? this.value : this.multiple ? [] : undefined,
items: []
};
},
computed: {
classes() {
return {
'v-item-group': true,
...this.themeClasses
};
},
selectedIndex() {
return this.selectedItem && this.items.indexOf(this.selectedItem) || -1;
},
selectedItem() {
if (this.multiple) return undefined;
return this.selectedItems[0];
},
selectedItems() {
return this.items.filter((item, index) => {
return this.toggleMethod(this.getValue(item, index));
});
},
selectedValues() {
if (this.internalValue == null) return [];
return Array.isArray(this.internalValue) ? this.internalValue : [this.internalValue];
},
toggleMethod() {
if (!this.multiple) {
return v => this.internalValue === v;
}
const internalValue = this.internalValue;
if (Array.isArray(internalValue)) {
return v => internalValue.includes(v);
}
return () => false;
}
},
watch: {
internalValue: 'updateItemsState',
items: 'updateItemsState'
},
created() {
if (this.multiple && !Array.isArray(this.internalValue)) {
consoleWarn('Model must be bound to an array if the multiple property is true.', this);
}
},
methods: {
genData() {
return {
class: this.classes
};
},
getValue(item, i) {
return item.value == null || item.value === '' ? i : item.value;
},
onClick(item) {
this.updateInternalValue(this.getValue(item, this.items.indexOf(item)));
},
register(item) {
const index = this.items.push(item) - 1;
item.$on('change', () => this.onClick(item)); // If no value provided and mandatory,
// assign first registered item
if (this.mandatory && !this.selectedValues.length) {
this.updateMandatory();
}
this.updateItem(item, index);
},
unregister(item) {
if (this._isDestroyed) return;
const index = this.items.indexOf(item);
const value = this.getValue(item, index);
this.items.splice(index, 1);
const valueIndex = this.selectedValues.indexOf(value); // Items is not selected, do nothing
if (valueIndex < 0) return; // If not mandatory, use regular update process
if (!this.mandatory) {
return this.updateInternalValue(value);
} // Remove the value
if (this.multiple && Array.isArray(this.internalValue)) {
this.internalValue = this.internalValue.filter(v => v !== value);
} else {
this.internalValue = undefined;
} // If mandatory and we have no selection
// add the last item as value
/* istanbul ignore else */
if (!this.selectedItems.length) {
this.updateMandatory(true);
}
},
updateItem(item, index) {
const value = this.getValue(item, index);
item.isActive = this.toggleMethod(value);
},
// https://github.com/vuetifyjs/vuetify/issues/5352
updateItemsState() {
this.$nextTick(() => {
if (this.mandatory && !this.selectedItems.length) {
return this.updateMandatory();
} // TODO: Make this smarter so it
// doesn't have to iterate every
// child in an update
this.items.forEach(this.updateItem);
});
},
updateInternalValue(value) {
this.multiple ? this.updateMultiple(value) : this.updateSingle(value);
},
updateMandatory(last) {
if (!this.items.length) return;
const items = this.items.slice();
if (last) items.reverse();
const item = items.find(item => !item.disabled); // If no tabs are available
// aborts mandatory value
if (!item) return;
const index = this.items.indexOf(item);
this.updateInternalValue(this.getValue(item, index));
},
updateMultiple(value) {
const defaultValue = Array.isArray(this.internalValue) ? this.internalValue : [];
const internalValue = defaultValue.slice();
const index = internalValue.findIndex(val => val === value);
if (this.mandatory && // Item already exists
index > -1 && // value would be reduced below min
internalValue.length - 1 < 1) return;
if ( // Max is set
this.max != null && // Item doesn't exist
index < 0 && // value would be increased above max
internalValue.length + 1 > this.max) return;
index > -1 ? internalValue.splice(index, 1) : internalValue.push(value);
this.internalValue = internalValue;
},
updateSingle(value) {
const isSame = value === this.internalValue;
if (this.mandatory && isSame) return;
this.internalValue = isSame ? undefined : value;
}
},
render(h) {
return h('div', this.genData(), this.$slots.default);
}
});
export default BaseItemGroup.extend({
name: 'v-item-group',
provide() {
return {
itemGroup: this
};
}
});
//# sourceMappingURL=VItemGroup.js.map
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
import VItem from './VItem';
import VItemGroup from './VItemGroup';
export { VItem, VItemGroup };
export default {
$_vuetify_subcomponents: {
VItem,
VItemGroup
}
};
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/components/VItemGroup/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAP,MAAkB,SAAlB;AACA,OAAO,UAAP,MAAuB,cAAvB;AAEA,SACE,KADF,EAEE,UAFF;AAKA,eAAe;AACb,EAAA,uBAAuB,EAAE;AACvB,IAAA,KADuB;AAEvB,IAAA;AAFuB;AADZ,CAAf","sourcesContent":["import VItem from './VItem'\nimport VItemGroup from './VItemGroup'\n\nexport {\n VItem,\n VItemGroup,\n}\n\nexport default {\n $_vuetify_subcomponents: {\n VItem,\n VItemGroup,\n },\n}\n"],"sourceRoot":"","file":"index.js"}