chore: update eslint

pull/2930/head^2
tanjinzhou 2020-09-30 17:15:17 +08:00
parent a892a8908b
commit d459c8dabe
10 changed files with 39 additions and 219 deletions

View File

@ -21,11 +21,12 @@
}
},
{
"files": ["**/types/**/*.ts"],
"files": ["*.ts"],
"extends": ["@vue/typescript/recommended"],
"rules": {
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/ban-types": 0
"@typescript-eslint/ban-types": 0,
"@typescript-eslint/explicit-module-boundary-types": 0
}
}
],

View File

@ -2,7 +2,7 @@ import { getOptionProps } from './props-util';
export default {
methods: {
setState(state = {}, callback) {
setState(state = {}, callback: () => any) {
let newState = typeof state === 'function' ? state(this.$data, this.$props) : state;
if (this.getDerivedStateFromProps) {
const s = this.getDerivedStateFromProps(getOptionProps(this), {
@ -25,6 +25,7 @@ export default {
},
__emit() {
// 直接调用事件底层组件不需要vueTool记录events
// eslint-disable-next-line prefer-rest-params
const args = [].slice.call(arguments, 0);
let eventName = args[0];
eventName = `on${eventName[0].toUpperCase()}${eventName.substring(1)}`;

View File

@ -2,7 +2,7 @@ import { getOptionProps } from './props-util';
export default {
methods: {
setState(state = {}, callback) {
setState(state = {}, callback: () => any) {
let newState = typeof state === 'function' ? state(this, this.$props) : state;
if (this.getDerivedStateFromProps) {
const s = this.getDerivedStateFromProps(getOptionProps(this), {
@ -25,6 +25,7 @@ export default {
},
__emit() {
// 直接调用事件底层组件不需要vueTool记录events
// eslint-disable-next-line prefer-rest-params
const args = [].slice.call(arguments, 0);
let eventName = args[0];
eventName = `on${eventName[0].toUpperCase()}${eventName.substring(1)}`;

View File

@ -1,98 +0,0 @@
import PropTypes from './vue-types';
export default {
props: {
autoMount: PropTypes.bool.def(true),
autoDestroy: PropTypes.bool.def(true),
visible: PropTypes.bool,
forceRender: PropTypes.bool.def(false),
parent: PropTypes.any,
getComponent: PropTypes.func.isRequired,
getContainer: PropTypes.func.isRequired,
children: PropTypes.func.isRequired,
},
mounted() {
if (this.autoMount) {
this.renderComponent();
}
},
updated() {
if (this.autoMount) {
this.renderComponent();
}
},
beforeUnmount() {
if (this.autoDestroy) {
this.removeContainer();
}
},
methods: {
removeContainer() {
if (this.container) {
this._component && this._component.$destroy();
this.container.parentNode.removeChild(this.container);
this.container = null;
this._component = null;
}
},
renderComponent(props = {}, ready) {
const { visible, forceRender, getContainer, parent } = this;
const self = this;
if (visible || parent._component || parent.$refs._component || forceRender) {
let el = this.componentEl;
if (!this.container) {
this.container = getContainer();
el = document.createElement('div');
this.componentEl = el;
this.container.appendChild(el);
}
// self.getComponent 不要放在 render 中,会因为响应式数据问题导致,多次触发 render
const com = { component: self.getComponent(props) };
if (!this._component) {
this._component = new this.$root.constructor({
el,
parent: self,
data: {
_com: com,
},
mounted() {
this.$nextTick(() => {
if (ready) {
ready.call(self);
}
});
},
updated() {
this.$nextTick(() => {
if (ready) {
ready.call(self);
}
});
},
methods: {
setComponent(_com) {
this.$data._com = _com;
},
},
render() {
return this.$data._com.component;
},
});
} else {
this._component.setComponent(com);
}
}
},
},
render() {
return this.children({
renderComponent: this.renderComponent,
removeContainer: this.removeContainer,
});
},
};

View File

@ -1,30 +0,0 @@
import { nextTick } from 'vue';
const antvRef = {
beforeMount: function bind(el, binding, vnode) {
nextTick(function() {
binding.value(el, vnode.key);
});
binding.value(el, vnode.key);
},
updated: function update(el, binding, vnode, oldVnode) {
if (oldVnode && oldVnode.directives) {
let oldBinding = oldVnode.directives.find(function(directive) {
return directive === antvRef;
});
if (oldBinding && oldBinding.value !== binding.value) {
oldBinding && oldBinding.value(null, oldVnode.key);
binding.value(el, vnode.key);
return;
}
}
// Should not have this situation
if (vnode.el !== oldVnode.el) {
binding.value(el, vnode.key);
}
},
unmounted: function unbind(el, binding, vnode) {
binding.value(null, vnode.key);
},
};
export default antvRef;

View File

@ -1,12 +0,0 @@
import ref from 'vue-ref';
// import { antInput } from './antInputDirective';
import { antDecorator } from './FormDecoratorDirective';
import { antPortal } from './portalDirective';
export default {
install: Vue => {
Vue.use(ref, { name: 'ant-ref' });
antDecorator(Vue);
antPortal(Vue);
},
};

View File

@ -1,25 +1,31 @@
function onCompositionStart(e) {
e.target.composing = true;
function onCompositionStart(e: Event) {
(e.target as any).composing = true;
}
function onCompositionEnd(e) {
// prevent triggering an input event for no reason
if (!e.target.composing) return;
e.target.composing = false;
trigger(e.target, 'input');
function onCompositionEnd(e: Event) {
const target = e.target as any;
if (target.composing) {
target.composing = false;
trigger(target, 'input');
}
}
function trigger(el, type) {
function trigger(el: HTMLElement, type: string) {
const e = document.createEvent('HTMLEvents');
e.initEvent(type, true, true);
el.dispatchEvent(e);
}
export function addEventListener(el, event, handler, options) {
export function addEventListener(
el: Element,
event: string,
handler: EventListener,
options?: EventListenerOptions,
) {
el.addEventListener(event, handler, options);
}
const antInput = {
created(el, binding) {
created(el: Element, binding: { modifiers: { lazy: any } }) {
if (!binding.modifiers || !binding.modifiers.lazy) {
addEventListener(el, 'compositionstart', onCompositionStart);
addEventListener(el, 'compositionend', onCompositionEnd);

View File

@ -11,13 +11,13 @@ const attributes = `accept acceptCharset accessKey action allowFullScreen allowT
shape size sizes span spellCheck src srcDoc srcLang srcSet start step style
summary tabIndex target title type useMap value width wmode wrap`;
const eventsName = `onCopy onCut onPaste onCompositionEnd onCompositionStart onCompositionUpdate onKeyDown
onKeyPress onKeyUp onFocus onBlur onChange onInput onSubmit onClick onContextMenu onDoubleClick
onDrag onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop onMouseDown
onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver onMouseUp onSelect onTouchCancel
onTouchEnd onTouchMove onTouchStart onScroll onWheel onAbort onCanPlay onCanPlayThrough
onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata
onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad onError`;
const eventsName = `onCopy onCut onPaste onCompositionend onCompositionstart onCompositionupdate onKeydown
onKeypress onKeyup onFocus onBlur onChange onInput onSubmit onClick onContextmenu onDoubleclick onDblclick
onDrag onDragend onDragenter onDragexit onDragleave onDragover onDragstart onDrop onMousedown
onMouseenter onMouseleave onMousemove onMouseout onMouseover onMouseup onSelect onTouchcancel
onTouchend onTouchmove onTouchstart onScroll onWheel onAbort onCanplay onCanplaythrough
onDurationchange onEmptied onEncrypted onEnded onError onLoadedsata onLoadedmetadata
onLoadstart onPause onPlay onPlaying onProgress onRatechange onSeeked onSeeking onStalled onSuspend onTimeupdate onVolumechange onWaiting onLoad onError`;
const propList = `${attributes} ${eventsName}`.split(/[\s\n]+/);
@ -25,17 +25,23 @@ const propList = `${attributes} ${eventsName}`.split(/[\s\n]+/);
const ariaPrefix = 'aria-';
const dataPrefix = 'data-';
function match(key, prefix) {
function match(key: string, prefix: string) {
return key.indexOf(prefix) === 0;
}
export interface PickConfig {
aria?: boolean;
data?: boolean;
attr?: boolean;
}
/**
* Picker props from exist props with filter
* @param props Passed props
* @param ariaOnly boolean | { aria?: boolean; data?: boolean; attr?: boolean; } filter config
*/
export default function pickAttrs(props, ariaOnly = false) {
let mergedConfig;
export default function pickAttrs(props: object, ariaOnly: boolean | PickConfig = false) {
let mergedConfig: PickConfig;
if (ariaOnly === false) {
mergedConfig = {
aria: true,

View File

@ -1,49 +0,0 @@
import { createVNode } from 'vue';
import PropTypes from './vue-types';
import { getOptionProps } from './props-util';
function getDisplayName(WrappedComponent) {
return WrappedComponent.name || 'Component';
}
let k = 1;
export default function wrapWithConnect(WrappedComponent) {
const tempProps = WrappedComponent.props || {};
const methods = WrappedComponent.methods || {};
const props = {};
Object.keys(tempProps).forEach(k => {
props[k] = { ...tempProps[k], required: false };
});
WrappedComponent.props.__propsSymbol__ = PropTypes.any;
WrappedComponent.props.children = PropTypes.array.def([]);
const ProxyWrappedComponent = {
props,
inheritAttrs: false,
name: `Proxy_${getDisplayName(WrappedComponent)}`,
methods: {
getProxyWrappedInstance() {
return this.$refs.wrappedInstance;
},
},
render() {
const { $slots = {}, $attrs } = this;
const props = getOptionProps(this);
const wrapProps = {
...props,
...$attrs,
__propsSymbol__: k++,
ref: 'wrappedInstance',
};
const slots = {};
for (let [key, value] of Object.entries($slots)) {
slots[key] = () => value();
}
return createVNode(WrappedComponent, wrapProps, slots);
},
};
Object.keys(methods).map(m => {
ProxyWrappedComponent.methods[m] = function() {
return this.getProxyWrappedInstance()[m](...arguments);
};
});
return ProxyWrappedComponent;
}

View File

@ -1,6 +0,0 @@
export default function syncWatch(fn) {
return {
handler: fn,
flush: 'sync',
};
}