chore: update eslint
parent
a892a8908b
commit
d459c8dabe
|
@ -21,11 +21,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"files": ["**/types/**/*.ts"],
|
"files": ["*.ts"],
|
||||||
"extends": ["@vue/typescript/recommended"],
|
"extends": ["@vue/typescript/recommended"],
|
||||||
"rules": {
|
"rules": {
|
||||||
"@typescript-eslint/no-explicit-any": 0,
|
"@typescript-eslint/no-explicit-any": 0,
|
||||||
"@typescript-eslint/ban-types": 0
|
"@typescript-eslint/ban-types": 0,
|
||||||
|
"@typescript-eslint/explicit-module-boundary-types": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { getOptionProps } from './props-util';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
setState(state = {}, callback) {
|
setState(state = {}, callback: () => any) {
|
||||||
let newState = typeof state === 'function' ? state(this.$data, this.$props) : state;
|
let newState = typeof state === 'function' ? state(this.$data, this.$props) : state;
|
||||||
if (this.getDerivedStateFromProps) {
|
if (this.getDerivedStateFromProps) {
|
||||||
const s = this.getDerivedStateFromProps(getOptionProps(this), {
|
const s = this.getDerivedStateFromProps(getOptionProps(this), {
|
||||||
|
@ -25,6 +25,7 @@ export default {
|
||||||
},
|
},
|
||||||
__emit() {
|
__emit() {
|
||||||
// 直接调用事件,底层组件不需要vueTool记录events
|
// 直接调用事件,底层组件不需要vueTool记录events
|
||||||
|
// eslint-disable-next-line prefer-rest-params
|
||||||
const args = [].slice.call(arguments, 0);
|
const args = [].slice.call(arguments, 0);
|
||||||
let eventName = args[0];
|
let eventName = args[0];
|
||||||
eventName = `on${eventName[0].toUpperCase()}${eventName.substring(1)}`;
|
eventName = `on${eventName[0].toUpperCase()}${eventName.substring(1)}`;
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { getOptionProps } from './props-util';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
setState(state = {}, callback) {
|
setState(state = {}, callback: () => any) {
|
||||||
let newState = typeof state === 'function' ? state(this, this.$props) : state;
|
let newState = typeof state === 'function' ? state(this, this.$props) : state;
|
||||||
if (this.getDerivedStateFromProps) {
|
if (this.getDerivedStateFromProps) {
|
||||||
const s = this.getDerivedStateFromProps(getOptionProps(this), {
|
const s = this.getDerivedStateFromProps(getOptionProps(this), {
|
||||||
|
@ -25,6 +25,7 @@ export default {
|
||||||
},
|
},
|
||||||
__emit() {
|
__emit() {
|
||||||
// 直接调用事件,底层组件不需要vueTool记录events
|
// 直接调用事件,底层组件不需要vueTool记录events
|
||||||
|
// eslint-disable-next-line prefer-rest-params
|
||||||
const args = [].slice.call(arguments, 0);
|
const args = [].slice.call(arguments, 0);
|
||||||
let eventName = args[0];
|
let eventName = args[0];
|
||||||
eventName = `on${eventName[0].toUpperCase()}${eventName.substring(1)}`;
|
eventName = `on${eventName[0].toUpperCase()}${eventName.substring(1)}`;
|
||||||
|
|
|
@ -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,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -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;
|
|
|
@ -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);
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -1,25 +1,31 @@
|
||||||
function onCompositionStart(e) {
|
function onCompositionStart(e: Event) {
|
||||||
e.target.composing = true;
|
(e.target as any).composing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCompositionEnd(e) {
|
function onCompositionEnd(e: Event) {
|
||||||
// prevent triggering an input event for no reason
|
const target = e.target as any;
|
||||||
if (!e.target.composing) return;
|
if (target.composing) {
|
||||||
e.target.composing = false;
|
target.composing = false;
|
||||||
trigger(e.target, 'input');
|
trigger(target, 'input');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function trigger(el, type) {
|
function trigger(el: HTMLElement, type: string) {
|
||||||
const e = document.createEvent('HTMLEvents');
|
const e = document.createEvent('HTMLEvents');
|
||||||
e.initEvent(type, true, true);
|
e.initEvent(type, true, true);
|
||||||
el.dispatchEvent(e);
|
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);
|
el.addEventListener(event, handler, options);
|
||||||
}
|
}
|
||||||
const antInput = {
|
const antInput = {
|
||||||
created(el, binding) {
|
created(el: Element, binding: { modifiers: { lazy: any } }) {
|
||||||
if (!binding.modifiers || !binding.modifiers.lazy) {
|
if (!binding.modifiers || !binding.modifiers.lazy) {
|
||||||
addEventListener(el, 'compositionstart', onCompositionStart);
|
addEventListener(el, 'compositionstart', onCompositionStart);
|
||||||
addEventListener(el, 'compositionend', onCompositionEnd);
|
addEventListener(el, 'compositionend', onCompositionEnd);
|
||||||
|
|
|
@ -11,13 +11,13 @@ const attributes = `accept acceptCharset accessKey action allowFullScreen allowT
|
||||||
shape size sizes span spellCheck src srcDoc srcLang srcSet start step style
|
shape size sizes span spellCheck src srcDoc srcLang srcSet start step style
|
||||||
summary tabIndex target title type useMap value width wmode wrap`;
|
summary tabIndex target title type useMap value width wmode wrap`;
|
||||||
|
|
||||||
const eventsName = `onCopy onCut onPaste onCompositionEnd onCompositionStart onCompositionUpdate onKeyDown
|
const eventsName = `onCopy onCut onPaste onCompositionend onCompositionstart onCompositionupdate onKeydown
|
||||||
onKeyPress onKeyUp onFocus onBlur onChange onInput onSubmit onClick onContextMenu onDoubleClick
|
onKeypress onKeyup onFocus onBlur onChange onInput onSubmit onClick onContextmenu onDoubleclick onDblclick
|
||||||
onDrag onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop onMouseDown
|
onDrag onDragend onDragenter onDragexit onDragleave onDragover onDragstart onDrop onMousedown
|
||||||
onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver onMouseUp onSelect onTouchCancel
|
onMouseenter onMouseleave onMousemove onMouseout onMouseover onMouseup onSelect onTouchcancel
|
||||||
onTouchEnd onTouchMove onTouchStart onScroll onWheel onAbort onCanPlay onCanPlayThrough
|
onTouchend onTouchmove onTouchstart onScroll onWheel onAbort onCanplay onCanplaythrough
|
||||||
onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata
|
onDurationchange onEmptied onEncrypted onEnded onError onLoadedsata onLoadedmetadata
|
||||||
onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad onError`;
|
onLoadstart onPause onPlay onPlaying onProgress onRatechange onSeeked onSeeking onStalled onSuspend onTimeupdate onVolumechange onWaiting onLoad onError`;
|
||||||
|
|
||||||
const propList = `${attributes} ${eventsName}`.split(/[\s\n]+/);
|
const propList = `${attributes} ${eventsName}`.split(/[\s\n]+/);
|
||||||
|
|
||||||
|
@ -25,17 +25,23 @@ const propList = `${attributes} ${eventsName}`.split(/[\s\n]+/);
|
||||||
const ariaPrefix = 'aria-';
|
const ariaPrefix = 'aria-';
|
||||||
const dataPrefix = 'data-';
|
const dataPrefix = 'data-';
|
||||||
|
|
||||||
function match(key, prefix) {
|
function match(key: string, prefix: string) {
|
||||||
return key.indexOf(prefix) === 0;
|
return key.indexOf(prefix) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PickConfig {
|
||||||
|
aria?: boolean;
|
||||||
|
data?: boolean;
|
||||||
|
attr?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Picker props from exist props with filter
|
* Picker props from exist props with filter
|
||||||
* @param props Passed props
|
* @param props Passed props
|
||||||
* @param ariaOnly boolean | { aria?: boolean; data?: boolean; attr?: boolean; } filter config
|
* @param ariaOnly boolean | { aria?: boolean; data?: boolean; attr?: boolean; } filter config
|
||||||
*/
|
*/
|
||||||
export default function pickAttrs(props, ariaOnly = false) {
|
export default function pickAttrs(props: object, ariaOnly: boolean | PickConfig = false) {
|
||||||
let mergedConfig;
|
let mergedConfig: PickConfig;
|
||||||
if (ariaOnly === false) {
|
if (ariaOnly === false) {
|
||||||
mergedConfig = {
|
mergedConfig = {
|
||||||
aria: true,
|
aria: true,
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
export default function syncWatch(fn) {
|
|
||||||
return {
|
|
||||||
handler: fn,
|
|
||||||
flush: 'sync',
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Reference in New Issue