[build] 0.5.7

This commit is contained in:
rex-zsd 2019-03-09 12:30:26 +08:00
parent fdb170ea3e
commit 95f77bf50d
141 changed files with 3548 additions and 3913 deletions

1
dist/action-sheet/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -24,18 +24,17 @@ VantComponent({
} }
}, },
methods: { methods: {
onSelect: function onSelect(event) { onSelect(event) {
var index = event.currentTarget.dataset.index; const { index } = event.currentTarget.dataset;
var item = this.data.actions[index]; const item = this.data.actions[index];
if (item && !item.disabled && !item.loading) { if (item && !item.disabled && !item.loading) {
this.$emit('select', item); this.$emit('select', item);
} }
}, },
onCancel: function onCancel() { onCancel() {
this.$emit('cancel'); this.$emit('cancel');
}, },
onClose: function onClose() { onClose() {
this.$emit('close'); this.$emit('close');
} }
} }

1
dist/area/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

150
dist/area/index.js vendored
View File

@ -25,182 +25,144 @@ VantComponent({
} }
}, },
data: { data: {
columns: [{ columns: [{ values: [] }, { values: [] }, { values: [] }],
values: [] displayColumns: [{ values: [] }, { values: [] }, { values: [] }]
}, {
values: []
}, {
values: []
}],
displayColumns: [{
values: []
}, {
values: []
}, {
values: []
}]
}, },
watch: { watch: {
value: function value(_value) { value(value) {
this.code = _value; this.code = value;
this.setValues(); this.setValues();
}, },
areaList: 'setValues', areaList: 'setValues',
columnsNum: function columnsNum(value) { columnsNum(value) {
this.set({ this.set({
displayColumns: this.data.columns.slice(0, +value) displayColumns: this.data.columns.slice(0, +value)
}); });
} }
}, },
methods: { methods: {
getPicker: function getPicker() { getPicker() {
if (this.picker == null) { if (this.picker == null) {
this.picker = this.selectComponent('.van-area__picker'); this.picker = this.selectComponent('.van-area__picker');
} }
return this.picker; return this.picker;
}, },
onCancel: function onCancel(event) { onCancel(event) {
this.emit('cancel', event.detail); this.emit('cancel', event.detail);
}, },
onConfirm: function onConfirm(event) { onConfirm(event) {
this.emit('confirm', event.detail); this.emit('confirm', event.detail);
}, },
emit: function emit(type, detail) { emit(type, detail) {
detail.values = detail.value; detail.values = detail.value;
delete detail.value; delete detail.value;
this.$emit(type, detail); this.$emit(type, detail);
}, },
onChange: function onChange(event) { onChange(event) {
var _this = this; const { index, picker, value } = event.detail;
var _event$detail = event.detail,
index = _event$detail.index,
picker = _event$detail.picker,
value = _event$detail.value;
this.code = value[index].code; this.code = value[index].code;
this.setValues().then(function () { this.setValues().then(() => {
_this.$emit('change', { this.$emit('change', {
picker: picker, picker,
values: picker.getValues(), values: picker.getValues(),
index: index index
}); });
}); });
}, },
getConfig: function getConfig(type) { getConfig(type) {
var areaList = this.data.areaList; const { areaList } = this.data;
return areaList && areaList[type + "_list"] || {}; return (areaList && areaList[`${type}_list`]) || {};
}, },
getList: function getList(type, code) { getList(type, code) {
var result = []; let result = [];
if (type !== 'province' && !code) { if (type !== 'province' && !code) {
return result; return result;
} }
const list = this.getConfig(type);
var list = this.getConfig(type); result = Object.keys(list).map(code => ({
result = Object.keys(list).map(function (code) { code,
return {
code: code,
name: list[code] name: list[code]
}; }));
});
if (code) { if (code) {
// oversea code // oversea code
if (code[0] === '9' && type === 'city') { if (code[0] === '9' && type === 'city') {
code = '9'; code = '9';
} }
result = result.filter(item => item.code.indexOf(code) === 0);
result = result.filter(function (item) {
return item.code.indexOf(code) === 0;
});
} }
return result; return result;
}, },
getIndex: function getIndex(type, code) { getIndex(type, code) {
var compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6; let compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
var list = this.getList(type, code.slice(0, compareNum - 2)); // oversea code const list = this.getList(type, code.slice(0, compareNum - 2));
// oversea code
if (code[0] === '9' && type === 'province') { if (code[0] === '9' && type === 'province') {
compareNum = 1; compareNum = 1;
} }
code = code.slice(0, compareNum); code = code.slice(0, compareNum);
for (let i = 0; i < list.length; i++) {
for (var i = 0; i < list.length; i++) {
if (list[i].code.slice(0, compareNum) === code) { if (list[i].code.slice(0, compareNum) === code) {
return i; return i;
} }
} }
return 0; return 0;
}, },
setValues: function setValues() { setValues() {
var _this2 = this; const county = this.getConfig('county');
let code = this.code || Object.keys(county)[0] || '';
var county = this.getConfig('county'); const province = this.getList('province');
var code = this.code || Object.keys(county)[0] || ''; const city = this.getList('city', code.slice(0, 2));
var province = this.getList('province'); const picker = this.getPicker();
var city = this.getList('city', code.slice(0, 2));
var picker = this.getPicker();
if (!picker) { if (!picker) {
return; return;
} }
const stack = [];
var stack = [];
stack.push(picker.setColumnValues(0, province, false)); stack.push(picker.setColumnValues(0, province, false));
stack.push(picker.setColumnValues(1, city, false)); stack.push(picker.setColumnValues(1, city, false));
if (city.length && code.slice(2, 4) === '00') { if (city.length && code.slice(2, 4) === '00') {
; ;
code = city[0].code; [{ code }] = city;
} }
stack.push(picker.setColumnValues(2, this.getList('county', code.slice(0, 4)), false)); stack.push(picker.setColumnValues(2, this.getList('county', code.slice(0, 4)), false));
return Promise.all(stack).then(function () { return Promise.all(stack)
return picker.setIndexes([_this2.getIndex('province', code), _this2.getIndex('city', code), _this2.getIndex('county', code)]); .catch(() => { })
}).catch(function () {}); .then(() => picker.setIndexes([
this.getIndex('province', code),
this.getIndex('city', code),
this.getIndex('county', code)
]))
.catch(() => { });
}, },
getValues: function getValues() { getValues() {
var picker = this.getPicker(); const picker = this.getPicker();
return picker ? picker.getValues().filter(function (value) { return picker ? picker.getValues().filter(value => !!value) : [];
return !!value;
}) : [];
}, },
getDetail: function getDetail() { getDetail() {
var values = this.getValues(); const values = this.getValues();
var area = { const area = {
code: '', code: '',
country: '', country: '',
province: '', province: '',
city: '', city: '',
county: '' county: ''
}; };
if (!values.length) { if (!values.length) {
return area; return area;
} }
const names = values.map((item) => item.name);
var names = values.map(function (item) {
return item.name;
});
area.code = values[values.length - 1].code; area.code = values[values.length - 1].code;
if (area.code[0] === '9') { if (area.code[0] === '9') {
area.country = names[1] || ''; area.country = names[1] || '';
area.province = names[2] || ''; area.province = names[2] || '';
} else { }
else {
area.province = names[0] || ''; area.province = names[0] || '';
area.city = names[1] || ''; area.city = names[1] || '';
area.county = names[2] || ''; area.county = names[2] || '';
} }
return area; return area;
}, },
reset: function reset() { reset() {
this.code = ''; this.code = '';
return this.setValues(); return this.setValues();
} }

1
dist/badge-group/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -4,14 +4,12 @@ VantComponent({
relation: { relation: {
name: 'badge', name: 'badge',
type: 'descendant', type: 'descendant',
linked: function linked(target) { linked(target) {
this.badges.push(target); this.badges.push(target);
this.setActive(); this.setActive();
}, },
unlinked: function unlinked(target) { unlinked(target) {
this.badges = this.badges.filter(function (item) { this.badges = this.badges.filter(item => item !== target);
return item !== target;
});
this.setActive(); this.setActive();
} }
}, },
@ -24,28 +22,24 @@ VantComponent({
watch: { watch: {
active: 'setActive' active: 'setActive'
}, },
beforeCreate: function beforeCreate() { beforeCreate() {
this.badges = []; this.badges = [];
this.currentActive = -1; this.currentActive = -1;
}, },
methods: { methods: {
setActive: function setActive(badge) { setActive(badge) {
var active = this.data.active; let { active } = this.data;
var badges = this.badges; const { badges } = this;
if (badge && !isNumber(badge)) { if (badge && !isNumber(badge)) {
active = badges.indexOf(badge); active = badges.indexOf(badge);
} }
if (active === this.currentActive) { if (active === this.currentActive) {
return; return;
} }
if (this.currentActive !== -1 && badges[this.currentActive]) { if (this.currentActive !== -1 && badges[this.currentActive]) {
this.$emit('change', active); this.$emit('change', active);
badges[this.currentActive].setActive(false); badges[this.currentActive].setActive(false);
} }
if (badges[active]) { if (badges[active]) {
badges[active].setActive(true); badges[active].setActive(true);
this.currentActive = active; this.currentActive = active;

1
dist/badge/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

11
dist/badge/index.js vendored
View File

@ -9,17 +9,14 @@ VantComponent({
title: String title: String
}, },
methods: { methods: {
onClick: function onClick() { onClick() {
var group = this.getRelationNodes('../badge-group/index')[0]; const group = this.getRelationNodes('../badge-group/index')[0];
if (group) { if (group) {
group.setActive(this); group.setActive(this);
} }
}, },
setActive: function setActive(active) { setActive(active) {
this.set({ this.set({ active });
active: active
});
} }
} }
}); });

1
dist/button/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -26,7 +26,7 @@ VantComponent({
} }
}, },
methods: { methods: {
onClick: function onClick() { onClick() {
if (!this.data.disabled && !this.data.loading) { if (!this.data.disabled && !this.data.loading) {
this.$emit('click'); this.$emit('click');
} }

1
dist/card/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

11
dist/card/index.js vendored
View File

@ -1,7 +1,14 @@
import { link } from '../mixins/link'; import { link } from '../mixins/link';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: ['num-class', 'desc-class', 'thumb-class', 'title-class', 'price-class', 'origin-price-class'], classes: [
'num-class',
'desc-class',
'thumb-class',
'title-class',
'price-class',
'origin-price-class',
],
mixins: [link], mixins: [link],
props: { props: {
tag: String, tag: String,
@ -24,7 +31,7 @@ VantComponent({
} }
}, },
methods: { methods: {
onClickThumb: function onClickThumb() { onClickThumb() {
this.jumpLink('thumbLink'); this.jumpLink('thumbLink');
} }
} }

1
dist/cell-group/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

1
dist/cell/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

10
dist/cell/index.js vendored
View File

@ -1,7 +1,13 @@
import { link } from '../mixins/link'; import { link } from '../mixins/link';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: ['title-class', 'label-class', 'value-class', 'right-icon-class', 'hover-class'], classes: [
'title-class',
'label-class',
'value-class',
'right-icon-class',
'hover-class'
],
mixins: [link], mixins: [link],
props: { props: {
title: null, title: null,
@ -22,7 +28,7 @@ VantComponent({
} }
}, },
methods: { methods: {
onClick: function onClick(event) { onClick(event) {
this.$emit('click', event.detail); this.$emit('click', event.detail);
this.jumpLink(); this.jumpLink();
} }

1
dist/checkbox-group/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -4,10 +4,8 @@ VantComponent({
relation: { relation: {
name: 'checkbox', name: 'checkbox',
type: 'descendant', type: 'descendant',
linked: function linked(target) { linked(target) {
var _this$data = this.data, const { value, disabled } = this.data;
value = _this$data.value,
disabled = _this$data.disabled;
target.set({ target.set({
value: value.indexOf(target.data.name) !== -1, value: value.indexOf(target.data.name) !== -1,
disabled: disabled || target.data.disabled disabled: disabled || target.data.disabled
@ -20,20 +18,16 @@ VantComponent({
disabled: Boolean disabled: Boolean
}, },
watch: { watch: {
value: function value(_value) { value(value) {
var children = this.getRelationNodes('../checkbox/index'); const children = this.getRelationNodes('../checkbox/index');
children.forEach(function (child) { children.forEach(child => {
child.set({ child.set({ value: value.indexOf(child.data.name) !== -1 });
value: _value.indexOf(child.data.name) !== -1
});
}); });
}, },
disabled: function disabled(_disabled) { disabled(disabled) {
var children = this.getRelationNodes('../checkbox/index'); const children = this.getRelationNodes('../checkbox/index');
children.forEach(function (child) { children.forEach(child => {
child.set({ child.set({ disabled: disabled || child.data.disabled });
disabled: _disabled || child.data.disabled
});
}); });
} }
} }

1
dist/checkbox/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -19,46 +19,43 @@ VantComponent({
} }
}, },
methods: { methods: {
emitChange: function emitChange(value) { emitChange(value) {
var parent = this.getRelationNodes('../checkbox-group/index')[0]; const parent = this.getRelationNodes('../checkbox-group/index')[0];
if (parent) { if (parent) {
this.setParentValue(parent, value); this.setParentValue(parent, value);
} else { }
else {
this.$emit('input', value); this.$emit('input', value);
this.$emit('change', value); this.$emit('change', value);
} }
}, },
toggle: function toggle() { toggle() {
if (!this.data.disabled) { if (!this.data.disabled) {
this.emitChange(!this.data.value); this.emitChange(!this.data.value);
} }
}, },
onClickLabel: function onClickLabel() { onClickLabel() {
if (!this.data.disabled && !this.data.labelDisabled) { if (!this.data.disabled && !this.data.labelDisabled) {
this.emitChange(!this.data.value); this.emitChange(!this.data.value);
} }
}, },
setParentValue: function setParentValue(parent, value) { setParentValue(parent, value) {
var parentValue = parent.data.value.slice(); const parentValue = parent.data.value.slice();
var name = this.data.name; const { name } = this.data;
if (value) { if (value) {
if (parent.data.max && parentValue.length >= parent.data.max) { if (parent.data.max && parentValue.length >= parent.data.max) {
return; return;
} }
/* istanbul ignore else */ /* istanbul ignore else */
if (parentValue.indexOf(name) === -1) { if (parentValue.indexOf(name) === -1) {
parentValue.push(name); parentValue.push(name);
parent.$emit('input', parentValue); parent.$emit('input', parentValue);
parent.$emit('change', parentValue); parent.$emit('change', parentValue);
} }
} else { }
var index = parentValue.indexOf(name); else {
const index = parentValue.indexOf(name);
/* istanbul ignore else */ /* istanbul ignore else */
if (index !== -1) { if (index !== -1) {
parentValue.splice(index, 1); parentValue.splice(index, 1);
parent.$emit('input', parentValue); parent.$emit('input', parentValue);

1
dist/col/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

11
dist/col/index.js vendored
View File

@ -12,14 +12,11 @@ VantComponent({
style: '' style: ''
}, },
methods: { methods: {
setGutter: function setGutter(gutter) { setGutter(gutter) {
var padding = gutter / 2 + "px"; const padding = `${gutter / 2}px`;
var style = gutter ? "padding-left: " + padding + "; padding-right: " + padding + ";" : ''; const style = gutter ? `padding-left: ${padding}; padding-right: ${padding};` : '';
if (style !== this.data.style) { if (style !== this.data.style) {
this.set({ this.set({ style });
style: style
});
} }
} }
} }

1
dist/collapse-item/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -4,7 +4,7 @@ VantComponent({
relation: { relation: {
name: 'collapse', name: 'collapse',
type: 'ancestor', type: 'ancestor',
linked: function linked(parent) { linked(parent) {
this.parent = parent; this.parent = parent;
} }
}, },
@ -28,73 +28,59 @@ VantComponent({
contentHeight: 0, contentHeight: 0,
expanded: false expanded: false
}, },
beforeCreate: function beforeCreate() { beforeCreate() {
this.animation = wx.createAnimation({ this.animation = wx.createAnimation({
duration: 300, duration: 300,
timingFunction: 'ease-in-out' timingFunction: 'ease-in-out'
}); });
}, },
methods: { methods: {
updateExpanded: function updateExpanded() { updateExpanded() {
if (!this.parent) { if (!this.parent) {
return null; return null;
} }
const { value, accordion, items } = this.parent.data;
var _this$parent$data = this.parent.data, const { name } = this.data;
value = _this$parent$data.value, const index = items.indexOf(this);
accordion = _this$parent$data.accordion, const currentName = name == null ? index : name;
items = _this$parent$data.items; const expanded = accordion
var name = this.data.name; ? value === currentName
var index = items.indexOf(this); : value.some(name => name === currentName);
var currentName = name == null ? index : name;
var expanded = accordion ? value === currentName : value.some(function (name) {
return name === currentName;
});
if (expanded !== this.data.expanded) { if (expanded !== this.data.expanded) {
this.updateStyle(expanded); this.updateStyle(expanded);
} }
this.set({ expanded });
this.set({
expanded: expanded
});
}, },
updateStyle: function updateStyle(expanded) { updateStyle(expanded) {
var _this = this; this.getRect('.van-collapse-item__content').then(res => {
const animationData = this.animation
this.getRect('.van-collapse-item__content').then(function (res) { .height(expanded ? res.height : 0)
var animationData = _this.animation.height(expanded ? res.height : 0).step().export(); .step()
.export();
if (expanded) { if (expanded) {
_this.set({ this.set({ animationData });
animationData: animationData }
}); else {
} else { this.set({
_this.set({
contentHeight: res.height + 'px' contentHeight: res.height + 'px'
}, function () { }, () => {
setTimeout(function () { setTimeout(() => {
_this.set({ this.set({ animationData });
animationData: animationData
});
}, 20); }, 20);
}); });
} }
}); });
}, },
onClick: function onClick() { onClick() {
if (this.data.disabled) { if (this.data.disabled) {
return; return;
} }
const { name, expanded } = this.data;
var _this$data = this.data, const index = this.parent.data.items.indexOf(this);
name = _this$data.name, const currentName = name == null ? index : name;
expanded = _this$data.expanded;
var index = this.parent.data.items.indexOf(this);
var currentName = name == null ? index : name;
this.parent.switch(currentName, !expanded); this.parent.switch(currentName, !expanded);
}, },
onTransitionEnd: function onTransitionEnd() { onTransitionEnd() {
if (this.data.expanded) { if (this.data.expanded) {
this.set({ this.set({
contentHeight: 'auto' contentHeight: 'auto'

1
dist/collapse/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -3,10 +3,10 @@ VantComponent({
relation: { relation: {
name: 'collapse-item', name: 'collapse-item',
type: 'descendant', type: 'descendant',
linked: function linked(child) { linked(child) {
this.set({ this.set({
items: [].concat(this.data.items, [child]) items: [...this.data.items, child]
}, function () { }, () => {
child.updateExpanded(); child.updateExpanded();
}); });
} }
@ -19,31 +19,28 @@ VantComponent({
items: [] items: []
}, },
watch: { watch: {
value: function value() { value() {
this.data.items.forEach(function (child) { this.data.items.forEach(child => {
child.updateExpanded(); child.updateExpanded();
}); });
}, },
accordion: function accordion() { accordion() {
this.data.items.forEach(function (child) { this.data.items.forEach(child => {
child.updateExpanded(); child.updateExpanded();
}); });
} }
}, },
methods: { methods: {
switch: function _switch(name, expanded) { switch(name, expanded) {
var _this$data = this.data, const { accordion, value } = this.data;
accordion = _this$data.accordion,
value = _this$data.value;
if (!accordion) { if (!accordion) {
name = expanded ? value.concat(name) : value.filter(function (activeName) { name = expanded
return activeName !== name; ? value.concat(name)
}); : value.filter(activeName => activeName !== name);
} else { }
else {
name = expanded ? name : ''; name = expanded ? name : '';
} }
this.$emit('change', name); this.$emit('change', name);
this.$emit('input', name); this.$emit('input', name);
} }

3
dist/common/color.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export declare const RED = "#f44";
export declare const BLUE = "#1989fa";
export declare const GREEN = "#07c160";

View File

@ -1,3 +1,3 @@
export var RED = '#f44'; export const RED = '#f44';
export var BLUE = '#1989fa'; export const BLUE = '#1989fa';
export var GREEN = '#07c160'; export const GREEN = '#07c160';

2
dist/common/component.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
declare function VantComponent<Data, Props, Watch, Methods, Computed>(vantOptions?: VantComponentOptions<Data, Props, Watch, Methods, Computed, CombinedComponentInstance<Data, Props, Watch, Methods, Computed>>): void;
export { VantComponent };

View File

@ -1,20 +1,14 @@
import { basic } from '../mixins/basic'; import { basic } from '../mixins/basic';
import { observe } from '../mixins/observer/index'; import { observe } from '../mixins/observer/index';
function mapKeys(source, target, map) { function mapKeys(source, target, map) {
Object.keys(map).forEach(function (key) { Object.keys(map).forEach(key => {
if (source[key]) { if (source[key]) {
target[map[key]] = source[key]; target[map[key]] = source[key];
} }
}); });
} }
function VantComponent(vantOptions = {}) {
function VantComponent(vantOptions) { const options = {};
if (vantOptions === void 0) {
vantOptions = {};
}
var options = {};
mapKeys(vantOptions, options, { mapKeys(vantOptions, options, {
data: 'data', data: 'data',
props: 'properties', props: 'properties',
@ -27,27 +21,23 @@ function VantComponent(vantOptions) {
destroyed: 'detached', destroyed: 'detached',
classes: 'externalClasses' classes: 'externalClasses'
}); });
var _vantOptions = vantOptions, const { relation } = vantOptions;
relation = _vantOptions.relation;
if (relation) { if (relation) {
options.relations = Object.assign(options.relations || {}, { options.relations = Object.assign(options.relations || {}, {
["../" + relation.name + "/index"]: relation [`../${relation.name}/index`]: relation
}); });
} // add default externalClasses }
// add default externalClasses
options.externalClasses = options.externalClasses || []; options.externalClasses = options.externalClasses || [];
options.externalClasses.push('custom-class'); // add default behaviors options.externalClasses.push('custom-class');
// add default behaviors
options.behaviors = options.behaviors || []; options.behaviors = options.behaviors || [];
options.behaviors.push(basic); // map field to form-field behavior options.behaviors.push(basic);
// map field to form-field behavior
if (vantOptions.field) { if (vantOptions.field) {
options.behaviors.push('wx://form-field'); options.behaviors.push('wx://form-field');
} // add default options }
// add default options
options.options = { options.options = {
multipleSlots: true, multipleSlots: true,
addGlobalClass: true addGlobalClass: true
@ -55,5 +45,4 @@ function VantComponent(vantOptions) {
observe(vantOptions, options); observe(vantOptions, options);
Component(options); Component(options);
} }
export { VantComponent }; export { VantComponent };

5
dist/common/utils.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
declare function isDef(value: any): boolean;
declare function isObj(x: any): boolean;
declare function isNumber(value: any): boolean;
declare function range(num: number, min: number, max: number): number;
export { isObj, isDef, isNumber, range };

View File

@ -1,18 +1,14 @@
function isDef(value) { function isDef(value) {
return value !== undefined && value !== null; return value !== undefined && value !== null;
} }
function isObj(x) { function isObj(x) {
var type = typeof x; const type = typeof x;
return x !== null && (type === 'object' || type === 'function'); return x !== null && (type === 'object' || type === 'function');
} }
function isNumber(value) { function isNumber(value) {
return /^\d+$/.test(value); return /^\d+$/.test(value);
} }
function range(num, min, max) { function range(num, min, max) {
return Math.min(Math.max(num, min), max); return Math.min(Math.max(num, min), max);
} }
export { isObj, isDef, isNumber, range }; export { isObj, isDef, isNumber, range };

1
dist/datetime-picker/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,44 +1,34 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isDef } from '../common/utils'; import { isDef } from '../common/utils';
var currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
function isValidDate(date) { function isValidDate(date) {
return isDef(date) && !isNaN(new Date(date).getTime()); return isDef(date) && !isNaN(new Date(date).getTime());
} }
function range(num, min, max) { function range(num, min, max) {
return Math.min(Math.max(num, min), max); return Math.min(Math.max(num, min), max);
} }
function padZero(val) { function padZero(val) {
return ("00" + val).slice(-2); return `00${val}`.slice(-2);
} }
function times(n, iteratee) { function times(n, iteratee) {
var index = -1; let index = -1;
var result = Array(n); const result = Array(n);
while (++index < n) { while (++index < n) {
result[index] = iteratee(index); result[index] = iteratee(index);
} }
return result; return result;
} }
function getTrueValue(formattedValue) { function getTrueValue(formattedValue) {
if (!formattedValue) return; if (!formattedValue)
return;
while (isNaN(parseInt(formattedValue, 10))) { while (isNaN(parseInt(formattedValue, 10))) {
formattedValue = formattedValue.slice(1); formattedValue = formattedValue.slice(1);
} }
return parseInt(formattedValue, 10); return parseInt(formattedValue, 10);
} }
function getMonthEndDay(year, month) { function getMonthEndDay(year, month) {
return 32 - new Date(year, month - 1, 32).getDate(); return 32 - new Date(year, month - 1, 32).getDate();
} }
VantComponent({ VantComponent({
props: { props: {
value: null, value: null,
@ -98,16 +88,13 @@ VantComponent({
columns: [] columns: []
}, },
watch: { watch: {
value: function value(val) { value(val) {
var _this = this; const { data } = this;
var data = this.data;
val = this.correctValue(val); val = this.correctValue(val);
var isEqual = val === data.innerValue; const isEqual = val === data.innerValue;
if (!isEqual) { if (!isEqual) {
this.updateColumnValue(val).then(function () { this.updateColumnValue(val).then(() => {
_this.$emit('input', val); this.$emit('input', val);
}); });
} }
}, },
@ -118,238 +105,191 @@ VantComponent({
maxMinute: 'updateColumns' maxMinute: 'updateColumns'
}, },
methods: { methods: {
getPicker: function getPicker() { getPicker() {
if (this.picker == null) { if (this.picker == null) {
var picker = this.picker = this.selectComponent('.van-datetime-picker'); const picker = this.picker = this.selectComponent('.van-datetime-picker');
var setColumnValues = picker.setColumnValues; const { setColumnValues } = picker;
picker.setColumnValues = (...args) => setColumnValues.apply(picker, [...args, false]);
picker.setColumnValues = function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
} }
return setColumnValues.apply(picker, [].concat(args, [false]));
};
}
return this.picker; return this.picker;
}, },
updateColumns: function updateColumns() { updateColumns() {
var results = this.getRanges().map(function (_ref, index) { const results = this.getRanges().map(({ type, range }, index) => {
var type = _ref.type, const values = times(range[1] - range[0] + 1, index => {
range = _ref.range; let value = range[0] + index;
var values = times(range[1] - range[0] + 1, function (index) { value = type === 'year' ? `${value}` : padZero(value);
var value = range[0] + index;
value = type === 'year' ? "" + value : padZero(value);
return value; return value;
}); });
return { return { values };
values: values
};
});
return this.set({
columns: results
}); });
return this.set({ columns: results });
}, },
getRanges: function getRanges() { getRanges() {
var data = this.data; const { data } = this;
if (data.type === 'time') { if (data.type === 'time') {
return [{ return [
{
type: 'hour', type: 'hour',
range: [data.minHour, data.maxHour] range: [data.minHour, data.maxHour]
}, { },
{
type: 'minute', type: 'minute',
range: [data.minMinute, data.maxMinute] range: [data.minMinute, data.maxMinute]
}];
} }
];
var _this$getBoundary = this.getBoundary('max', data.innerValue), }
maxYear = _this$getBoundary.maxYear, const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = this.getBoundary('max', data.innerValue);
maxDate = _this$getBoundary.maxDate, const { minYear, minDate, minMonth, minHour, minMinute } = this.getBoundary('min', data.innerValue);
maxMonth = _this$getBoundary.maxMonth, const result = [
maxHour = _this$getBoundary.maxHour, {
maxMinute = _this$getBoundary.maxMinute;
var _this$getBoundary2 = this.getBoundary('min', data.innerValue),
minYear = _this$getBoundary2.minYear,
minDate = _this$getBoundary2.minDate,
minMonth = _this$getBoundary2.minMonth,
minHour = _this$getBoundary2.minHour,
minMinute = _this$getBoundary2.minMinute;
var result = [{
type: 'year', type: 'year',
range: [minYear, maxYear] range: [minYear, maxYear]
}, { },
{
type: 'month', type: 'month',
range: [minMonth, maxMonth] range: [minMonth, maxMonth]
}, { },
{
type: 'day', type: 'day',
range: [minDate, maxDate] range: [minDate, maxDate]
}, { },
{
type: 'hour', type: 'hour',
range: [minHour, maxHour] range: [minHour, maxHour]
}, { },
{
type: 'minute', type: 'minute',
range: [minMinute, maxMinute] range: [minMinute, maxMinute]
}]; }
if (data.type === 'date') result.splice(3, 2); ];
if (data.type === 'year-month') result.splice(2, 3); if (data.type === 'date')
result.splice(3, 2);
if (data.type === 'year-month')
result.splice(2, 3);
return result; return result;
}, },
correctValue: function correctValue(value) { correctValue(value) {
var data = this.data; // validate value const { data } = this;
// validate value
var isDateType = data.type !== 'time'; const isDateType = data.type !== 'time';
if (isDateType && !isValidDate(value)) { if (isDateType && !isValidDate(value)) {
value = data.minDate; value = data.minDate;
} else if (!isDateType && !value) { }
var minHour = data.minHour; else if (!isDateType && !value) {
value = padZero(minHour) + ":00"; const { minHour } = data;
} // time type value = `${padZero(minHour)}:00`;
}
// time type
if (!isDateType) { if (!isDateType) {
var _value$split = value.split(':'), let [hour, minute] = value.split(':');
hour = _value$split[0],
minute = _value$split[1];
hour = padZero(range(hour, data.minHour, data.maxHour)); hour = padZero(range(hour, data.minHour, data.maxHour));
minute = padZero(range(minute, data.minMinute, data.maxMinute)); minute = padZero(range(minute, data.minMinute, data.maxMinute));
return hour + ":" + minute; return `${hour}:${minute}`;
} // date type }
// date type
value = Math.max(value, data.minDate); value = Math.max(value, data.minDate);
value = Math.min(value, data.maxDate); value = Math.min(value, data.maxDate);
return value; return value;
}, },
getBoundary: function getBoundary(type, innerValue) { getBoundary(type, innerValue) {
var value = new Date(innerValue); const value = new Date(innerValue);
var boundary = new Date(this.data[type + "Date"]); const boundary = new Date(this.data[`${type}Date`]);
var year = boundary.getFullYear(); const year = boundary.getFullYear();
var month = 1; let month = 1;
var date = 1; let date = 1;
var hour = 0; let hour = 0;
var minute = 0; let minute = 0;
if (type === 'max') { if (type === 'max') {
month = 12; month = 12;
date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1); date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1);
hour = 23; hour = 23;
minute = 59; minute = 59;
} }
if (value.getFullYear() === year) { if (value.getFullYear() === year) {
month = boundary.getMonth() + 1; month = boundary.getMonth() + 1;
if (value.getMonth() + 1 === month) { if (value.getMonth() + 1 === month) {
date = boundary.getDate(); date = boundary.getDate();
if (value.getDate() === date) { if (value.getDate() === date) {
hour = boundary.getHours(); hour = boundary.getHours();
if (value.getHours() === hour) { if (value.getHours() === hour) {
minute = boundary.getMinutes(); minute = boundary.getMinutes();
} }
} }
} }
} }
return { return {
[type + "Year"]: year, [`${type}Year`]: year,
[type + "Month"]: month, [`${type}Month`]: month,
[type + "Date"]: date, [`${type}Date`]: date,
[type + "Hour"]: hour, [`${type}Hour`]: hour,
[type + "Minute"]: minute [`${type}Minute`]: minute
}; };
}, },
onCancel: function onCancel() { onCancel() {
this.$emit('cancel'); this.$emit('cancel');
}, },
onConfirm: function onConfirm() { onConfirm() {
this.$emit('confirm', this.data.innerValue); this.$emit('confirm', this.data.innerValue);
}, },
onChange: function onChange() { onChange() {
var _this2 = this; const { data } = this;
let value;
var data = this.data; const picker = this.getPicker();
var value;
var picker = this.getPicker();
if (data.type === 'time') { if (data.type === 'time') {
var indexes = picker.getIndexes(); const indexes = picker.getIndexes();
value = indexes[0] + data.minHour + ":" + (indexes[1] + data.minMinute); value = `${indexes[0] + data.minHour}:${indexes[1] + data.minMinute}`;
} else { }
var values = picker.getValues(); else {
var year = getTrueValue(values[0]); const values = picker.getValues();
var month = getTrueValue(values[1]); const year = getTrueValue(values[0]);
var maxDate = getMonthEndDay(year, month); const month = getTrueValue(values[1]);
var date = getTrueValue(values[2]); const maxDate = getMonthEndDay(year, month);
let date = getTrueValue(values[2]);
if (data.type === 'year-month') { if (data.type === 'year-month') {
date = 1; date = 1;
} }
date = date > maxDate ? maxDate : date; date = date > maxDate ? maxDate : date;
var hour = 0; let hour = 0;
var minute = 0; let minute = 0;
if (data.type === 'datetime') { if (data.type === 'datetime') {
hour = getTrueValue(values[3]); hour = getTrueValue(values[3]);
minute = getTrueValue(values[4]); minute = getTrueValue(values[4]);
} }
value = new Date(year, month - 1, date, hour, minute); value = new Date(year, month - 1, date, hour, minute);
} }
value = this.correctValue(value); value = this.correctValue(value);
this.updateColumnValue(value).then(function () { this.updateColumnValue(value).then(() => {
_this2.$emit('input', value); this.$emit('input', value);
this.$emit('change', picker);
_this2.$emit('change', picker);
}); });
}, },
updateColumnValue: function updateColumnValue(value) { updateColumnValue(value) {
var _this3 = this; let values = [];
const { data } = this;
var values = []; const picker = this.getPicker();
var data = this.data;
var picker = this.getPicker();
if (data.type === 'time') { if (data.type === 'time') {
var pair = value.split(':'); const pair = value.split(':');
values = [pair[0], pair[1]]; values = [pair[0], pair[1]];
} else { }
var date = new Date(value); else {
values = ["" + date.getFullYear(), padZero(date.getMonth() + 1)]; const date = new Date(value);
values = [`${date.getFullYear()}`, padZero(date.getMonth() + 1)];
if (data.type === 'date') { if (data.type === 'date') {
values.push(padZero(date.getDate())); values.push(padZero(date.getDate()));
} }
if (data.type === 'datetime') { if (data.type === 'datetime') {
values.push(padZero(date.getDate()), padZero(date.getHours()), padZero(date.getMinutes())); values.push(padZero(date.getDate()), padZero(date.getHours()), padZero(date.getMinutes()));
} }
} }
return this.set({ innerValue: value })
return this.set({ .then(() => this.updateColumns())
innerValue: value .then(() => picker.setValues(values));
}).then(function () {
return _this3.updateColumns();
}).then(function () {
return picker.setValues(values);
});
} }
}, },
created: function created() { created() {
var _this4 = this; const innerValue = this.correctValue(this.data.value);
this.updateColumnValue(innerValue).then(() => {
var innerValue = this.correctValue(this.data.value); this.$emit('input', innerValue);
this.updateColumnValue(innerValue).then(function () {
_this4.$emit('input', innerValue);
}); });
} }
}); });

42
dist/dialog/dialog.d.ts vendored Normal file
View File

@ -0,0 +1,42 @@
declare type DialogAction = 'confirm' | 'cancel';
declare type DialogOptions = {
lang?: string;
show?: boolean;
title?: string;
zIndex?: number;
context?: any;
message?: string;
overlay?: boolean;
selector?: string;
ariaLabel?: string;
transition?: string;
asyncClose?: boolean;
businessId?: number;
sessionFrom?: string;
appParameter?: string;
messageAlign?: string;
sendMessageImg?: string;
showMessageCard?: boolean;
sendMessagePath?: string;
sendMessageTitle?: string;
confirmButtonText?: string;
cancelButtonText?: string;
showConfirmButton?: boolean;
showCancelButton?: boolean;
closeOnClickOverlay?: boolean;
confirmButtonOpenType?: string;
};
interface Dialog {
(options: DialogOptions): Promise<DialogAction>;
alert?: (options: DialogOptions) => Promise<DialogAction>;
confirm?: (options: DialogOptions) => Promise<DialogAction>;
close?: () => void;
stopLoading?: () => void;
install?: () => void;
setDefaultOptions?: (options: DialogOptions) => void;
resetDefaultOptions?: () => void;
defaultOptions?: DialogOptions;
currentOptions?: DialogOptions;
}
declare const Dialog: Dialog;
export default Dialog;

54
dist/dialog/dialog.js vendored
View File

@ -1,31 +1,23 @@
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } let queue = [];
var queue = [];
function getContext() { function getContext() {
var pages = getCurrentPages(); const pages = getCurrentPages();
return pages[pages.length - 1]; return pages[pages.length - 1];
} }
const Dialog = options => {
var Dialog = function Dialog(options) { options = Object.assign({}, Dialog.currentOptions, options);
options = _extends({}, Dialog.currentOptions, options); return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) { const context = options.context || getContext();
var context = options.context || getContext(); const dialog = context.selectComponent(options.selector);
var dialog = context.selectComponent(options.selector);
delete options.selector; delete options.selector;
if (dialog) { if (dialog) {
dialog.set(_extends({ dialog.set(Object.assign({ onCancel: reject, onConfirm: resolve }, options));
onCancel: reject,
onConfirm: resolve
}, options));
queue.push(dialog); queue.push(dialog);
} else { }
else {
console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确'); console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确');
} }
}); });
}; };
Dialog.defaultOptions = { Dialog.defaultOptions = {
show: true, show: true,
title: '', title: '',
@ -44,33 +36,23 @@ Dialog.defaultOptions = {
confirmButtonOpenType: '' confirmButtonOpenType: ''
}; };
Dialog.alert = Dialog; Dialog.alert = Dialog;
Dialog.confirm = options => Dialog(Object.assign({ showCancelButton: true }, options));
Dialog.confirm = function (options) { Dialog.close = () => {
return Dialog(_extends({ queue.forEach(dialog => {
showCancelButton: true
}, options));
};
Dialog.close = function () {
queue.forEach(function (dialog) {
dialog.close(); dialog.close();
}); });
queue = []; queue = [];
}; };
Dialog.stopLoading = () => {
Dialog.stopLoading = function () { queue.forEach(dialog => {
queue.forEach(function (dialog) {
dialog.stopLoading(); dialog.stopLoading();
}); });
}; };
Dialog.setDefaultOptions = options => {
Dialog.setDefaultOptions = function (options) {
Object.assign(Dialog.currentOptions, options); Object.assign(Dialog.currentOptions, options);
}; };
Dialog.resetDefaultOptions = () => {
Dialog.resetDefaultOptions = function () { Dialog.currentOptions = Object.assign({}, Dialog.defaultOptions);
Dialog.currentOptions = _extends({}, Dialog.defaultOptions);
}; };
Dialog.resetDefaultOptions(); Dialog.resetDefaultOptions();
export default Dialog; export default Dialog;

1
dist/dialog/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

33
dist/dialog/index.js vendored
View File

@ -45,35 +45,34 @@ VantComponent({
} }
}, },
watch: { watch: {
show: function show(_show) { show(show) {
!_show && this.stopLoading(); !show && this.stopLoading();
} }
}, },
methods: { methods: {
onConfirm: function onConfirm() { onConfirm() {
this.handleAction('confirm'); this.handleAction('confirm');
}, },
onCancel: function onCancel() { onCancel() {
this.handleAction('cancel'); this.handleAction('cancel');
}, },
onClickOverlay: function onClickOverlay() { onClickOverlay() {
this.onClose('overlay'); this.onClose('overlay');
}, },
handleAction: function handleAction(action) { handleAction(action) {
if (this.data.asyncClose) { if (this.data.asyncClose) {
this.set({ this.set({
["loading." + action]: true [`loading.${action}`]: true
}); });
} }
this.onClose(action); this.onClose(action);
}, },
close: function close() { close() {
this.set({ this.set({
show: false show: false
}); });
}, },
stopLoading: function stopLoading() { stopLoading() {
this.set({ this.set({
loading: { loading: {
confirm: false, confirm: false,
@ -81,18 +80,14 @@ VantComponent({
} }
}); });
}, },
onClose: function onClose(action) { onClose(action) {
if (!this.data.asyncClose) { if (!this.data.asyncClose) {
this.close(); this.close();
} }
this.$emit('close', action);
this.$emit('close', action); //把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading //把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading
this.$emit(action, { dialog: this });
this.$emit(action, { const callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];
dialog: this
});
var callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];
if (callback) { if (callback) {
callback(this); callback(this);
} }

1
dist/field/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

85
dist/field/index.js vendored
View File

@ -3,6 +3,7 @@ VantComponent({
field: true, field: true,
classes: ['input-class'], classes: ['input-class'],
props: { props: {
size: String,
icon: String, icon: String,
label: String, label: String,
error: Boolean, error: Boolean,
@ -59,95 +60,69 @@ VantComponent({
data: { data: {
showClear: false showClear: false
}, },
beforeCreate: function beforeCreate() { beforeCreate() {
this.focused = false; this.focused = false;
}, },
methods: { methods: {
onInput: function onInput(event) { onInput(event) {
var _this = this; const { value = '' } = event.detail || {};
var _ref = event.detail || {},
_ref$value = _ref.value,
value = _ref$value === void 0 ? '' : _ref$value;
this.set({ this.set({
value: value, value,
showClear: this.getShowClear(value) showClear: this.getShowClear(value)
}, function () { }, () => {
_this.emitChange(value); this.emitChange(value);
}); });
}, },
onFocus: function onFocus(event) { onFocus(event) {
var _ref2 = event.detail || {}, const { value = '', height = 0 } = event.detail || {};
_ref2$value = _ref2.value, this.$emit('focus', { value, height });
value = _ref2$value === void 0 ? '' : _ref2$value,
_ref2$height = _ref2.height,
height = _ref2$height === void 0 ? 0 : _ref2$height;
this.$emit('focus', {
value: value,
height: height
});
this.focused = true; this.focused = true;
this.blurFromClear = false; this.blurFromClear = false;
this.set({ this.set({
showClear: this.getShowClear() showClear: this.getShowClear()
}); });
}, },
onBlur: function onBlur(event) { onBlur(event) {
var _this2 = this; const { value = '', cursor = 0 } = event.detail || {};
this.$emit('blur', { value, cursor });
var _ref3 = event.detail || {},
_ref3$value = _ref3.value,
value = _ref3$value === void 0 ? '' : _ref3$value,
_ref3$cursor = _ref3.cursor,
cursor = _ref3$cursor === void 0 ? 0 : _ref3$cursor;
this.$emit('blur', {
value: value,
cursor: cursor
});
this.focused = false; this.focused = false;
var showClear = this.getShowClear(); const showClear = this.getShowClear();
if (this.data.value === value) { if (this.data.value === value) {
this.set({ this.set({
showClear: showClear showClear
}); });
} else if (!this.blurFromClear) { }
else if (!this.blurFromClear) {
// fix: the handwritten keyboard does not trigger input change // fix: the handwritten keyboard does not trigger input change
this.set({ this.set({
value: value, value,
showClear: showClear showClear
}, function () { }, () => {
_this2.emitChange(value); this.emitChange(value);
}); });
} }
}, },
onClickIcon: function onClickIcon() { onClickIcon() {
this.$emit('click-icon'); this.$emit('click-icon');
}, },
getShowClear: function getShowClear(value) { getShowClear(value) {
value = value === undefined ? this.data.value : value; value = value === undefined ? this.data.value : value;
return this.data.clearable && this.focused && value && !this.data.readonly; return (this.data.clearable && this.focused && value && !this.data.readonly);
}, },
onClear: function onClear() { onClear() {
var _this3 = this;
this.blurFromClear = true; this.blurFromClear = true;
this.set({ this.set({
value: '', value: '',
showClear: this.getShowClear('') showClear: this.getShowClear('')
}, function () { }, () => {
_this3.emitChange(''); this.emitChange('');
this.$emit('clear', '');
_this3.$emit('clear', '');
}); });
}, },
onConfirm: function onConfirm() { onConfirm() {
this.$emit('confirm', this.data.value); this.$emit('confirm', this.data.value);
}, },
emitChange: function emitChange(value) { emitChange(value) {
this.$emit('input', value); this.$emit('input', value);
this.$emit('change', value); this.$emit('change', value);
} }

View File

@ -10,6 +10,7 @@
custom-style="{{ customStyle }}" custom-style="{{ customStyle }}"
title-width="{{ titleWidth }}" title-width="{{ titleWidth }}"
custom-class="van-field" custom-class="van-field"
size="{{ size }}"
> >
<slot name="left-icon" slot="icon" /> <slot name="left-icon" slot="icon" />
<slot name="label" slot="title" /> <slot name="label" slot="title" />

1
dist/goods-action-button/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -14,7 +14,7 @@ VantComponent({
} }
}, },
methods: { methods: {
onClick: function onClick(event) { onClick(event) {
this.$emit('click', event.detail); this.$emit('click', event.detail);
this.jumpLink(); this.jumpLink();
} }

1
dist/goods-action-icon/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -11,7 +11,7 @@ VantComponent({
icon: String icon: String
}, },
methods: { methods: {
onClick: function onClick(event) { onClick(event) {
this.$emit('click', event.detail); this.$emit('click', event.detail);
this.jumpLink(); this.jumpLink();
} }

1
dist/goods-action/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

1
dist/icon/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

2
dist/icon/index.js vendored
View File

@ -12,7 +12,7 @@ VantComponent({
} }
}, },
methods: { methods: {
onClick: function onClick() { onClick() {
this.$emit('click'); this.$emit('click');
} }
} }

File diff suppressed because one or more lines are too long

1
dist/info/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

1
dist/loading/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

1
dist/mixins/basic.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const basic: void;

18
dist/mixins/basic.js vendored
View File

@ -1,21 +1,21 @@
export var basic = Behavior({ export const basic = Behavior({
methods: { methods: {
$emit: function $emit() { $emit() {
this.triggerEvent.apply(this, arguments); this.triggerEvent.apply(this, arguments);
}, },
getRect: function getRect(selector, all) { getRect(selector, all) {
var _this = this; return new Promise(resolve => {
wx.createSelectorQuery()
return new Promise(function (resolve) { .in(this)[all ? 'selectAll' : 'select'](selector)
wx.createSelectorQuery().in(_this)[all ? 'selectAll' : 'select'](selector).boundingClientRect(function (rect) { .boundingClientRect(rect => {
if (all && Array.isArray(rect) && rect.length) { if (all && Array.isArray(rect) && rect.length) {
resolve(rect); resolve(rect);
} }
if (!all && rect) { if (!all && rect) {
resolve(rect); resolve(rect);
} }
}).exec(); })
.exec();
}); });
} }
} }

1
dist/mixins/button.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const button: void;

View File

@ -1,4 +1,4 @@
export var button = Behavior({ export const button = Behavior({
externalClasses: ['hover-class'], externalClasses: ['hover-class'],
properties: { properties: {
id: String, id: String,

1
dist/mixins/iphonex.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const iphonex: void;

View File

@ -1,16 +1,14 @@
var isIPhoneX = null; let isIPhoneX = null;
function getIsIPhoneX() { function getIsIPhoneX() {
return new Promise(function (resolve, reject) { return new Promise((resolve, reject) => {
if (isIPhoneX !== null) { if (isIPhoneX !== null) {
resolve(isIPhoneX); resolve(isIPhoneX);
} else { }
else {
wx.getSystemInfo({ wx.getSystemInfo({
success: function success(_ref) { success: ({ model, screenHeight }) => {
var model = _ref.model, const iphoneX = /iphone x/i.test(model);
screenHeight = _ref.screenHeight; const iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
var iphoneX = /iphone x/i.test(model);
var iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
isIPhoneX = iphoneX || iphoneNew; isIPhoneX = iphoneX || iphoneNew;
resolve(isIPhoneX); resolve(isIPhoneX);
}, },
@ -19,21 +17,16 @@ function getIsIPhoneX() {
} }
}); });
} }
export const iphonex = Behavior({
export var iphonex = Behavior({
properties: { properties: {
safeAreaInsetBottom: { safeAreaInsetBottom: {
type: Boolean, type: Boolean,
value: true value: true
} }
}, },
created: function created() { created() {
var _this = this; getIsIPhoneX().then(isIPhoneX => {
this.set({ isIPhoneX });
getIsIPhoneX().then(function (isIPhoneX) {
_this.set({
isIPhoneX: isIPhoneX
});
}); });
} }
}); });

1
dist/mixins/link.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const link: void;

15
dist/mixins/link.js vendored
View File

@ -1,4 +1,4 @@
export var link = Behavior({ export const link = Behavior({
properties: { properties: {
url: String, url: String,
linkType: { linkType: {
@ -7,17 +7,10 @@ export var link = Behavior({
} }
}, },
methods: { methods: {
jumpLink: function jumpLink(urlKey) { jumpLink(urlKey = 'url') {
if (urlKey === void 0) { const url = this.data[urlKey];
urlKey = 'url';
}
var url = this.data[urlKey];
if (url) { if (url) {
wx[this.data.linkType]({ wx[this.data.linkType]({ url });
url: url
});
} }
} }
} }

1
dist/mixins/observer/behavior.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const behavior: void;

View File

@ -1,30 +1,21 @@
function setAsync(context, data) { function setAsync(context, data) {
return new Promise(function (resolve) { return new Promise(resolve => {
context.setData(data, resolve); context.setData(data, resolve);
}); });
} }
; ;
export var behavior = Behavior({ export const behavior = Behavior({
created: function created() { created() {
var _this = this;
if (!this.$options) { if (!this.$options) {
return; return;
} }
const cache = {};
var cache = {}; const { computed } = this.$options();
const keys = Object.keys(computed);
var _this$$options = this.$options(), this.calcComputed = () => {
computed = _this$$options.computed; const needUpdate = {};
keys.forEach(key => {
var keys = Object.keys(computed); const value = computed[key].call(this);
this.calcComputed = function () {
var needUpdate = {};
keys.forEach(function (key) {
var value = computed[key].call(_this);
if (cache[key] !== value) { if (cache[key] !== value) {
cache[key] = needUpdate[key] = value; cache[key] = needUpdate[key] = value;
} }
@ -32,29 +23,23 @@ export var behavior = Behavior({
return needUpdate; return needUpdate;
}; };
}, },
attached: function attached() { attached() {
this.set(); this.set();
}, },
methods: { methods: {
// set data and set computed data // set data and set computed data
set: function set(data, callback) { set(data, callback) {
var _this2 = this; const stack = [];
var stack = [];
if (data) { if (data) {
stack.push(setAsync(this, data)); stack.push(setAsync(this, data));
} }
if (this.calcComputed) { if (this.calcComputed) {
stack.push(setAsync(this, this.calcComputed())); stack.push(setAsync(this, this.calcComputed()));
} }
return Promise.all(stack).then(res => {
return Promise.all(stack).then(function (res) {
if (callback && typeof callback === 'function') { if (callback && typeof callback === 'function') {
callback.call(_this2); callback.call(this);
} }
return res; return res;
}); });
} }

1
dist/mixins/observer/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare function observe(vantOptions: any, options: any): void;

View File

@ -1,36 +1,25 @@
import { behavior } from './behavior'; import { behavior } from './behavior';
import { observeProps } from './props'; import { observeProps } from './props';
export function observe(vantOptions, options) { export function observe(vantOptions, options) {
var watch = vantOptions.watch, const { watch, computed } = vantOptions;
computed = vantOptions.computed;
options.behaviors.push(behavior); options.behaviors.push(behavior);
if (watch) { if (watch) {
var props = options.properties || {}; const props = options.properties || {};
Object.keys(watch).forEach(function (key) { Object.keys(watch).forEach(key => {
if (key in props) { if (key in props) {
var prop = props[key]; let prop = props[key];
if (prop === null || !('type' in prop)) { if (prop === null || !('type' in prop)) {
prop = { prop = { type: prop };
type: prop
};
} }
prop.observer = watch[key]; prop.observer = watch[key];
props[key] = prop; props[key] = prop;
} }
}); });
options.properties = props; options.properties = props;
} }
if (computed) { if (computed) {
options.methods = options.methods || {}; options.methods = options.methods || {};
options.methods.$options = () => vantOptions;
options.methods.$options = function () {
return vantOptions;
};
if (options.properties) { if (options.properties) {
observeProps(options.properties); observeProps(options.properties);
} }

1
dist/mixins/observer/props.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare function observeProps(props: any): void;

View File

@ -2,31 +2,21 @@ export function observeProps(props) {
if (!props) { if (!props) {
return; return;
} }
Object.keys(props).forEach(key => {
Object.keys(props).forEach(function (key) { let prop = props[key];
var prop = props[key];
if (prop === null || !('type' in prop)) { if (prop === null || !('type' in prop)) {
prop = { prop = { type: prop };
type: prop
};
} }
let { observer } = prop;
var _prop = prop,
observer = _prop.observer;
prop.observer = function () { prop.observer = function () {
if (observer) { if (observer) {
if (typeof observer === 'string') { if (typeof observer === 'string') {
observer = this[observer]; observer = this[observer];
} }
observer.apply(this, arguments); observer.apply(this, arguments);
} }
this.set(); this.set();
}; };
props[key] = prop; props[key] = prop;
}); });
} }

1
dist/mixins/open-type.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const openType: void;

View File

@ -1,25 +1,25 @@
export var openType = Behavior({ export const openType = Behavior({
properties: { properties: {
openType: String openType: String
}, },
methods: { methods: {
bindGetUserInfo: function bindGetUserInfo(event) { bindGetUserInfo(event) {
this.$emit('getuserinfo', event.detail); this.$emit('getuserinfo', event.detail);
}, },
bindContact: function bindContact(event) { bindContact(event) {
this.$emit('contact', event.detail); this.$emit('contact', event.detail);
}, },
bindGetPhoneNumber: function bindGetPhoneNumber(event) { bindGetPhoneNumber(event) {
this.$emit('getphonenumber', event.detail); this.$emit('getphonenumber', event.detail);
}, },
bindError: function bindError(event) { bindError(event) {
this.$emit('error', event.detail); this.$emit('error', event.detail);
}, },
bindLaunchApp: function bindLaunchApp(event) { bindLaunchApp(event) {
this.$emit('launchapp', event.detail); this.$emit('launchapp', event.detail);
}, },
bindOpenSetting: function bindOpenSetting(event) { bindOpenSetting(event) {
this.$emit('opensetting', event.detail); this.$emit('opensetting', event.detail);
} },
} }
}); });

1
dist/mixins/touch.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const touch: void;

View File

@ -1,6 +1,6 @@
export var touch = Behavior({ export const touch = Behavior({
methods: { methods: {
touchStart: function touchStart(event) { touchStart(event) {
this.direction = ''; this.direction = '';
this.deltaX = 0; this.deltaX = 0;
this.deltaY = 0; this.deltaY = 0;
@ -9,8 +9,8 @@ export var touch = Behavior({
this.startX = event.touches[0].clientX; this.startX = event.touches[0].clientX;
this.startY = event.touches[0].clientY; this.startY = event.touches[0].clientY;
}, },
touchMove: function touchMove(event) { touchMove(event) {
var touch = event.touches[0]; const touch = event.touches[0];
this.deltaX = touch.clientX - this.startX; this.deltaX = touch.clientX - this.startX;
this.deltaY = touch.clientY - this.startY; this.deltaY = touch.clientY - this.startY;
this.offsetX = Math.abs(this.deltaX); this.offsetX = Math.abs(this.deltaX);

1
dist/mixins/transition.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare const transition: (showDefaultValue: boolean) => void;

View File

@ -1,19 +1,12 @@
import { isObj } from '../common/utils'; import { isObj } from '../common/utils';
const getClassNames = (name) => ({
var getClassNames = function getClassNames(name) { enter: `van-${name}-enter van-${name}-enter-active enter-class enter-active-class`,
return { 'enter-to': `van-${name}-enter-to van-${name}-enter-active enter-to-class enter-active-class`,
enter: "van-" + name + "-enter van-" + name + "-enter-active enter-class enter-active-class", leave: `van-${name}-leave van-${name}-leave-active leave-class leave-active-class`,
'enter-to': "van-" + name + "-enter-to van-" + name + "-enter-active enter-to-class enter-active-class", 'leave-to': `van-${name}-leave-to van-${name}-leave-active leave-to-class leave-active-class`
leave: "van-" + name + "-leave van-" + name + "-leave-active leave-class leave-active-class", });
'leave-to': "van-" + name + "-leave-to van-" + name + "-leave-active leave-to-class leave-active-class" const requestAnimationFrame = (cb) => setTimeout(cb, 1000 / 60);
}; export const transition = function (showDefaultValue) {
};
var requestAnimationFrame = function requestAnimationFrame(cb) {
return setTimeout(cb, 1000 / 60);
};
export var transition = function transition(showDefaultValue) {
return Behavior({ return Behavior({
properties: { properties: {
customStyle: String, customStyle: String,
@ -39,65 +32,56 @@ export var transition = function transition(showDefaultValue) {
display: false, display: false,
classNames: getClassNames('fade') classNames: getClassNames('fade')
}, },
attached: function attached() { attached() {
if (this.data.show) { if (this.data.show) {
this.show(); this.show();
} }
}, },
methods: { methods: {
observeShow: function observeShow(value) { observeShow(value) {
if (value) { if (value) {
this.show(); this.show();
} else { }
else {
this.leave(); this.leave();
} }
}, },
updateClasses: function updateClasses(name) { updateClasses(name) {
this.set({ this.set({
classNames: getClassNames(name) classNames: getClassNames(name)
}); });
}, },
show: function show() { show() {
var _this = this; const { classNames, duration } = this.data;
var _this$data = this.data,
classNames = _this$data.classNames,
duration = _this$data.duration;
this.set({ this.set({
inited: true, inited: true,
display: true, display: true,
classes: classNames.enter, classes: classNames.enter,
currentDuration: isObj(duration) ? duration.enter : duration currentDuration: isObj(duration) ? duration.enter : duration
}).then(function () { }).then(() => {
requestAnimationFrame(function () { requestAnimationFrame(() => {
_this.set({ this.set({
classes: classNames['enter-to'] classes: classNames['enter-to']
}); });
}); });
}); });
}, },
leave: function leave() { leave() {
var _this2 = this; const { classNames, duration } = this.data;
var _this$data2 = this.data,
classNames = _this$data2.classNames,
duration = _this$data2.duration;
this.set({ this.set({
classes: classNames.leave, classes: classNames.leave,
currentDuration: isObj(duration) ? duration.leave : duration currentDuration: isObj(duration) ? duration.leave : duration
}).then(function () { }).then(() => {
requestAnimationFrame(function () { requestAnimationFrame(() => {
_this2.set({ this.set({
classes: classNames['leave-to'] classes: classNames['leave-to']
}); });
}); });
}); });
}, },
onTransitionEnd: function onTransitionEnd() { onTransitionEnd() {
if (!this.data.show) { if (!this.data.show) {
this.set({ this.set({ display: false });
display: false
});
} }
} }
} }

1
dist/nav-bar/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -17,10 +17,10 @@ VantComponent({
} }
}, },
methods: { methods: {
onClickLeft: function onClickLeft() { onClickLeft() {
this.$emit('click-left'); this.$emit('click-left');
}, },
onClickRight: function onClickRight() { onClickRight() {
this.$emit('click-right'); this.$emit('click-right');
} }
} }

1
dist/notice-bar/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,6 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
var FONT_COLOR = '#ed6a0c'; const FONT_COLOR = '#ed6a0c';
var BG_COLOR = '#fffbe8'; const BG_COLOR = '#fffbe8';
VantComponent({ VantComponent({
props: { props: {
text: { text: {
@ -49,82 +49,79 @@ VantComponent({
hasRightIcon: false hasRightIcon: false
}, },
watch: { watch: {
text: function text() { text() {
this.set({}, this.init); this.set({}, this.init);
} }
}, },
created: function created() { created() {
if (this.data.mode) { if (this.data.mode) {
this.set({ this.set({
hasRightIcon: true hasRightIcon: true
}); });
} }
this.resetAnimation = wx.createAnimation({ this.resetAnimation = wx.createAnimation({
duration: 0, duration: 0,
timingFunction: 'linear' timingFunction: 'linear'
}); });
}, },
destroyed: function destroyed() { destroyed() {
this.timer && clearTimeout(this.timer); this.timer && clearTimeout(this.timer);
}, },
methods: { methods: {
init: function init() { init() {
var _this = this; Promise.all([
this.getRect('.van-notice-bar__content'),
Promise.all([this.getRect('.van-notice-bar__content'), this.getRect('.van-notice-bar__content-wrap')]).then(function (rects) { this.getRect('.van-notice-bar__content-wrap')
var contentRect = rects[0], ]).then((rects) => {
wrapRect = rects[1]; const [contentRect, wrapRect] = rects;
if (contentRect == null ||
if (contentRect == null || wrapRect == null || !contentRect.width || !wrapRect.width) { wrapRect == null ||
!contentRect.width ||
!wrapRect.width) {
return; return;
} }
const { speed, scrollable, delay } = this.data;
var _this$data = _this.data,
speed = _this$data.speed,
scrollable = _this$data.scrollable,
delay = _this$data.delay;
if (scrollable && wrapRect.width < contentRect.width) { if (scrollable && wrapRect.width < contentRect.width) {
var duration = contentRect.width / speed * 1000; const duration = (contentRect.width / speed) * 1000;
_this.wrapWidth = wrapRect.width; this.wrapWidth = wrapRect.width;
_this.contentWidth = contentRect.width; this.contentWidth = contentRect.width;
_this.duration = duration; this.duration = duration;
_this.animation = wx.createAnimation({ this.animation = wx.createAnimation({
duration: duration, duration,
timingFunction: 'linear', timingFunction: 'linear',
delay: delay delay
}); });
this.scroll();
_this.scroll();
} }
}); });
}, },
scroll: function scroll() { scroll() {
var _this2 = this;
this.timer && clearTimeout(this.timer); this.timer && clearTimeout(this.timer);
this.timer = null; this.timer = null;
this.set({ this.set({
animationData: this.resetAnimation.translateX(this.wrapWidth).step().export() animationData: this.resetAnimation
.translateX(this.wrapWidth)
.step()
.export()
}); });
setTimeout(function () { setTimeout(() => {
_this2.set({ this.set({
animationData: _this2.animation.translateX(-_this2.contentWidth).step().export() animationData: this.animation
.translateX(-this.contentWidth)
.step()
.export()
}); });
}, 20); }, 20);
this.timer = setTimeout(function () { this.timer = setTimeout(() => {
_this2.scroll(); this.scroll();
}, this.duration); }, this.duration);
}, },
onClickIcon: function onClickIcon() { onClickIcon() {
this.timer && clearTimeout(this.timer); this.timer && clearTimeout(this.timer);
this.timer = null; this.timer = null;
this.set({ this.set({ show: false });
show: false
});
}, },
onClick: function onClick(event) { onClick(event) {
this.$emit('click', event); this.$emit('click', event);
} }
} }

1
dist/notify/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

13
dist/notify/index.js vendored
View File

@ -17,22 +17,19 @@ VantComponent({
} }
}, },
methods: { methods: {
show: function show() { show() {
var _this = this; const { duration } = this.data;
var duration = this.data.duration;
clearTimeout(this.timer); clearTimeout(this.timer);
this.set({ this.set({
show: true show: true
}); });
if (duration > 0 && duration !== Infinity) { if (duration > 0 && duration !== Infinity) {
this.timer = setTimeout(function () { this.timer = setTimeout(() => {
_this.hide(); this.hide();
}, duration); }, duration);
} }
}, },
hide: function hide() { hide() {
clearTimeout(this.timer); clearTimeout(this.timer);
this.set({ this.set({
show: false show: false

7
dist/notify/notify.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
declare type NotifyOptions = {
selector?: string;
duration?: number;
context?: any;
};
export default function Notify(options?: NotifyOptions): void;
export {};

25
dist/notify/notify.js vendored
View File

@ -1,34 +1,25 @@
import { isObj } from '../common/utils'; import { isObj } from '../common/utils';
var defaultOptions = { const defaultOptions = {
selector: '#van-notify', selector: '#van-notify',
duration: 3000 duration: 3000
}; };
function parseOptions(text) { function parseOptions(text) {
return isObj(text) ? text : { return isObj(text) ? text : { text };
text: text
};
} }
function getContext() { function getContext() {
var pages = getCurrentPages(); const pages = getCurrentPages();
return pages[pages.length - 1]; return pages[pages.length - 1];
} }
export default function Notify(options = {}) {
export default function Notify(options) {
if (options === void 0) {
options = {};
}
options = Object.assign({}, defaultOptions, parseOptions(options)); options = Object.assign({}, defaultOptions, parseOptions(options));
var context = options.context || getContext(); const context = options.context || getContext();
var notify = context.selectComponent(options.selector); const notify = context.selectComponent(options.selector);
delete options.selector; delete options.selector;
if (notify) { if (notify) {
notify.set(options); notify.set(options);
notify.show(); notify.show();
} else { }
else {
console.warn('未找到 van-notify 节点,请确认 selector 及 context 是否正确'); console.warn('未找到 van-notify 节点,请确认 selector 及 context 是否正确');
} }
} }

1
dist/overlay/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -14,10 +14,10 @@ VantComponent({
} }
}, },
methods: { methods: {
onClick: function onClick() { onClick() {
this.$emit('click'); this.$emit('click');
}, },
// for prevent touchmove // for prevent touchmove
noop: function noop() {} noop() { }
} }
}); });

1
dist/panel/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

1
dist/picker-column/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,6 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isObj, range } from '../common/utils'; import { isObj, range } from '../common/utils';
var DEFAULT_DURATION = 200; const DEFAULT_DURATION = 200;
VantComponent({ VantComponent({
classes: ['active-class'], classes: ['active-class'],
props: { props: {
@ -25,119 +25,111 @@ VantComponent({
options: [], options: [],
currentIndex: 0 currentIndex: 0
}, },
beforeCreate: function beforeCreate() { beforeCreate() {
var _this = this; const { defaultIndex, initialOptions } = this.data;
var _this$data = this.data,
defaultIndex = _this$data.defaultIndex,
initialOptions = _this$data.initialOptions;
this.set({ this.set({
currentIndex: defaultIndex, currentIndex: defaultIndex,
options: initialOptions options: initialOptions
}).then(function () { }).then(() => {
_this.setIndex(defaultIndex); this.setIndex(defaultIndex);
}); });
}, },
computed: { computed: {
count: function count() { count() {
return this.data.options.length; return this.data.options.length;
}, },
baseOffset: function baseOffset() { baseOffset() {
var data = this.data; const { data } = this;
return data.itemHeight * (data.visibleItemCount - 1) / 2; return (data.itemHeight * (data.visibleItemCount - 1)) / 2;
}, },
wrapperStyle: function wrapperStyle() { wrapperStyle() {
var data = this.data; const { data } = this;
return ["transition: " + data.duration + "ms", "transform: translate3d(0, " + (data.offset + data.baseOffset) + "px, 0)", "line-height: " + data.itemHeight + "px"].join('; '); return [
`transition: ${data.duration}ms`,
`transform: translate3d(0, ${data.offset + data.baseOffset}px, 0)`,
`line-height: ${data.itemHeight}px`
].join('; ');
} }
}, },
watch: { watch: {
defaultIndex: function defaultIndex(value) { defaultIndex(value) {
this.setIndex(value); this.setIndex(value);
} }
}, },
methods: { methods: {
onTouchStart: function onTouchStart(event) { onTouchStart(event) {
this.set({ this.set({
startY: event.touches[0].clientY, startY: event.touches[0].clientY,
startOffset: this.data.offset, startOffset: this.data.offset,
duration: 0 duration: 0
}); });
}, },
onTouchMove: function onTouchMove(event) { onTouchMove(event) {
var data = this.data; const { data } = this;
var deltaY = event.touches[0].clientY - data.startY; const deltaY = event.touches[0].clientY - data.startY;
this.set({ this.set({
offset: range(data.startOffset + deltaY, -(data.count * data.itemHeight), data.itemHeight) offset: range(data.startOffset + deltaY, -(data.count * data.itemHeight), data.itemHeight)
}); });
}, },
onTouchEnd: function onTouchEnd() { onTouchEnd() {
var data = this.data; const { data } = this;
if (data.offset !== data.startOffset) { if (data.offset !== data.startOffset) {
this.set({ this.set({
duration: DEFAULT_DURATION duration: DEFAULT_DURATION
}); });
var index = range(Math.round(-data.offset / data.itemHeight), 0, data.count - 1); const index = range(Math.round(-data.offset / data.itemHeight), 0, data.count - 1);
this.setIndex(index, true); this.setIndex(index, true);
} }
}, },
onClickItem: function onClickItem(event) { onClickItem(event) {
var index = event.currentTarget.dataset.index; const { index } = event.currentTarget.dataset;
this.setIndex(index, true); this.setIndex(index, true);
}, },
adjustIndex: function adjustIndex(index) { adjustIndex(index) {
var data = this.data; const { data } = this;
index = range(index, 0, data.count); index = range(index, 0, data.count);
for (let i = index; i < data.count; i++) {
for (var i = index; i < data.count; i++) { if (!this.isDisabled(data.options[i]))
if (!this.isDisabled(data.options[i])) return i; return i;
} }
for (let i = index - 1; i >= 0; i--) {
for (var _i = index - 1; _i >= 0; _i--) { if (!this.isDisabled(data.options[i]))
if (!this.isDisabled(data.options[_i])) return _i; return i;
} }
}, },
isDisabled: function isDisabled(option) { isDisabled(option) {
return isObj(option) && option.disabled; return isObj(option) && option.disabled;
}, },
getOptionText: function getOptionText(option) { getOptionText(option) {
var data = this.data; const { data } = this;
return isObj(option) && data.valueKey in option ? option[data.valueKey] : option; return isObj(option) && data.valueKey in option
? option[data.valueKey]
: option;
}, },
setIndex: function setIndex(index, userAction) { setIndex(index, userAction) {
var _this2 = this; const { data } = this;
var data = this.data;
index = this.adjustIndex(index) || 0; index = this.adjustIndex(index) || 0;
var offset = -index * data.itemHeight; const offset = -index * data.itemHeight;
if (index !== data.currentIndex) { if (index !== data.currentIndex) {
return this.set({ return this.set({ offset, currentIndex: index }).then(() => {
offset: offset, userAction && this.$emit('change', index);
currentIndex: index
}).then(function () {
userAction && _this2.$emit('change', index);
});
} else {
return this.set({
offset: offset
}); });
} }
else {
return this.set({ offset });
}
}, },
setValue: function setValue(value) { setValue(value) {
var options = this.data.options; const { options } = this.data;
for (let i = 0; i < options.length; i++) {
for (var i = 0; i < options.length; i++) {
if (this.getOptionText(options[i]) === value) { if (this.getOptionText(options[i]) === value) {
return this.setIndex(i); return this.setIndex(i);
} }
} }
return Promise.resolve(); return Promise.resolve();
}, },
getValue: function getValue() { getValue() {
var data = this.data; const { data } = this;
return data.options[data.currentIndex]; return data.options[data.currentIndex];
} }
} }

1
dist/picker/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

110
dist/picker/index.js vendored
View File

@ -1,9 +1,7 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
function isSimple(columns) { function isSimple(columns) {
return columns.length && !columns[0].values; return columns.length && !columns[0].values;
} }
VantComponent({ VantComponent({
classes: ['active-class', 'toolbar-class', 'column-class'], classes: ['active-class', 'toolbar-class', 'column-class'],
props: { props: {
@ -27,60 +25,50 @@ VantComponent({
columns: { columns: {
type: Array, type: Array,
value: [], value: [],
observer: function observer(columns) { observer(columns = []) {
if (columns === void 0) {
columns = [];
}
this.simple = isSimple(columns); this.simple = isSimple(columns);
this.children = this.selectAllComponents('.van-picker__column'); this.children = this.selectAllComponents('.van-picker__column');
if (Array.isArray(this.children) && this.children.length) { if (Array.isArray(this.children) && this.children.length) {
this.setColumns().catch(function () {}); this.setColumns().catch(() => { });
} }
} }
} }
}, },
beforeCreate: function beforeCreate() { beforeCreate() {
this.children = []; this.children = [];
}, },
methods: { methods: {
noop: function noop() {}, noop() { },
setColumns: function setColumns() { setColumns() {
var _this = this; const { data } = this;
const columns = this.simple ? [{ values: data.columns }] : data.columns;
var data = this.data; const stack = columns.map((column, index) => this.setColumnValues(index, column.values));
var columns = this.simple ? [{
values: data.columns
}] : data.columns;
var stack = columns.map(function (column, index) {
return _this.setColumnValues(index, column.values);
});
return Promise.all(stack); return Promise.all(stack);
}, },
emit: function emit(event) { emit(event) {
var type = event.currentTarget.dataset.type; const { type } = event.currentTarget.dataset;
if (this.simple) { if (this.simple) {
this.$emit(type, { this.$emit(type, {
value: this.getColumnValue(0), value: this.getColumnValue(0),
index: this.getColumnIndex(0) index: this.getColumnIndex(0)
}); });
} else { }
else {
this.$emit(type, { this.$emit(type, {
value: this.getValues(), value: this.getValues(),
index: this.getIndexes() index: this.getIndexes()
}); });
} }
}, },
onChange: function onChange(event) { onChange(event) {
if (this.simple) { if (this.simple) {
this.$emit('change', { this.$emit('change', {
picker: this, picker: this,
value: this.getColumnValue(0), value: this.getColumnValue(0),
index: this.getColumnIndex(0) index: this.getColumnIndex(0)
}); });
} else { }
else {
this.$emit('change', { this.$emit('change', {
picker: this, picker: this,
value: this.getValues(), value: this.getValues(),
@ -89,96 +77,70 @@ VantComponent({
} }
}, },
// get column instance by index // get column instance by index
getColumn: function getColumn(index) { getColumn(index) {
return this.children[index]; return this.children[index];
}, },
// get column value by index // get column value by index
getColumnValue: function getColumnValue(index) { getColumnValue(index) {
var column = this.getColumn(index); const column = this.getColumn(index);
return column && column.getValue(); return column && column.getValue();
}, },
// set column value by index // set column value by index
setColumnValue: function setColumnValue(index, value) { setColumnValue(index, value) {
var column = this.getColumn(index); const column = this.getColumn(index);
if (column == null) { if (column == null) {
return Promise.reject('setColumnValue: 对应列不存在'); return Promise.reject('setColumnValue: 对应列不存在');
} }
return column.setValue(value); return column.setValue(value);
}, },
// get column option index by column index // get column option index by column index
getColumnIndex: function getColumnIndex(columnIndex) { getColumnIndex(columnIndex) {
return (this.getColumn(columnIndex) || {}).data.currentIndex; return (this.getColumn(columnIndex) || {}).data.currentIndex;
}, },
// set column option index by column index // set column option index by column index
setColumnIndex: function setColumnIndex(columnIndex, optionIndex) { setColumnIndex(columnIndex, optionIndex) {
var column = this.getColumn(columnIndex); const column = this.getColumn(columnIndex);
if (column == null) { if (column == null) {
return Promise.reject('setColumnIndex: 对应列不存在'); return Promise.reject('setColumnIndex: 对应列不存在');
} }
return column.setIndex(optionIndex); return column.setIndex(optionIndex);
}, },
// get options of column by index // get options of column by index
getColumnValues: function getColumnValues(index) { getColumnValues(index) {
return (this.children[index] || {}).data.options; return (this.children[index] || {}).data.options;
}, },
// set options of column by index // set options of column by index
setColumnValues: function setColumnValues(index, options, needReset) { setColumnValues(index, options, needReset = true) {
if (needReset === void 0) { const column = this.children[index];
needReset = true;
}
var column = this.children[index];
if (column == null) { if (column == null) {
return Promise.reject('setColumnValues: 对应列不存在'); return Promise.reject('setColumnValues: 对应列不存在');
} }
const isSame = JSON.stringify(column.data.options) === JSON.stringify(options);
var isSame = JSON.stringify(column.data.options) === JSON.stringify(options);
if (isSame) { if (isSame) {
return Promise.resolve(); return Promise.resolve();
} }
return column.set({ options }).then(() => {
return column.set({
options: options
}).then(function () {
if (needReset) { if (needReset) {
column.setIndex(0); column.setIndex(0);
} }
}); });
}, },
// get values of all columns // get values of all columns
getValues: function getValues() { getValues() {
return this.children.map(function (child) { return this.children.map((child) => child.getValue());
return child.getValue();
});
}, },
// set values of all columns // set values of all columns
setValues: function setValues(values) { setValues(values) {
var _this2 = this; const stack = values.map((value, index) => this.setColumnValue(index, value));
var stack = values.map(function (value, index) {
return _this2.setColumnValue(index, value);
});
return Promise.all(stack); return Promise.all(stack);
}, },
// get indexes of all columns // get indexes of all columns
getIndexes: function getIndexes() { getIndexes() {
return this.children.map(function (child) { return this.children.map((child) => child.data.currentIndex);
return child.data.currentIndex;
});
}, },
// set indexes of all columns // set indexes of all columns
setIndexes: function setIndexes(indexes) { setIndexes(indexes) {
var _this3 = this; const stack = indexes.map((optionIndex, columnIndex) => this.setColumnIndex(columnIndex, optionIndex));
var stack = indexes.map(function (optionIndex, columnIndex) {
return _this3.setColumnIndex(columnIndex, optionIndex);
});
return Promise.all(stack); return Promise.all(stack);
} }
} }

1
dist/popup/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

20
dist/popup/index.js vendored
View File

@ -2,7 +2,14 @@ import { VantComponent } from '../common/component';
import { transition } from '../mixins/transition'; import { transition } from '../mixins/transition';
import { iphonex } from '../mixins/iphonex'; import { iphonex } from '../mixins/iphonex';
VantComponent({ VantComponent({
classes: ['enter-class', 'enter-active-class', 'enter-to-class', 'leave-class', 'leave-active-class', 'leave-to-class'], classes: [
'enter-class',
'enter-active-class',
'enter-to-class',
'leave-class',
'leave-active-class',
'leave-to-class'
],
mixins: [transition(false), iphonex], mixins: [transition(false), iphonex],
props: { props: {
transition: { transition: {
@ -29,21 +36,18 @@ VantComponent({
observer: 'observeClass' observer: 'observeClass'
} }
}, },
created: function created() { created() {
this.observeClass(); this.observeClass();
}, },
methods: { methods: {
onClickOverlay: function onClickOverlay() { onClickOverlay() {
this.$emit('click-overlay'); this.$emit('click-overlay');
if (this.data.closeOnClickOverlay) { if (this.data.closeOnClickOverlay) {
this.$emit('close'); this.$emit('close');
} }
}, },
observeClass: function observeClass() { observeClass() {
var _this$data = this.data, const { transition, position } = this.data;
transition = _this$data.transition,
position = _this$data.position;
this.updateClasses(transition || position); this.updateClasses(transition || position);
} }
} }

1
dist/progress/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -28,37 +28,35 @@ VantComponent({
showPivot: 'getWidth' showPivot: 'getWidth'
}, },
computed: { computed: {
portionStyle: function portionStyle() { portionStyle() {
var width = (this.data.progressWidth - this.data.pivotWidth) * this.data.percentage / 100 + 'px'; const width = (this.data.progressWidth - this.data.pivotWidth) * this.data.percentage / 100 + 'px';
var background = this.getCurrentColor(); const background = this.getCurrentColor();
return "width: " + width + "; background: " + background + "; "; return `width: ${width}; background: ${background}; `;
}, },
pivotStyle: function pivotStyle() { pivotStyle() {
var color = this.data.textColor; const color = this.data.textColor;
var background = this.data.pivotColor || this.getCurrentColor(); const background = this.data.pivotColor || this.getCurrentColor();
return "color: " + color + "; background: " + background; return `color: ${color}; background: ${background}`;
}, },
text: function text() { text() {
return this.data.pivotText || this.data.percentage + '%'; return this.data.pivotText || this.data.percentage + '%';
} }
}, },
mounted: function mounted() { mounted() {
this.getWidth(); this.getWidth();
}, },
methods: { methods: {
getCurrentColor: function getCurrentColor() { getCurrentColor() {
return this.data.inactive ? '#cacaca' : this.data.color; return this.data.inactive ? '#cacaca' : this.data.color;
}, },
getWidth: function getWidth() { getWidth() {
var _this = this; this.getRect('.van-progress').then(rect => {
this.set({
this.getRect('.van-progress').then(function (rect) {
_this.set({
progressWidth: rect.width progressWidth: rect.width
}); });
}); });
this.getRect('.van-progress__pivot').then(function (rect) { this.getRect('.van-progress__pivot').then(rect => {
_this.set({ this.set({
pivotWidth: rect.width || 0 pivotWidth: rect.width || 0
}); });
}); });

1
dist/radio-group/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -4,10 +4,8 @@ VantComponent({
relation: { relation: {
name: 'radio', name: 'radio',
type: 'descendant', type: 'descendant',
linked: function linked(target) { linked(target) {
var _this$data = this.data, const { value, disabled } = this.data;
value = _this$data.value,
disabled = _this$data.disabled;
target.set({ target.set({
value: value, value: value,
disabled: disabled || target.data.disabled disabled: disabled || target.data.disabled
@ -19,20 +17,16 @@ VantComponent({
disabled: Boolean disabled: Boolean
}, },
watch: { watch: {
value: function value(_value) { value(value) {
var children = this.getRelationNodes('../radio/index'); const children = this.getRelationNodes('../radio/index');
children.forEach(function (child) { children.forEach(child => {
child.set({ child.set({ value });
value: _value
});
}); });
}, },
disabled: function disabled(_disabled) { disabled(disabled) {
var children = this.getRelationNodes('../radio/index'); const children = this.getRelationNodes('../radio/index');
children.forEach(function (child) { children.forEach(child => {
child.set({ child.set({ disabled: disabled || child.data.disabled });
disabled: _disabled || child.data.disabled
});
}); });
} }
} }

1
dist/radio/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

8
dist/radio/index.js vendored
View File

@ -15,15 +15,15 @@ VantComponent({
checkedColor: String checkedColor: String
}, },
methods: { methods: {
emitChange: function emitChange(value) { emitChange(value) {
var instance = this.getRelationNodes('../radio-group/index')[0] || this; const instance = this.getRelationNodes('../radio-group/index')[0] || this;
instance.$emit('input', value); instance.$emit('input', value);
instance.$emit('change', value); instance.$emit('change', value);
}, },
onChange: function onChange(event) { onChange(event) {
this.emitChange(event.detail.value); this.emitChange(event.detail.value);
}, },
onClickLabel: function onClickLabel() { onClickLabel() {
if (!this.data.disabled && !this.data.labelDisabled) { if (!this.data.disabled && !this.data.labelDisabled) {
this.emitChange(this.data.name); this.emitChange(this.data.name);
} }

1
dist/rate/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

55
dist/rate/index.js vendored
View File

@ -1,5 +1,3 @@
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
field: true, field: true,
@ -44,54 +42,37 @@ VantComponent({
innerValue: 0 innerValue: 0
}, },
watch: { watch: {
value: function value(_value) { value(value) {
if (_value !== this.data.innerValue) { if (value !== this.data.innerValue) {
this.set({ this.set({ innerValue: value });
innerValue: _value
});
} }
} }
}, },
computed: { computed: {
list: function list() { list() {
var _this$data = this.data, const { count, innerValue } = this.data;
count = _this$data.count, return Array.from({ length: count }, (_, index) => index < innerValue);
innerValue = _this$data.innerValue;
return Array.from({
length: count
}, function (_, index) {
return index < innerValue;
});
} }
}, },
methods: { methods: {
onSelect: function onSelect(event) { onSelect(event) {
var data = this.data; const { data } = this;
var index = event.currentTarget.dataset.index; const { index } = event.currentTarget.dataset;
if (!data.disabled && !data.readonly) { if (!data.disabled && !data.readonly) {
this.set({ this.set({ innerValue: index + 1 });
innerValue: index + 1
});
this.$emit('input', index + 1); this.$emit('input', index + 1);
this.$emit('change', index + 1); this.$emit('change', index + 1);
} }
}, },
onTouchMove: function onTouchMove(event) { onTouchMove(event) {
var _this = this; const { clientX, clientY } = event.touches[0];
this.getRect('.van-rate__item', true).then(list => {
var _event$touches$ = event.touches[0], const target = list.find(item => clientX >= item.left &&
clientX = _event$touches$.clientX, clientX <= item.right &&
clientY = _event$touches$.clientY; clientY >= item.top &&
this.getRect('.van-rate__item', true).then(function (list) { clientY <= item.bottom);
var target = list.find(function (item) {
return clientX >= item.left && clientX <= item.right && clientY >= item.top && clientY <= item.bottom;
});
if (target != null) { if (target != null) {
_this.onSelect(_extends({}, event, { this.onSelect(Object.assign({}, event, { currentTarget: target }));
currentTarget: target
}));
} }
}); });
} }

1
dist/row/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

24
dist/row/index.js vendored
View File

@ -3,7 +3,7 @@ VantComponent({
relation: { relation: {
name: 'col', name: 'col',
type: 'descendant', type: 'descendant',
linked: function linked(target) { linked(target) {
if (this.data.gutter) { if (this.data.gutter) {
target.setGutter(this.data.gutter); target.setGutter(this.data.gutter);
} }
@ -15,23 +15,21 @@ VantComponent({
watch: { watch: {
gutter: 'setGutter' gutter: 'setGutter'
}, },
mounted: function mounted() { mounted() {
if (this.data.gutter) { if (this.data.gutter) {
this.setGutter(); this.setGutter();
} }
}, },
methods: { methods: {
setGutter: function setGutter() { setGutter() {
var _this = this; const { gutter } = this.data;
const margin = `-${Number(gutter) / 2}px`;
var gutter = this.data.gutter; const style = gutter
var margin = "-" + Number(gutter) / 2 + "px"; ? `margin-right: ${margin}; margin-left: ${margin};`
var style = gutter ? "margin-right: " + margin + "; margin-left: " + margin + ";" : ''; : '';
this.set({ this.set({ style });
style: style this.getRelationNodes('../col/index').forEach(col => {
}); col.setGutter(this.data.gutter);
this.getRelationNodes('../col/index').forEach(function (col) {
col.setGutter(_this.data.gutter);
}); });
} }
} }

1
dist/search/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

22
dist/search/index.js vendored
View File

@ -22,30 +22,26 @@ VantComponent({
} }
}, },
methods: { methods: {
onChange: function onChange(event) { onChange(event) {
this.set({ this.set({ value: event.detail });
value: event.detail
});
this.$emit('change', event.detail); this.$emit('change', event.detail);
}, },
onCancel: function onCancel() { onCancel() {
this.set({ this.set({ value: '' });
value: ''
});
this.$emit('cancel'); this.$emit('cancel');
this.$emit('change', ''); this.$emit('change', '');
}, },
onSearch: function onSearch() { onSearch() {
this.$emit('search', this.data.value); this.$emit('search', this.data.value);
}, },
onFocus: function onFocus() { onFocus() {
this.$emit('focus'); this.$emit('focus');
}, },
onBlur: function onBlur() { onBlur() {
this.$emit('blur'); this.$emit('blur');
}, },
onClear: function onClear() { onClear() {
this.$emit('clear'); this.$emit('clear');
} },
} }
}); });

1
dist/slider/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

Some files were not shown because too many files have changed in this diff Show More