first
This commit is contained in:
29
node_modules/vant/es/mixins/bind-event.js
generated
vendored
Normal file
29
node_modules/vant/es/mixins/bind-event.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Bind event when mounted or activated
|
||||
*/
|
||||
import { on, off } from '../utils/dom/event';
|
||||
var uid = 0;
|
||||
export function BindEventMixin(handler) {
|
||||
var key = "binded_" + uid++;
|
||||
|
||||
function bind() {
|
||||
if (!this[key]) {
|
||||
handler.call(this, on, true);
|
||||
this[key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
function unbind() {
|
||||
if (this[key]) {
|
||||
handler.call(this, off, false);
|
||||
this[key] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
mounted: bind,
|
||||
activated: bind,
|
||||
deactivated: unbind,
|
||||
beforeDestroy: unbind
|
||||
};
|
||||
}
|
139
node_modules/vant/es/mixins/checkbox.js
generated
vendored
Normal file
139
node_modules/vant/es/mixins/checkbox.js
generated
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
/**
|
||||
* Common part of Checkbox & Radio
|
||||
*/
|
||||
import Icon from '../icon';
|
||||
import { FieldMixin } from './field';
|
||||
import { ChildrenMixin } from './relation';
|
||||
import { addUnit } from '../utils';
|
||||
export var CheckboxMixin = function CheckboxMixin(_ref) {
|
||||
var parent = _ref.parent,
|
||||
bem = _ref.bem,
|
||||
role = _ref.role;
|
||||
return {
|
||||
mixins: [ChildrenMixin(parent), FieldMixin],
|
||||
props: {
|
||||
name: null,
|
||||
value: null,
|
||||
disabled: Boolean,
|
||||
iconSize: [Number, String],
|
||||
checkedColor: String,
|
||||
labelPosition: String,
|
||||
labelDisabled: Boolean,
|
||||
shape: {
|
||||
type: String,
|
||||
default: 'round'
|
||||
},
|
||||
bindGroup: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
disableBindRelation: function disableBindRelation() {
|
||||
return !this.bindGroup;
|
||||
},
|
||||
isDisabled: function isDisabled() {
|
||||
return this.parent && this.parent.disabled || this.disabled;
|
||||
},
|
||||
direction: function direction() {
|
||||
return this.parent && this.parent.direction || null;
|
||||
},
|
||||
iconStyle: function iconStyle() {
|
||||
var checkedColor = this.checkedColor || this.parent && this.parent.checkedColor;
|
||||
|
||||
if (checkedColor && this.checked && !this.isDisabled) {
|
||||
return {
|
||||
borderColor: checkedColor,
|
||||
backgroundColor: checkedColor
|
||||
};
|
||||
}
|
||||
},
|
||||
tabindex: function tabindex() {
|
||||
if (this.isDisabled || role === 'radio' && !this.checked) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onClick: function onClick(event) {
|
||||
var _this = this;
|
||||
|
||||
var target = event.target;
|
||||
var icon = this.$refs.icon;
|
||||
var iconClicked = icon === target || (icon == null ? void 0 : icon.contains(target));
|
||||
|
||||
if (!this.isDisabled && (iconClicked || !this.labelDisabled)) {
|
||||
this.toggle(); // wait for toggle method to complete
|
||||
// so we can get the changed value in the click event listener
|
||||
|
||||
setTimeout(function () {
|
||||
_this.$emit('click', event);
|
||||
});
|
||||
} else {
|
||||
this.$emit('click', event);
|
||||
}
|
||||
},
|
||||
genIcon: function genIcon() {
|
||||
var h = this.$createElement;
|
||||
var checked = this.checked;
|
||||
var iconSize = this.iconSize || this.parent && this.parent.iconSize;
|
||||
return h("div", {
|
||||
"ref": "icon",
|
||||
"class": bem('icon', [this.shape, {
|
||||
disabled: this.isDisabled,
|
||||
checked: checked
|
||||
}]),
|
||||
"style": {
|
||||
fontSize: addUnit(iconSize)
|
||||
}
|
||||
}, [this.slots('icon', {
|
||||
checked: checked
|
||||
}) || h(Icon, {
|
||||
"attrs": {
|
||||
"name": "success"
|
||||
},
|
||||
"style": this.iconStyle
|
||||
})]);
|
||||
},
|
||||
genLabel: function genLabel() {
|
||||
var h = this.$createElement;
|
||||
var slot = this.slots();
|
||||
|
||||
if (slot) {
|
||||
return h("span", {
|
||||
"class": bem('label', [this.labelPosition, {
|
||||
disabled: this.isDisabled
|
||||
}])
|
||||
}, [slot]);
|
||||
}
|
||||
}
|
||||
},
|
||||
render: function render() {
|
||||
var h = arguments[0];
|
||||
var Children = [this.genIcon()];
|
||||
|
||||
if (this.labelPosition === 'left') {
|
||||
Children.unshift(this.genLabel());
|
||||
} else {
|
||||
Children.push(this.genLabel());
|
||||
}
|
||||
|
||||
return h("div", {
|
||||
"attrs": {
|
||||
"role": role,
|
||||
"tabindex": this.tabindex,
|
||||
"aria-checked": String(this.checked)
|
||||
},
|
||||
"class": bem([{
|
||||
disabled: this.isDisabled,
|
||||
'label-disabled': this.labelDisabled
|
||||
}, this.direction]),
|
||||
"on": {
|
||||
"click": this.onClick
|
||||
}
|
||||
}, [Children]);
|
||||
}
|
||||
};
|
||||
};
|
33
node_modules/vant/es/mixins/click-outside.js
generated
vendored
Normal file
33
node_modules/vant/es/mixins/click-outside.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Listen to click outside event
|
||||
*/
|
||||
import { on, off } from '../utils/dom/event';
|
||||
export var ClickOutsideMixin = function ClickOutsideMixin(config) {
|
||||
return {
|
||||
props: {
|
||||
closeOnClickOutside: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
data: function data() {
|
||||
var _this = this;
|
||||
|
||||
var clickOutsideHandler = function clickOutsideHandler(event) {
|
||||
if (_this.closeOnClickOutside && !_this.$el.contains(event.target)) {
|
||||
_this[config.method]();
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
clickOutsideHandler: clickOutsideHandler
|
||||
};
|
||||
},
|
||||
mounted: function mounted() {
|
||||
on(document, config.event, this.clickOutsideHandler);
|
||||
},
|
||||
beforeDestroy: function beforeDestroy() {
|
||||
off(document, config.event, this.clickOutsideHandler);
|
||||
}
|
||||
};
|
||||
};
|
38
node_modules/vant/es/mixins/close-on-popstate.js
generated
vendored
Normal file
38
node_modules/vant/es/mixins/close-on-popstate.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
import { on, off } from '../utils/dom/event';
|
||||
import { BindEventMixin } from './bind-event';
|
||||
export var CloseOnPopstateMixin = {
|
||||
mixins: [BindEventMixin(function (bind, isBind) {
|
||||
this.handlePopstate(isBind && this.closeOnPopstate);
|
||||
})],
|
||||
props: {
|
||||
closeOnPopstate: Boolean
|
||||
},
|
||||
data: function data() {
|
||||
return {
|
||||
bindStatus: false
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
closeOnPopstate: function closeOnPopstate(val) {
|
||||
this.handlePopstate(val);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onPopstate: function onPopstate() {
|
||||
this.close();
|
||||
this.shouldReopen = false;
|
||||
},
|
||||
handlePopstate: function handlePopstate(bind) {
|
||||
/* istanbul ignore if */
|
||||
if (this.$isServer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.bindStatus !== bind) {
|
||||
this.bindStatus = bind;
|
||||
var action = bind ? on : off;
|
||||
action(window, 'popstate', this.onPopstate);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
24
node_modules/vant/es/mixins/field.js
generated
vendored
Normal file
24
node_modules/vant/es/mixins/field.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
export var FieldMixin = {
|
||||
inject: {
|
||||
vanField: {
|
||||
default: null
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value: function value() {
|
||||
var field = this.vanField;
|
||||
|
||||
if (field) {
|
||||
field.resetValidation();
|
||||
field.validateWithTrigger('onChange');
|
||||
}
|
||||
}
|
||||
},
|
||||
created: function created() {
|
||||
var field = this.vanField;
|
||||
|
||||
if (field && !field.children) {
|
||||
field.children = this;
|
||||
}
|
||||
}
|
||||
};
|
18
node_modules/vant/es/mixins/popup/context.js
generated
vendored
Normal file
18
node_modules/vant/es/mixins/popup/context.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
export var context = {
|
||||
zIndex: 2000,
|
||||
lockCount: 0,
|
||||
stack: [],
|
||||
find: function find(vm) {
|
||||
return this.stack.filter(function (item) {
|
||||
return item.vm === vm;
|
||||
})[0];
|
||||
},
|
||||
remove: function remove(vm) {
|
||||
var item = this.find(vm);
|
||||
if (!item) return;
|
||||
item.vm = null;
|
||||
item.overlay = null;
|
||||
var index = this.stack.indexOf(item);
|
||||
this.stack.splice(index, 1);
|
||||
}
|
||||
};
|
220
node_modules/vant/es/mixins/popup/index.js
generated
vendored
Normal file
220
node_modules/vant/es/mixins/popup/index.js
generated
vendored
Normal file
@ -0,0 +1,220 @@
|
||||
// Context
|
||||
import { context } from './context';
|
||||
import { openOverlay, closeOverlay, updateOverlay, removeOverlay } from './overlay'; // Utils
|
||||
|
||||
import { on, off, preventDefault } from '../../utils/dom/event';
|
||||
import { removeNode } from '../../utils/dom/node';
|
||||
import { getScroller } from '../../utils/dom/scroll'; // Mixins
|
||||
|
||||
import { TouchMixin } from '../touch';
|
||||
import { PortalMixin } from '../portal';
|
||||
import { CloseOnPopstateMixin } from '../close-on-popstate';
|
||||
export var popupMixinProps = {
|
||||
// Initial rendering animation
|
||||
transitionAppear: Boolean,
|
||||
// whether to show popup
|
||||
value: Boolean,
|
||||
// whether to show overlay
|
||||
overlay: Boolean,
|
||||
// overlay custom style
|
||||
overlayStyle: Object,
|
||||
// overlay custom class name
|
||||
overlayClass: String,
|
||||
// whether to close popup when overlay is clicked
|
||||
closeOnClickOverlay: Boolean,
|
||||
// z-index
|
||||
zIndex: [Number, String],
|
||||
// prevent body scroll
|
||||
lockScroll: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// whether to lazy render
|
||||
lazyRender: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
};
|
||||
export function PopupMixin(options) {
|
||||
if (options === void 0) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
return {
|
||||
mixins: [TouchMixin, CloseOnPopstateMixin, PortalMixin({
|
||||
afterPortal: function afterPortal() {
|
||||
if (this.overlay) {
|
||||
updateOverlay();
|
||||
}
|
||||
}
|
||||
})],
|
||||
provide: function provide() {
|
||||
return {
|
||||
vanPopup: this
|
||||
};
|
||||
},
|
||||
props: popupMixinProps,
|
||||
data: function data() {
|
||||
this.onReopenCallback = [];
|
||||
return {
|
||||
inited: this.value
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
shouldRender: function shouldRender() {
|
||||
return this.inited || !this.lazyRender;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value: function value(val) {
|
||||
var type = val ? 'open' : 'close';
|
||||
this.inited = this.inited || this.value;
|
||||
this[type]();
|
||||
|
||||
if (!options.skipToggleEvent) {
|
||||
this.$emit(type);
|
||||
}
|
||||
},
|
||||
overlay: 'renderOverlay'
|
||||
},
|
||||
mounted: function mounted() {
|
||||
if (this.value) {
|
||||
this.open();
|
||||
}
|
||||
},
|
||||
|
||||
/* istanbul ignore next */
|
||||
activated: function activated() {
|
||||
if (this.shouldReopen) {
|
||||
this.$emit('input', true);
|
||||
this.shouldReopen = false;
|
||||
}
|
||||
},
|
||||
beforeDestroy: function beforeDestroy() {
|
||||
removeOverlay(this);
|
||||
|
||||
if (this.opened) {
|
||||
this.removeLock();
|
||||
}
|
||||
|
||||
if (this.getContainer) {
|
||||
removeNode(this.$el);
|
||||
}
|
||||
},
|
||||
|
||||
/* istanbul ignore next */
|
||||
deactivated: function deactivated() {
|
||||
if (this.value) {
|
||||
this.close();
|
||||
this.shouldReopen = true;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
open: function open() {
|
||||
/* istanbul ignore next */
|
||||
if (this.$isServer || this.opened) {
|
||||
return;
|
||||
} // cover default zIndex
|
||||
|
||||
|
||||
if (this.zIndex !== undefined) {
|
||||
context.zIndex = this.zIndex;
|
||||
}
|
||||
|
||||
this.opened = true;
|
||||
this.renderOverlay();
|
||||
this.addLock();
|
||||
this.onReopenCallback.forEach(function (callback) {
|
||||
callback();
|
||||
});
|
||||
},
|
||||
addLock: function addLock() {
|
||||
if (this.lockScroll) {
|
||||
on(document, 'touchstart', this.touchStart);
|
||||
on(document, 'touchmove', this.onTouchMove);
|
||||
|
||||
if (!context.lockCount) {
|
||||
document.body.classList.add('van-overflow-hidden');
|
||||
}
|
||||
|
||||
context.lockCount++;
|
||||
}
|
||||
},
|
||||
removeLock: function removeLock() {
|
||||
if (this.lockScroll && context.lockCount) {
|
||||
context.lockCount--;
|
||||
off(document, 'touchstart', this.touchStart);
|
||||
off(document, 'touchmove', this.onTouchMove);
|
||||
|
||||
if (!context.lockCount) {
|
||||
document.body.classList.remove('van-overflow-hidden');
|
||||
}
|
||||
}
|
||||
},
|
||||
close: function close() {
|
||||
if (!this.opened) {
|
||||
return;
|
||||
}
|
||||
|
||||
closeOverlay(this);
|
||||
this.opened = false;
|
||||
this.removeLock();
|
||||
this.$emit('input', false);
|
||||
},
|
||||
onTouchMove: function onTouchMove(event) {
|
||||
this.touchMove(event);
|
||||
var direction = this.deltaY > 0 ? '10' : '01';
|
||||
var el = getScroller(event.target, this.$el);
|
||||
var scrollHeight = el.scrollHeight,
|
||||
offsetHeight = el.offsetHeight,
|
||||
scrollTop = el.scrollTop;
|
||||
var status = '11';
|
||||
/* istanbul ignore next */
|
||||
|
||||
if (scrollTop === 0) {
|
||||
status = offsetHeight >= scrollHeight ? '00' : '01';
|
||||
} else if (scrollTop + offsetHeight >= scrollHeight) {
|
||||
status = '10';
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
|
||||
|
||||
if (status !== '11' && this.direction === 'vertical' && !(parseInt(status, 2) & parseInt(direction, 2))) {
|
||||
preventDefault(event, true);
|
||||
}
|
||||
},
|
||||
renderOverlay: function renderOverlay() {
|
||||
var _this = this;
|
||||
|
||||
if (this.$isServer || !this.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.$nextTick(function () {
|
||||
_this.updateZIndex(_this.overlay ? 1 : 0);
|
||||
|
||||
if (_this.overlay) {
|
||||
openOverlay(_this, {
|
||||
zIndex: context.zIndex++,
|
||||
duration: _this.duration,
|
||||
className: _this.overlayClass,
|
||||
customStyle: _this.overlayStyle
|
||||
});
|
||||
} else {
|
||||
closeOverlay(_this);
|
||||
}
|
||||
});
|
||||
},
|
||||
updateZIndex: function updateZIndex(value) {
|
||||
if (value === void 0) {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
this.$el.style.zIndex = ++context.zIndex + value;
|
||||
},
|
||||
onReopen: function onReopen(callback) {
|
||||
this.onReopenCallback.push(callback);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
77
node_modules/vant/es/mixins/popup/overlay.js
generated
vendored
Normal file
77
node_modules/vant/es/mixins/popup/overlay.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import Overlay from '../../overlay';
|
||||
import { context } from './context';
|
||||
import { mount } from '../../utils/functional';
|
||||
import { removeNode } from '../../utils/dom/node';
|
||||
var defaultConfig = {
|
||||
className: '',
|
||||
customStyle: {}
|
||||
};
|
||||
|
||||
function mountOverlay(vm) {
|
||||
return mount(Overlay, {
|
||||
on: {
|
||||
// close popup when overlay clicked & closeOnClickOverlay is true
|
||||
click: function click() {
|
||||
vm.$emit('click-overlay');
|
||||
|
||||
if (vm.closeOnClickOverlay) {
|
||||
if (vm.onClickOverlay) {
|
||||
vm.onClickOverlay();
|
||||
} else {
|
||||
vm.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function updateOverlay(vm) {
|
||||
var item = context.find(vm);
|
||||
|
||||
if (item) {
|
||||
var el = vm.$el;
|
||||
var config = item.config,
|
||||
overlay = item.overlay;
|
||||
|
||||
if (el && el.parentNode) {
|
||||
el.parentNode.insertBefore(overlay.$el, el);
|
||||
}
|
||||
|
||||
_extends(overlay, defaultConfig, config, {
|
||||
show: true
|
||||
});
|
||||
}
|
||||
}
|
||||
export function openOverlay(vm, config) {
|
||||
var item = context.find(vm);
|
||||
|
||||
if (item) {
|
||||
item.config = config;
|
||||
} else {
|
||||
var overlay = mountOverlay(vm);
|
||||
context.stack.push({
|
||||
vm: vm,
|
||||
config: config,
|
||||
overlay: overlay
|
||||
});
|
||||
}
|
||||
|
||||
updateOverlay(vm);
|
||||
}
|
||||
export function closeOverlay(vm) {
|
||||
var item = context.find(vm);
|
||||
|
||||
if (item) {
|
||||
item.overlay.show = false;
|
||||
}
|
||||
}
|
||||
export function removeOverlay(vm) {
|
||||
var item = context.find(vm);
|
||||
|
||||
if (item) {
|
||||
removeNode(item.overlay.$el);
|
||||
context.remove(vm);
|
||||
}
|
||||
}
|
0
node_modules/vant/es/mixins/popup/type.js
generated
vendored
Normal file
0
node_modules/vant/es/mixins/popup/type.js
generated
vendored
Normal file
48
node_modules/vant/es/mixins/portal.js
generated
vendored
Normal file
48
node_modules/vant/es/mixins/portal.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
function getElement(selector) {
|
||||
if (typeof selector === 'string') {
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
|
||||
return selector();
|
||||
}
|
||||
|
||||
export function PortalMixin(_temp) {
|
||||
var _ref = _temp === void 0 ? {} : _temp,
|
||||
ref = _ref.ref,
|
||||
afterPortal = _ref.afterPortal;
|
||||
|
||||
return {
|
||||
props: {
|
||||
getContainer: [String, Function]
|
||||
},
|
||||
watch: {
|
||||
getContainer: 'portal'
|
||||
},
|
||||
mounted: function mounted() {
|
||||
if (this.getContainer) {
|
||||
this.portal();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
portal: function portal() {
|
||||
var getContainer = this.getContainer;
|
||||
var el = ref ? this.$refs[ref] : this.$el;
|
||||
var container;
|
||||
|
||||
if (getContainer) {
|
||||
container = getElement(getContainer);
|
||||
} else if (this.$parent) {
|
||||
container = this.$parent.$el;
|
||||
}
|
||||
|
||||
if (container && container !== el.parentNode) {
|
||||
container.appendChild(el);
|
||||
}
|
||||
|
||||
if (afterPortal) {
|
||||
afterPortal.call(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
76
node_modules/vant/es/mixins/relation.js
generated
vendored
Normal file
76
node_modules/vant/es/mixins/relation.js
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
import { sortChildren } from '../utils/vnodes';
|
||||
export function ChildrenMixin(_parent, options) {
|
||||
var _inject, _computed;
|
||||
|
||||
if (options === void 0) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
var indexKey = options.indexKey || 'index';
|
||||
return {
|
||||
inject: (_inject = {}, _inject[_parent] = {
|
||||
default: null
|
||||
}, _inject),
|
||||
computed: (_computed = {
|
||||
parent: function parent() {
|
||||
if (this.disableBindRelation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this[_parent];
|
||||
}
|
||||
}, _computed[indexKey] = function () {
|
||||
this.bindRelation();
|
||||
|
||||
if (this.parent) {
|
||||
return this.parent.children.indexOf(this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}, _computed),
|
||||
watch: {
|
||||
disableBindRelation: function disableBindRelation(val) {
|
||||
if (!val) {
|
||||
this.bindRelation();
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted: function mounted() {
|
||||
this.bindRelation();
|
||||
},
|
||||
beforeDestroy: function beforeDestroy() {
|
||||
var _this = this;
|
||||
|
||||
if (this.parent) {
|
||||
this.parent.children = this.parent.children.filter(function (item) {
|
||||
return item !== _this;
|
||||
});
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
bindRelation: function bindRelation() {
|
||||
if (!this.parent || this.parent.children.indexOf(this) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var children = [].concat(this.parent.children, [this]);
|
||||
sortChildren(children, this.parent);
|
||||
this.parent.children = children;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
export function ParentMixin(parent) {
|
||||
return {
|
||||
provide: function provide() {
|
||||
var _ref;
|
||||
|
||||
return _ref = {}, _ref[parent] = this, _ref;
|
||||
},
|
||||
data: function data() {
|
||||
return {
|
||||
children: []
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
23
node_modules/vant/es/mixins/slots.js
generated
vendored
Normal file
23
node_modules/vant/es/mixins/slots.js
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Use scopedSlots in Vue 2.6+
|
||||
* downgrade to slots in lower version
|
||||
*/
|
||||
export var SlotsMixin = {
|
||||
methods: {
|
||||
slots: function slots(name, props) {
|
||||
if (name === void 0) {
|
||||
name = 'default';
|
||||
}
|
||||
|
||||
var $slots = this.$slots,
|
||||
$scopedSlots = this.$scopedSlots;
|
||||
var scopedSlot = $scopedSlots[name];
|
||||
|
||||
if (scopedSlot) {
|
||||
return scopedSlot(props);
|
||||
}
|
||||
|
||||
return $slots[name];
|
||||
}
|
||||
}
|
||||
};
|
63
node_modules/vant/es/mixins/touch.js
generated
vendored
Normal file
63
node_modules/vant/es/mixins/touch.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
import { on } from '../utils/dom/event';
|
||||
|
||||
function getDirection(x, y) {
|
||||
if (x > y) {
|
||||
return 'horizontal';
|
||||
}
|
||||
|
||||
if (y > x) {
|
||||
return 'vertical';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
export var TouchMixin = {
|
||||
data: function data() {
|
||||
return {
|
||||
direction: ''
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
touchStart: function touchStart(event) {
|
||||
this.resetTouchStatus();
|
||||
this.startX = event.touches[0].clientX;
|
||||
this.startY = event.touches[0].clientY;
|
||||
},
|
||||
touchMove: function touchMove(event) {
|
||||
var touch = event.touches[0]; // safari back will set clientX to negative number
|
||||
|
||||
this.deltaX = touch.clientX < 0 ? 0 : touch.clientX - this.startX;
|
||||
this.deltaY = touch.clientY - this.startY;
|
||||
this.offsetX = Math.abs(this.deltaX);
|
||||
this.offsetY = Math.abs(this.deltaY); // lock direction when distance is greater than a certain value
|
||||
|
||||
var LOCK_DIRECTION_DISTANCE = 10;
|
||||
|
||||
if (!this.direction || this.offsetX < LOCK_DIRECTION_DISTANCE && this.offsetY < LOCK_DIRECTION_DISTANCE) {
|
||||
this.direction = getDirection(this.offsetX, this.offsetY);
|
||||
}
|
||||
},
|
||||
resetTouchStatus: function resetTouchStatus() {
|
||||
this.direction = '';
|
||||
this.deltaX = 0;
|
||||
this.deltaY = 0;
|
||||
this.offsetX = 0;
|
||||
this.offsetY = 0;
|
||||
},
|
||||
// avoid Vue 2.6 event bubble issues by manually binding events
|
||||
// https://github.com/vant-ui/vant/issues/3015
|
||||
bindTouchEvent: function bindTouchEvent(el) {
|
||||
var onTouchStart = this.onTouchStart,
|
||||
onTouchMove = this.onTouchMove,
|
||||
onTouchEnd = this.onTouchEnd;
|
||||
on(el, 'touchstart', onTouchStart);
|
||||
on(el, 'touchmove', onTouchMove);
|
||||
|
||||
if (onTouchEnd) {
|
||||
on(el, 'touchend', onTouchEnd);
|
||||
on(el, 'touchcancel', onTouchEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user