build: update compiler

fix #1591
This commit is contained in:
rex 2019-08-12 19:57:38 +08:00 committed by GitHub
parent bec0bd7abe
commit c9fcdd70bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
69 changed files with 2141 additions and 2141 deletions

View File

@ -1,25 +1,22 @@
const gulp = require('gulp'); const gulp = require('gulp');
const path = require('path'); const path = require('path');
const less = require('gulp-less'); const less = require('gulp-less');
const ts = require('gulp-typescript');
const insert = require('gulp-insert'); const insert = require('gulp-insert');
const rename = require('gulp-rename'); const rename = require('gulp-rename');
const postcss = require('gulp-postcss'); const postcss = require('gulp-postcss');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const tsConfig = path.resolve(__dirname, '../tsconfig.json');
const isProduction = process.env.NODE_ENV === 'production';
const src = path.join(__dirname, '../packages'); const src = path.join(__dirname, '../packages');
const libConfig = path.resolve(__dirname, '../tsconfig.lib.json');
const esConfig = path.resolve(__dirname, '../tsconfig.json');
const exampleConfig = path.resolve(__dirname, '../tsconfig.example.json');
const libDir = path.resolve(__dirname, '../lib'); const libDir = path.resolve(__dirname, '../lib');
const esDir = path.resolve(__dirname, '../dist'); const esDir = path.resolve(__dirname, '../dist');
const exampleDir = path.resolve(__dirname, '../example/dist'); const exampleDir = path.resolve(__dirname, '../example/dist');
const libConfig = {
target: 'es5',
lib: ['es2015', 'es2017', 'dom'],
module: 'commonjs',
declaration: false
};
const compileLess = dist => () => const compileLess = dist => () =>
gulp gulp
.src(`${src}/**/*.less`) .src(`${src}/**/*.less`)
@ -28,7 +25,7 @@ const compileLess = dist => () =>
.pipe( .pipe(
insert.transform((contents, file) => { insert.transform((contents, file) => {
if (!file.path.includes('packages' + path.sep + 'common')) { if (!file.path.includes('packages' + path.sep + 'common')) {
contents = `@import '../common/index.wxss';` + contents; contents = `@import '../common/index.wxss';${contents}`;
} }
return contents; return contents;
}) })
@ -40,35 +37,49 @@ const compileLess = dist => () =>
) )
.pipe(gulp.dest(dist)); .pipe(gulp.dest(dist));
const compileTs = (dist, config) => () => { const compileTs = (config, dest) => async () => {
const tsProject = ts.createProject(tsConfig, config); await exec(`npx tsc -p ${config}`);
return tsProject await exec(`npx tscpaths -p ${config} -s ../packages -o ../${dest}`);
.src()
.pipe(tsProject())
.on('error', () => {})
.pipe(gulp.dest(dist));
}; };
const copy = (dist, ext) => () => const copy = (dist, ext) => () =>
gulp.src(`${src}/**/*.${ext}`).pipe(gulp.dest(dist)); gulp.src(`${src}/**/*.${ext}`).pipe(gulp.dest(dist));
const compile = (dist, config) => const copyStatic = dist =>
gulp.parallel( gulp.parallel(copy(dist, 'wxml'), copy(dist, 'wxs'), copy(dist, 'json'));
compileTs(dist, config),
compileLess(dist),
copy(dist, 'wxml'),
copy(dist, 'wxs'),
copy(dist, 'json')
);
if (isProduction) { const clean = path => () => exec(`npx rimraf ${path}`);
gulp.series(compile(esDir), compile(libDir, libConfig))();
} else {
compile(exampleDir)();
gulp.watch(`${src}/**/*.ts`, compileTs(exampleDir)); module.exports = {
gulp.watch(`${src}/**/*.less`, compileLess(exampleDir)); buildEs: gulp.series(
gulp.watch(`${src}/**/*.wxml`, copy(exampleDir, 'wxml')); clean(esDir),
gulp.watch(`${src}/**/*.wxs`, copy(exampleDir, 'wxs')); gulp.parallel(
gulp.watch(`${src}/**/*.json`, copy(exampleDir, 'json')); compileTs(esConfig, esDir),
} compileLess(esDir),
copyStatic(esDir)
)
),
buildLib: gulp.series(
clean(libDir),
gulp.parallel(
compileTs(libConfig, libDir),
compileLess(libDir),
copyStatic(libDir)
)
),
buildExample: gulp.series(
clean(exampleDir),
gulp.parallel(
compileTs(exampleConfig, exampleDir),
compileLess(exampleDir),
copyStatic(exampleDir),
() => {
gulp.watch(`${src}/**/*.ts`, compileTs(exampleConfig, exampleDir));
gulp.watch(`${src}/**/*.less`, compileLess(exampleDir));
gulp.watch(`${src}/**/*.wxml`, copy(exampleDir, 'wxml'));
gulp.watch(`${src}/**/*.wxs`, copy(exampleDir, 'wxs'));
gulp.watch(`${src}/**/*.json`, copy(exampleDir, 'json'));
}
)
)
};

View File

@ -1,12 +1,15 @@
require('./compiler');
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
const serve = require('webpack-serve'); const serve = require('webpack-serve');
const config = require('./webpack.doc.dev'); const config = require('./webpack.doc.dev');
const dist = path.join(__dirname, '../example/dist'); const dist = path.join(__dirname, '../example/dist');
const icons = path.join(__dirname, '../node_modules/@vant/icons'); const icons = path.join(__dirname, '../node_modules/@vant/icons');
const { exec } = require('child_process');
const gulpConfig = path.resolve(__dirname, './compiler.js');
fs.removeSync(dist);
fs.copySync(icons, path.join(dist, '/@vant/icons')); fs.copySync(icons, path.join(dist, '/@vant/icons'));
serve({}, { config }); serve({}, { config });
exec(`npx gulp -f ${gulpConfig} buildExample`);

View File

@ -1,2 +1,3 @@
declare function VantComponent<Data, Props, Watch, Methods, Computed>(vantOptions?: VantComponentOptions<Data, Props, Watch, Methods, Computed, CombinedComponentInstance<Data, Props, Watch, Methods, Computed>>): void; import { VantComponentOptions, CombinedComponentInstance } from 'definitions/index';
declare function VantComponent<Data, Props, Methods, Computed>(vantOptions?: VantComponentOptions<Data, Props, Methods, Computed, CombinedComponentInstance<Data, Props, Methods, Computed>>): void;
export { VantComponent }; export { VantComponent };

32
dist/definitions/index.d.ts vendored Normal file
View File

@ -0,0 +1,32 @@
/// <reference types="miniprogram-api-typings" />
import { Weapp } from './weapp';
declare type RecordToAny<T> = {
[K in keyof T]: any;
};
declare type RecordToReturn<T> = {
[P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]> : T[P];
};
export declare type CombinedComponentInstance<Data, Props, Methods, Computed> = Methods & WechatMiniprogram.Component.TrivialInstance & Weapp.FormField & {
data: Data & RecordToReturn<Computed> & RecordToAny<Props>;
};
export interface VantComponentOptions<Data, Props, Methods, Computed, Instance> {
data?: Data;
field?: boolean;
classes?: string[];
mixins?: string[];
props?: Props & Weapp.PropertyOption;
watch?: Weapp.WatchOption<Instance>;
computed?: Computed & Weapp.ComputedOption<Instance>;
relation?: Weapp.RelationOption<Instance> & {
name: string;
};
relations?: {
[componentName: string]: Weapp.RelationOption<Instance>;
};
methods?: Methods & Weapp.MethodOption<Instance>;
beforeCreate?: (this: Instance) => void;
created?: (this: Instance) => void;
mounted?: (this: Instance) => void;
destroyed?: (this: Instance) => void;
}
export {};

0
dist/definitions/index.js vendored Normal file
View File

111
dist/definitions/weapp.d.ts vendored Normal file
View File

@ -0,0 +1,111 @@
/// <reference types="miniprogram-api-typings" />
export declare namespace Weapp {
interface FormField {
data: {
name: string;
value: any;
};
}
interface Target {
id: string;
tagName: string;
dataset: {
[key: string]: any;
};
}
interface Event {
/**
*
*/
type: string;
/**
*
*/
timeStamp: number;
/**
*
*/
target: Target;
/**
*
*/
currentTarget: Target;
/**
*
*/
detail: any;
}
interface Touch {
/**
*
*/
identifier: number;
/**
* X轴Y轴
*/
pageX: number;
/**
* X轴Y轴
*/
pageY: number;
/**
* X轴Y轴
*/
clientX: number;
/**
* X轴Y轴
*/
clientY: number;
}
interface TouchEvent extends Event {
touches: Array<Touch>;
changedTouches: Array<Touch>;
}
/**
* relation定义miniprogram-api-typings缺少this定义
*/
interface RelationOption<Instance> {
/** 目标组件的相对关系 */
type: 'parent' | 'child' | 'ancestor' | 'descendant';
/** 关系生命周期函数当关系被建立在页面节点树中时触发触发时机在组件attached生命周期之后 */
linked?(this: Instance, target: WechatMiniprogram.Component.TrivialInstance): void;
/** 关系生命周期函数当关系在页面节点树中发生改变时触发触发时机在组件moved生命周期之后 */
linkChanged?(this: Instance, target: WechatMiniprogram.Component.TrivialInstance): void;
/** 关系生命周期函数当关系脱离页面节点树时触发触发时机在组件detached生命周期之后 */
unlinked?(this: Instance, target: WechatMiniprogram.Component.TrivialInstance): void;
/** 如果这一项被设置则它表示关联的目标节点所应具有的behavior所有拥有这一behavior的组件节点都会被关联 */
target?: string;
}
/**
* obverser定义miniprogram-api-typings缺少this定义
*/
type Observer<Instance, T> = (this: Instance, newVal: T, oldVal: T, changedPath: Array<string | number>) => void;
/**
* watch定义
*/
interface WatchOption<Instance> {
[name: string]: string | Observer<Instance, any>;
}
/**
* methods定义miniprogram-api-typings缺少this定义
*/
interface MethodOption<Instance> {
[name: string]: (this: Instance, ...args: any[]) => any;
}
interface ComputedOption<Instance> {
[name: string]: (this: Instance) => any;
}
type PropertyType = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor | FunctionConstructor | null;
interface PropertyOption {
[name: string]: PropertyType | PropertyType[] | {
/** 属性类型 */
type: PropertyType | PropertyType[];
/** 属性初始值 */
value?: any;
/** 属性值被更改时的响应函数 */
observer?: string | Observer<WechatMiniprogram.Component.TrivialInstance, any>;
/** 属性的类型(可以指定多个) */
optionalTypes?: PropertyType[];
};
}
}

0
dist/definitions/weapp.js vendored Normal file
View File

View File

@ -1,10 +1,11 @@
/// <reference types="miniprogram-api-typings" />
declare type DialogAction = 'confirm' | 'cancel'; declare type DialogAction = 'confirm' | 'cancel';
declare type DialogOptions = { declare type DialogOptions = {
lang?: string; lang?: string;
show?: boolean; show?: boolean;
title?: string; title?: string;
zIndex?: number; zIndex?: number;
context?: any; context?: WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance;
message?: string; message?: string;
overlay?: boolean; overlay?: boolean;
selector?: string; selector?: string;

View File

@ -1 +1 @@
export declare const basic: void; export declare const basic: string;

View File

@ -1 +1 @@
export declare const button: void; export declare const button: string;

View File

@ -1 +1 @@
export declare const link: void; export declare const link: string;

View File

@ -1 +1 @@
export declare const behavior: void; export declare const behavior: string;

View File

@ -1 +1 @@
export declare const openType: void; export declare const openType: string;

View File

@ -1,4 +1,4 @@
export declare const safeArea: ({ safeAreaInsetBottom, safeAreaInsetTop }?: { export declare const safeArea: ({ safeAreaInsetBottom, safeAreaInsetTop }?: {
safeAreaInsetBottom?: boolean; safeAreaInsetBottom?: boolean;
safeAreaInsetTop?: boolean; safeAreaInsetTop?: boolean;
}) => void; }) => string;

View File

@ -1 +1 @@
export declare const touch: void; export declare const touch: string;

View File

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

View File

@ -10,11 +10,13 @@ export const transition = function (showDefaultValue) {
return Behavior({ return Behavior({
properties: { properties: {
customStyle: String, customStyle: String,
// @ts-ignore
show: { show: {
type: Boolean, type: Boolean,
value: showDefaultValue, value: showDefaultValue,
observer: 'observeShow' observer: 'observeShow'
}, },
// @ts-ignore
duration: { duration: {
type: [Number, Object], type: [Number, Object],
value: 300, value: 300,

4
dist/tabs/index.js vendored
View File

@ -95,6 +95,7 @@ VantComponent({
}); });
}, },
destroyed() { destroyed() {
// @ts-ignore
this.createIntersectionObserver().disconnect(); this.createIntersectionObserver().disconnect();
}, },
methods: { methods: {
@ -271,7 +272,9 @@ VantComponent({
} }
const { offsetTop } = this.data; const { offsetTop } = this.data;
const { windowHeight } = wx.getSystemInfoSync(); const { windowHeight } = wx.getSystemInfoSync();
// @ts-ignore
this.createIntersectionObserver().disconnect(); this.createIntersectionObserver().disconnect();
// @ts-ignore
this.createIntersectionObserver() this.createIntersectionObserver()
.relativeToViewport({ top: -(this.navHeight + offsetTop) }) .relativeToViewport({ top: -(this.navHeight + offsetTop) })
.observe('.van-tabs', (res) => { .observe('.van-tabs', (res) => {
@ -286,6 +289,7 @@ VantComponent({
}); });
this.setPosition(position); this.setPosition(position);
}); });
// @ts-ignore
this.createIntersectionObserver() this.createIntersectionObserver()
.relativeToViewport({ bottom: -(windowHeight - 1 - offsetTop) }) .relativeToViewport({ bottom: -(windowHeight - 1 - offsetTop) })
.observe('.van-tabs', (res) => { .observe('.van-tabs', (res) => {

11
dist/toast/toast.d.ts vendored
View File

@ -1,10 +1,11 @@
/// <reference types="miniprogram-api-typings" />
declare type ToastMessage = string | number; declare type ToastMessage = string | number;
interface ToastOptions { interface ToastOptions {
show?: boolean; show?: boolean;
type?: string; type?: string;
mask?: boolean; mask?: boolean;
zIndex?: number; zIndex?: number;
context?: any; context?: WechatMiniprogram.Component.TrivialInstance | WechatMiniprogram.Page.TrivialInstance;
position?: string; position?: string;
duration?: number; duration?: number;
selector?: string; selector?: string;
@ -13,11 +14,11 @@ interface ToastOptions {
message?: ToastMessage; message?: ToastMessage;
onClose?: () => void; onClose?: () => void;
} }
declare function Toast(toastOptions: ToastOptions | ToastMessage): Weapp.Component; declare function Toast(toastOptions: ToastOptions | ToastMessage): WechatMiniprogram.Component.TrivialInstance;
declare namespace Toast { declare namespace Toast {
var loading: (options: string | number | ToastOptions) => Weapp.Component; var loading: (options: string | number | ToastOptions) => WechatMiniprogram.Component.Instance<Record<string, any>, Record<string, any>, Record<string, any>>;
var success: (options: string | number | ToastOptions) => Weapp.Component; var success: (options: string | number | ToastOptions) => WechatMiniprogram.Component.Instance<Record<string, any>, Record<string, any>, Record<string, any>>;
var fail: (options: string | number | ToastOptions) => Weapp.Component; var fail: (options: string | number | ToastOptions) => WechatMiniprogram.Component.Instance<Record<string, any>, Record<string, any>, Record<string, any>>;
var clear: () => void; var clear: () => void;
var setDefaultOptions: (options: ToastOptions) => void; var setDefaultOptions: (options: ToastOptions) => void;
var resetDefaultOptions: () => void; var resetDefaultOptions: () => void;

2
dist/toast/toast.js vendored
View File

@ -47,7 +47,7 @@ function Toast(toastOptions) {
} }
return toast; return toast;
} }
const createMethod = type => (options) => Toast(Object.assign({ type }, parseOptions(options))); const createMethod = (type) => (options) => Toast(Object.assign({ type }, parseOptions(options)));
Toast.loading = createMethod('loading'); Toast.loading = createMethod('loading');
Toast.success = createMethod('success'); Toast.success = createMethod('success');
Toast.fail = createMethod('fail'); Toast.fail = createMethod('fail');

2
lib/definitions/index.js Normal file
View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

2
lib/definitions/weapp.js Normal file
View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -12,11 +12,13 @@ exports.transition = function (showDefaultValue) {
return Behavior({ return Behavior({
properties: { properties: {
customStyle: String, customStyle: String,
// @ts-ignore
show: { show: {
type: Boolean, type: Boolean,
value: showDefaultValue, value: showDefaultValue,
observer: 'observeShow' observer: 'observeShow'
}, },
// @ts-ignore
duration: { duration: {
type: [Number, Object], type: [Number, Object],
value: 300, value: 300,

View File

@ -98,6 +98,7 @@ component_1.VantComponent({
}); });
}, },
destroyed: function () { destroyed: function () {
// @ts-ignore
this.createIntersectionObserver().disconnect(); this.createIntersectionObserver().disconnect();
}, },
methods: { methods: {
@ -261,7 +262,9 @@ component_1.VantComponent({
} }
var offsetTop = this.data.offsetTop; var offsetTop = this.data.offsetTop;
var windowHeight = wx.getSystemInfoSync().windowHeight; var windowHeight = wx.getSystemInfoSync().windowHeight;
// @ts-ignore
this.createIntersectionObserver().disconnect(); this.createIntersectionObserver().disconnect();
// @ts-ignore
this.createIntersectionObserver() this.createIntersectionObserver()
.relativeToViewport({ top: -(this.navHeight + offsetTop) }) .relativeToViewport({ top: -(this.navHeight + offsetTop) })
.observe('.van-tabs', function (res) { .observe('.van-tabs', function (res) {
@ -276,6 +279,7 @@ component_1.VantComponent({
}); });
_this.setPosition(position); _this.setPosition(position);
}); });
// @ts-ignore
this.createIntersectionObserver() this.createIntersectionObserver()
.relativeToViewport({ bottom: -(windowHeight - 1 - offsetTop) }) .relativeToViewport({ bottom: -(windowHeight - 1 - offsetTop) })
.observe('.van-tabs', function (res) { .observe('.van-tabs', function (res) {

View File

@ -10,7 +10,7 @@
"lint": "eslint ./packages --ext .js,.ts", "lint": "eslint ./packages --ext .js,.ts",
"release": "sh build/release.sh", "release": "sh build/release.sh",
"release:site": "sh build/release-site.sh", "release:site": "sh build/release-site.sh",
"build:lib": "yarn && rm -rf dist && rm -rf lib && NODE_ENV=production node build/compiler.js", "build:lib": "yarn && npx gulp -f build/compiler.js --series buildEs buildLib",
"build:changelog": "vant-doc changelog --tag v0.5.0 ./docs/markdown/changelog.generated.md" "build:changelog": "vant-doc changelog --tag v0.5.0 ./docs/markdown/changelog.generated.md"
}, },
"files": [ "files": [
@ -42,11 +42,10 @@
"gulp-less": "^4.0.1", "gulp-less": "^4.0.1",
"gulp-postcss": "^8.0.0", "gulp-postcss": "^8.0.0",
"gulp-rename": "^1.2.2", "gulp-rename": "^1.2.2",
"gulp-typescript": "^5.0.0",
"html-webpack-plugin": "^3.2.0", "html-webpack-plugin": "^3.2.0",
"less": "^3.9.0", "less": "^3.9.0",
"less-loader": "^5.0.0", "less-loader": "^5.0.0",
"miniprogram-api-typings": "2.4.2-2", "miniprogram-api-typings": "2.7.7-2",
"postcss-loader": "^3.0.0", "postcss-loader": "^3.0.0",
"progress-bar-webpack-plugin": "^1.11.0", "progress-bar-webpack-plugin": "^1.11.0",
"style-loader": "^1.0.0", "style-loader": "^1.0.0",

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { safeArea } from '../mixins/safe-area'; import { safeArea } from '../mixins/safe-area';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
mixins: [safeArea()], mixins: [safeArea()],

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { pickerProps } from '../picker/shared'; import { pickerProps } from '../picker/shared';
import { Weapp } from 'definitions/weapp';
type AreaItem = { type AreaItem = {
name: string; name: string;

View File

@ -4,11 +4,11 @@ VantComponent({
relation: { relation: {
name: 'badge', name: 'badge',
type: 'descendant', type: 'descendant',
linked(target: Weapp.Component) { linked(target) {
this.badges.push(target); this.badges.push(target);
this.setActive(this.data.active); this.setActive(this.data.active);
}, },
unlinked(target: Weapp.Component) { unlinked(target) {
this.badges = this.badges.filter(item => item !== target); this.badges = this.badges.filter(item => item !== target);
this.setActive(this.data.active); this.setActive(this.data.active);
} }

View File

@ -4,7 +4,7 @@ VantComponent({
relation: { relation: {
type: 'ancestor', type: 'ancestor',
name: 'badge-group', name: 'badge-group',
linked(target: Weapp.Component) { linked(target) {
this.parent = target; this.parent = target;
} }
}, },

View File

@ -1,5 +1,6 @@
import { link } from '../mixins/link'; import { link } from '../mixins/link';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
classes: [ classes: [

View File

@ -6,14 +6,14 @@ VantComponent({
relation: { relation: {
name: 'checkbox', name: 'checkbox',
type: 'descendant', type: 'descendant',
linked(target: Weapp.Component) { linked(target) {
this.children = this.children || []; this.children = this.children || [];
this.children.push(target); this.children.push(target);
this.updateChild(target); this.updateChild(target);
}, },
unlinked(target: Weapp.Component) { unlinked(target) {
this.children = this.children.filter( this.children = this.children.filter(
(child: Weapp.Component) => child !== target (child: WechatMiniprogram.Component.TrivialInstance) => child !== target
); );
} }
}, },
@ -32,12 +32,12 @@ VantComponent({
methods: { methods: {
updateChildren() { updateChildren() {
(this.children || []).forEach((child: Weapp.Component) => (this.children || []).forEach((child: WechatMiniprogram.Component.TrivialInstance) =>
this.updateChild(child) this.updateChild(child)
); );
}, },
updateChild(child: Weapp.Component) { updateChild(child: WechatMiniprogram.Component.TrivialInstance) {
const { value, disabled } = this.data; const { value, disabled } = this.data;
child.set({ child.set({
value: value.indexOf(child.data.name) !== -1, value: value.indexOf(child.data.name) !== -1,

View File

@ -1,6 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
function emit(target: Weapp.Component, value: boolean | any[]) { function emit(target: WechatMiniprogram.Component.TrivialInstance, value: boolean | any[]) {
target.$emit('input', value); target.$emit('input', value);
target.$emit('change', value); target.$emit('change', value);
} }
@ -57,7 +57,7 @@ VantComponent({
} }
}, },
setParentValue(parent: Weapp.Component, value: boolean) { setParentValue(parent: WechatMiniprogram.Component.TrivialInstance, value: boolean) {
const parentValue = parent.data.value.slice(); const parentValue = parent.data.value.slice();
const { name } = this.data; const { name } = this.data;
const { max } = parent.data; const { max } = parent.data;

View File

@ -8,7 +8,7 @@ VantComponent({
relation: { relation: {
name: 'collapse', name: 'collapse',
type: 'ancestor', type: 'ancestor',
linked(parent: Weapp.Component) { linked(parent) {
this.parent = parent; this.parent = parent;
} }
}, },
@ -81,7 +81,7 @@ VantComponent({
updateStyle(expanded: boolean) { updateStyle(expanded: boolean) {
return this.getRect('.van-collapse-item__content') return this.getRect('.van-collapse-item__content')
.then((rect: wx.BoundingClientRectCallbackResult) => rect.height) .then((rect: WechatMiniprogram.BoundingClientRectCallbackResult) => rect.height)
.then((height: number) => { .then((height: number) => {
if (expanded) { if (expanded) {
return this.set({ return this.set({

View File

@ -4,12 +4,12 @@ VantComponent({
relation: { relation: {
name: 'collapse-item', name: 'collapse-item',
type: 'descendant', type: 'descendant',
linked(child: Weapp.Component) { linked(child) {
this.children.push(child); this.children.push(child);
}, },
unlinked(child: Weapp.Component) { unlinked(child) {
this.children = this.children.filter( this.children = this.children.filter(
(item: Weapp.Component) => item !== child (item: WechatMiniprogram.Component.TrivialInstance) => item !== child
); );
} }
}, },
@ -35,7 +35,7 @@ VantComponent({
methods: { methods: {
updateExpanded() { updateExpanded() {
this.children.forEach((child: Weapp.Component) => { this.children.forEach((child: WechatMiniprogram.Component.TrivialInstance) => {
child.updateExpanded(); child.updateExpanded();
}); });
}, },

View File

@ -1,5 +1,7 @@
import { basic } from '../mixins/basic'; import { basic } from '../mixins/basic';
import { observe } from '../mixins/observer/index'; import { observe } from '../mixins/observer/index';
import { VantComponentOptions, CombinedComponentInstance } from 'definitions/index';
import { Weapp } from 'packages/definitions/weapp';
function mapKeys(source: object, target: object, map: object) { function mapKeys(source: object, target: object, map: object) {
Object.keys(map).forEach(key => { Object.keys(map).forEach(key => {
@ -9,14 +11,13 @@ function mapKeys(source: object, target: object, map: object) {
}); });
} }
function VantComponent<Data, Props, Watch, Methods, Computed>( function VantComponent<Data, Props, Methods, Computed>(
vantOptions: VantComponentOptions< vantOptions: VantComponentOptions<
Data, Data,
Props, Props,
Watch,
Methods, Methods,
Computed, Computed,
CombinedComponentInstance<Data, Props, Watch, Methods, Computed> CombinedComponentInstance<Data, Props, Methods, Computed>
> = {} > = {}
): void { ): void {
const options: any = {}; const options: any = {};

View File

@ -0,0 +1,39 @@
import { Weapp } from './weapp';
type RecordToAny<T> = { [K in keyof T]: any };
type RecordToReturn<T> = {
[P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]> : T[P]
};
export type CombinedComponentInstance<
Data,
Props,
Methods,
Computed
> = Methods &
WechatMiniprogram.Component.TrivialInstance &
Weapp.FormField &
{
data: Data & RecordToReturn<Computed> & RecordToAny<Props>;
};
export interface VantComponentOptions<Data, Props, Methods, Computed, Instance> {
data?: Data;
field?: boolean;
classes?: string[];
mixins?: string[];
props?: Props & Weapp.PropertyOption;
watch?: Weapp.WatchOption<Instance>;
computed?: Computed & Weapp.ComputedOption<Instance>;
relation?: Weapp.RelationOption<Instance> & { name: string };
relations?: {
[componentName: string]: Weapp.RelationOption<Instance>;
};
methods?: Methods & Weapp.MethodOption<Instance>;
// lifetimes
beforeCreate?: (this: Instance) => void;
created?: (this: Instance) => void;
mounted?: (this: Instance) => void;
destroyed?: (this: Instance) => void;
}

View File

@ -0,0 +1,133 @@
export namespace Weapp {
export interface FormField {
data: {
name: string
value: any
}
}
interface Target {
id: string
tagName: string
dataset: {
[key: string]: any
}
}
export interface Event {
/**
*
*/
type: string
/**
*
*/
timeStamp: number
/**
*
*/
target: Target
/**
*
*/
currentTarget: Target
/**
*
*/
detail: any
}
interface Touch {
/**
*
*/
identifier: number
/**
* X轴Y轴
*/
pageX: number
/**
* X轴Y轴
*/
pageY: number
/**
* X轴Y轴
*/
clientX: number
/**
* X轴Y轴
*/
clientY: number
}
export interface TouchEvent extends Event {
touches: Array<Touch>
changedTouches: Array<Touch>
}
/**
* relation定义miniprogram-api-typings缺少this定义
*/
export interface RelationOption<Instance> {
/** 目标组件的相对关系 */
type: 'parent' | 'child' | 'ancestor' | 'descendant';
/** 关系生命周期函数当关系被建立在页面节点树中时触发触发时机在组件attached生命周期之后 */
linked?(this: Instance, target: WechatMiniprogram.Component.TrivialInstance): void;
/** 关系生命周期函数当关系在页面节点树中发生改变时触发触发时机在组件moved生命周期之后 */
linkChanged?(this: Instance, target: WechatMiniprogram.Component.TrivialInstance): void;
/** 关系生命周期函数当关系脱离页面节点树时触发触发时机在组件detached生命周期之后 */
unlinked?(this: Instance, target: WechatMiniprogram.Component.TrivialInstance): void;
/** 如果这一项被设置则它表示关联的目标节点所应具有的behavior所有拥有这一behavior的组件节点都会被关联 */
target?: string;
}
/**
* obverser定义miniprogram-api-typings缺少this定义
*/
type Observer<Instance, T> = (
this: Instance,
newVal: T,
oldVal: T,
changedPath: Array<string | number>,
) => void;
/**
* watch定义
*/
export interface WatchOption<Instance> {
[name: string]: string | Observer<Instance, any>
}
/**
* methods定义miniprogram-api-typings缺少this定义
*/
export interface MethodOption<Instance> {
[name: string]: (this: Instance, ...args: any[]) => any
}
export interface ComputedOption<Instance> {
[name: string]: (this: Instance) => any
}
type PropertyType =
| StringConstructor
| NumberConstructor
| BooleanConstructor
| ArrayConstructor
| ObjectConstructor
| FunctionConstructor
| null;
export interface PropertyOption {
[name: string]: PropertyType | PropertyType[] | {
/** 属性类型 */
type: PropertyType | PropertyType[];
/** 属性初始值 */
value?: any;
/** 属性值被更改时的响应函数 */
observer?: string | Observer<WechatMiniprogram.Component.TrivialInstance, any>;
/** 属性的类型(可以指定多个) */
optionalTypes?: PropertyType[];
}
}
}

View File

@ -6,7 +6,7 @@ type DialogOptions = {
show?: boolean; show?: boolean;
title?: string; title?: string;
zIndex?: number; zIndex?: number;
context?: any; context?: WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance;
message?: string; message?: string;
overlay?: boolean; overlay?: boolean;
selector?: string; selector?: string;

View File

@ -1,4 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
field: true, field: true,

View File

@ -2,6 +2,7 @@ import { VantComponent } from '../common/component';
import { link } from '../mixins/link'; import { link } from '../mixins/link';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
mixins: [link, button, openType], mixins: [link, button, openType],

View File

@ -2,6 +2,7 @@ import { VantComponent } from '../common/component';
import { link } from '../mixins/link'; import { link } from '../mixins/link';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
classes: ['icon-class', 'text-class'], classes: ['icon-class', 'text-class'],

View File

@ -1,4 +1,4 @@
function setAsync(context: Weapp.Component, data: object) { function setAsync(context: WechatMiniprogram.Component.TrivialInstance, data: object) {
return new Promise(resolve => { return new Promise(resolve => {
context.setData(data, resolve); context.setData(data, resolve);
}); });

View File

@ -1,3 +1,5 @@
import { Weapp } from "definitions/weapp";
export const openType = Behavior({ export const openType = Behavior({
properties: { properties: {
openType: String openType: String

View File

@ -1,3 +1,5 @@
import { Weapp } from "definitions/weapp";
export const touch = Behavior({ export const touch = Behavior({
methods: { methods: {
touchStart(event: Weapp.TouchEvent) { touchStart(event: Weapp.TouchEvent) {

View File

@ -13,11 +13,13 @@ export const transition = function (showDefaultValue: boolean) {
return Behavior({ return Behavior({
properties: { properties: {
customStyle: String, customStyle: String,
// @ts-ignore
show: { show: {
type: Boolean, type: Boolean,
value: showDefaultValue, value: showDefaultValue,
observer: 'observeShow' observer: 'observeShow'
}, },
// @ts-ignore
duration: { duration: {
type: [Number, Object], type: [Number, Object],
value: 300, value: 300,

View File

@ -1,4 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
const FONT_COLOR = '#ed6a0c'; const FONT_COLOR = '#ed6a0c';
const BG_COLOR = '#fffbe8'; const BG_COLOR = '#fffbe8';
@ -74,7 +75,7 @@ VantComponent({
Promise.all([ Promise.all([
this.getRect('.van-notice-bar__content'), this.getRect('.van-notice-bar__content'),
this.getRect('.van-notice-bar__wrap') this.getRect('.van-notice-bar__wrap')
]).then((rects: wx.BoundingClientRectCallbackResult[]) => { ]).then((rects: WechatMiniprogram.BoundingClientRectCallbackResult[]) => {
const [contentRect, wrapRect] = rects; const [contentRect, wrapRect] = rects;
if ( if (
contentRect == null || contentRect == null ||

View File

@ -20,7 +20,7 @@ function parseOptions(text: NotifyOptions | string): NotifyOptions {
return isObj(text) ? (text as NotifyOptions) : ({ text } as NotifyOptions); return isObj(text) ? (text as NotifyOptions) : ({ text } as NotifyOptions);
} }
function getContext(): Page.PageInstance { function getContext() {
const pages = getCurrentPages(); const pages = getCurrentPages();
return pages[pages.length - 1]; return pages[pages.length - 1];
} }

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isObj, range } from '../common/utils'; import { isObj, range } from '../common/utils';
import { Weapp } from 'definitions/weapp';
const DEFAULT_DURATION = 200; const DEFAULT_DURATION = 200;

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { pickerProps } from './shared'; import { pickerProps } from './shared';
import { Weapp } from 'definitions/weapp';
interface Column { interface Column {
values: object[]; values: object[];
@ -147,7 +148,7 @@ VantComponent({
// get values of all columns // get values of all columns
getValues() { getValues() {
return this.children.map((child: Weapp.Component) => child.getValue()); return this.children.map((child: WechatMiniprogram.Component.TrivialInstance) => child.getValue());
}, },
// set values of all columns // set values of all columns
@ -161,7 +162,7 @@ VantComponent({
// get indexes of all columns // get indexes of all columns
getIndexes() { getIndexes() {
return this.children.map( return this.children.map(
(child: Weapp.Component) => child.data.currentIndex (child: WechatMiniprogram.Component.TrivialInstance) => child.data.currentIndex
); );
}, },

View File

@ -6,14 +6,14 @@ VantComponent({
relation: { relation: {
name: 'radio', name: 'radio',
type: 'descendant', type: 'descendant',
linked(target: Weapp.Component) { linked(target) {
this.children = this.children || []; this.children = this.children || [];
this.children.push(target); this.children.push(target);
this.updateChild(target); this.updateChild(target);
}, },
unlinked(target: Weapp.Component) { unlinked(target) {
this.children = this.children.filter( this.children = this.children.filter(
(child: Weapp.Component) => child !== target (child: WechatMiniprogram.Component.TrivialInstance) => child !== target
); );
} }
}, },
@ -31,12 +31,12 @@ VantComponent({
methods: { methods: {
updateChildren() { updateChildren() {
(this.children || []).forEach((child: Weapp.Component) => (this.children || []).forEach((child: WechatMiniprogram.Component.TrivialInstance) =>
this.updateChild(child) this.updateChild(child)
); );
}, },
updateChild(child: Weapp.Component) { updateChild(child: WechatMiniprogram.Component.TrivialInstance) {
const { value, disabled } = this.data; const { value, disabled } = this.data;
child.set({ child.set({
value, value,

View File

@ -1,4 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
field: true, field: true,
@ -6,7 +7,7 @@ VantComponent({
relation: { relation: {
name: 'radio-group', name: 'radio-group',
type: 'ancestor', type: 'ancestor',
linked(target: Weapp.Component) { linked(target) {
this.parent = target; this.parent = target;
}, },
unlinked() { unlinked() {

View File

@ -1,4 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
field: true, field: true,
@ -67,7 +68,7 @@ VantComponent({
const { clientX, clientY } = event.touches[0]; const { clientX, clientY } = event.touches[0];
this.getRect('.van-rate__icon', true).then( this.getRect('.van-rate__icon', true).then(
(list: wx.BoundingClientRectCallbackResult[]) => { (list: WechatMiniprogram.BoundingClientRectCallbackResult[]) => {
const target = list const target = list
.sort(item => item.right - item.left) .sort(item => item.right - item.left)
.find( .find(

View File

@ -4,7 +4,7 @@ VantComponent({
relation: { relation: {
name: 'col', name: 'col',
type: 'descendant', type: 'descendant',
linked(target: Weapp.Component) { linked(target) {
if (this.data.gutter) { if (this.data.gutter) {
target.setGutter(this.data.gutter); target.setGutter(this.data.gutter);
} }

View File

@ -1,4 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
field: true, field: true,

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { touch } from '../mixins/touch'; import { touch } from '../mixins/touch';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
mixins: [touch], mixins: [touch],
@ -53,7 +54,7 @@ VantComponent({
if (this.data.disabled) return; if (this.data.disabled) return;
this.touchMove(event); this.touchMove(event);
this.getRect('.van-slider').then((rect: wx.BoundingClientRectCallbackResult) => { this.getRect('.van-slider').then((rect: WechatMiniprogram.BoundingClientRectCallbackResult) => {
const diff = this.deltaX / rect.width * 100; const diff = this.deltaX / rect.width * 100;
this.newValue = this.startValue + diff; this.newValue = this.startValue + diff;
this.updateValue(this.newValue, false, true); this.updateValue(this.newValue, false, true);
@ -68,7 +69,7 @@ VantComponent({
onClick(event: Weapp.TouchEvent) { onClick(event: Weapp.TouchEvent) {
if (this.data.disabled) return; if (this.data.disabled) return;
this.getRect('.van-slider').then((rect: wx.BoundingClientRectCallbackResult) => { this.getRect('.van-slider').then((rect: WechatMiniprogram.BoundingClientRectCallbackResult) => {
const value = (event.detail.x - rect.left) / rect.width * 100; const value = (event.detail.x - rect.left) / rect.width * 100;
this.updateValue(value, true); this.updateValue(value, true);
}); });

View File

@ -1,4 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
field: true, field: true,

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { safeArea } from '../mixins/safe-area'; import { safeArea } from '../mixins/safe-area';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
mixins: [safeArea()], mixins: [safeArea()],

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { touch } from '../mixins/touch'; import { touch } from '../mixins/touch';
import { Weapp } from 'definitions/weapp';
const THRESHOLD = 0.3; const THRESHOLD = 0.3;

View File

@ -1,4 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
VantComponent({ VantComponent({
field: true, field: true,

View File

@ -7,14 +7,14 @@ VantComponent({
relation: { relation: {
name: 'tabbar-item', name: 'tabbar-item',
type: 'descendant', type: 'descendant',
linked(target: Weapp.Component) { linked(target) {
this.children.push(target); this.children.push(target);
target.parent = this; target.parent = this;
target.updateFromParent(); target.updateFromParent();
}, },
unlinked(target: Weapp.Component) { unlinked(target) {
this.children = this.children.filter( this.children = this.children.filter(
(item: Weapp.Component) => item !== target (item: WechatMiniprogram.Component.TrivialInstance) => item !== target
); );
this.updateChildren(); this.updateChildren();
} }
@ -59,11 +59,11 @@ VantComponent({
} }
return Promise.all( return Promise.all(
children.map((child: Weapp.Component) => child.updateFromParent()) children.map((child: WechatMiniprogram.Component.TrivialInstance) => child.updateFromParent())
); );
}, },
onChange(child: Weapp.Component) { onChange(child: WechatMiniprogram.Component.TrivialInstance) {
const index = this.children.indexOf(child); const index = this.children.indexOf(child);
const active = child.data.name || index; const active = child.data.name || index;

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { touch } from '../mixins/touch'; import { touch } from '../mixins/touch';
import { Weapp } from 'definitions/weapp';
type TabItemData = { type TabItemData = {
width?: number width?: number
@ -18,11 +19,11 @@ VantComponent({
relation: { relation: {
name: 'tab', name: 'tab',
type: 'descendant', type: 'descendant',
linked(child: Weapp.Component) { linked(child) {
this.child.push(child); this.child.push(child);
this.updateTabs(this.data.tabs.concat(child.data)); this.updateTabs(this.data.tabs.concat(child.data));
}, },
unlinked(child: Weapp.Component) { unlinked(child) {
const index = this.child.indexOf(child); const index = this.child.indexOf(child);
const { tabs } = this.data; const { tabs } = this.data;
tabs.splice(index, 1); tabs.splice(index, 1);
@ -108,7 +109,7 @@ VantComponent({
this.scrollIntoView(); this.scrollIntoView();
this.getRect('.van-tabs__wrap').then( this.getRect('.van-tabs__wrap').then(
(rect: wx.BoundingClientRectCallbackResult) => { (rect: WechatMiniprogram.BoundingClientRectCallbackResult) => {
this.navHeight = rect.height; this.navHeight = rect.height;
this.observerContentScroll(); this.observerContentScroll();
} }
@ -116,6 +117,7 @@ VantComponent({
}, },
destroyed() { destroyed() {
// @ts-ignore
this.createIntersectionObserver().disconnect(); this.createIntersectionObserver().disconnect();
}, },
@ -162,7 +164,7 @@ VantComponent({
const { color, active, duration, lineWidth, lineHeight } = this.data; const { color, active, duration, lineWidth, lineHeight } = this.data;
this.getRect('.van-tab', true).then( this.getRect('.van-tab', true).then(
(rects: wx.BoundingClientRectCallbackResult[]) => { (rects: WechatMiniprogram.BoundingClientRectCallbackResult[]) => {
const rect = rects[active]; const rect = rects[active];
const width = lineWidth !== -1 ? lineWidth : rect.width / 2; const width = lineWidth !== -1 ? lineWidth : rect.width / 2;
const height = lineHeight !== -1 ? `height: ${lineHeight}px;` : ''; const height = lineHeight !== -1 ? `height: ${lineHeight}px;` : '';
@ -197,7 +199,7 @@ VantComponent({
if (!animated) return ''; if (!animated) return '';
this.getRect('.van-tabs__content').then( this.getRect('.van-tabs__content').then(
(rect: wx.BoundingClientRectCallbackResult) => { (rect: WechatMiniprogram.BoundingClientRectCallbackResult) => {
const { width } = rect; const { width } = rect;
this.set({ this.set({
@ -212,7 +214,7 @@ VantComponent({
const props = { width, animated }; const props = { width, animated };
this.child.forEach((item: Weapp.Component) => { this.child.forEach((item: WechatMiniprogram.Component.TrivialInstance) => {
item.set(props); item.set(props);
}); });
} }
@ -220,7 +222,7 @@ VantComponent({
}, },
setActiveTab() { setActiveTab() {
this.child.forEach((item: Weapp.Component, index: number) => { this.child.forEach((item: WechatMiniprogram.Component.TrivialInstance, index: number) => {
const data: TabItemData = { const data: TabItemData = {
active: index === this.data.active active: index === this.data.active
}; };
@ -254,8 +256,8 @@ VantComponent({
this.getRect('.van-tabs__nav') this.getRect('.van-tabs__nav')
]).then( ]).then(
([tabRects, navRect]: [ ([tabRects, navRect]: [
wx.BoundingClientRectCallbackResult[], WechatMiniprogram.BoundingClientRectCallbackResult[],
wx.BoundingClientRectCallbackResult WechatMiniprogram.BoundingClientRectCallbackResult
]) => { ]) => {
const tabRect = tabRects[active]; const tabRect = tabRects[active];
const offsetLeft = tabRects const offsetLeft = tabRects
@ -337,11 +339,13 @@ VantComponent({
const { offsetTop } = this.data; const { offsetTop } = this.data;
const { windowHeight } = wx.getSystemInfoSync(); const { windowHeight } = wx.getSystemInfoSync();
// @ts-ignore
this.createIntersectionObserver().disconnect(); this.createIntersectionObserver().disconnect();
// @ts-ignore
this.createIntersectionObserver() this.createIntersectionObserver()
.relativeToViewport({ top: -(this.navHeight + offsetTop) }) .relativeToViewport({ top: -(this.navHeight + offsetTop) })
.observe('.van-tabs', (res: wx.ObserveCallbackResult) => { .observe('.van-tabs', (res: WechatMiniprogram.ObserveCallbackResult) => {
const { top } = res.boundingClientRect; const { top } = res.boundingClientRect;
if (top > offsetTop) { if (top > offsetTop) {
@ -359,9 +363,10 @@ VantComponent({
this.setPosition(position); this.setPosition(position);
}); });
// @ts-ignore
this.createIntersectionObserver() this.createIntersectionObserver()
.relativeToViewport({ bottom: -(windowHeight - 1 - offsetTop) }) .relativeToViewport({ bottom: -(windowHeight - 1 - offsetTop) })
.observe('.van-tabs', (res: wx.ObserveCallbackResult) => { .observe('.van-tabs', (res: WechatMiniprogram.ObserveCallbackResult) => {
const { top, bottom } = res.boundingClientRect; const { top, bottom } = res.boundingClientRect;
if (bottom < this.navHeight) { if (bottom < this.navHeight) {

View File

@ -7,7 +7,7 @@ interface ToastOptions {
type?: string; type?: string;
mask?: boolean; mask?: boolean;
zIndex?: number; zIndex?: number;
context?: any; context?: WechatMiniprogram.Component.TrivialInstance | WechatMiniprogram.Page.TrivialInstance;
position?: string; position?: string;
duration?: number; duration?: number;
selector?: string; selector?: string;
@ -42,7 +42,7 @@ function getContext() {
return pages[pages.length - 1]; return pages[pages.length - 1];
} }
function Toast(toastOptions: ToastOptions | ToastMessage): Weapp.Component { function Toast(toastOptions: ToastOptions | ToastMessage): WechatMiniprogram.Component.TrivialInstance {
const options = { const options = {
...currentOptions, ...currentOptions,
...parseOptions(toastOptions) ...parseOptions(toastOptions)
@ -81,7 +81,7 @@ function Toast(toastOptions: ToastOptions | ToastMessage): Weapp.Component {
return toast; return toast;
} }
const createMethod = type => (options: ToastOptions | ToastMessage) => const createMethod = (type: string) => (options: ToastOptions | ToastMessage) =>
Toast({ Toast({
type, type,
...parseOptions(options) ...parseOptions(options)

View File

@ -1,4 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { Weapp } from 'definitions/weapp';
const ITEM_HEIGHT = 44; const ITEM_HEIGHT = 44;

6
tsconfig.example.json Normal file
View File

@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "example/dist"
}
}

View File

@ -3,11 +3,14 @@
"module": "es6", "module": "es6",
"esModuleInterop": true, "esModuleInterop": true,
"target": "es6", "target": "es6",
"noImplicitAny": false,
"declaration": true, "declaration": true,
"noImplicitAny": false,
"outDir": "dist", "outDir": "dist",
"baseUrl": ".", "baseUrl": ".",
"types": ["miniprogram-api-typings"] "types": ["miniprogram-api-typings"],
"paths": {
"definitions/*": ["./packages/definitions/*"]
}
}, },
"include": ["packages/**/*", "types/**/*"] "include": ["packages/**/*"]
} }

10
tsconfig.lib.json Normal file
View File

@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["es2015", "es2017", "dom"],
"declaration": false,
"outDir": "lib"
}
}

65
types/index.d.ts vendored
View File

@ -1,65 +0,0 @@
/// <reference path="./weapp.d.ts" />
interface ComponentInstance {
triggerEvent: never;
$emit(name: string, detail?: any): void;
}
type Mixins = any[];
type ExternalClasses = string[];
type LooseObject = {
[key: string]: any;
};
type Relation<Instance> = {
name?: string;
type: string;
linked?: (this: Instance, target?: Weapp.Component) => void;
unlinked?: (this: Instance, target?: Weapp.Component) => void;
};
type Relations<Instance> = {
[key: string]: Relation<Instance>;
};
type RecordToAny<T> = { [K in keyof T]: any };
type RecordToReturn<T> = {
[P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]> : T[P]
};
type CombinedComponentInstance<
Data,
Props,
Watch,
Methods,
Computed
> = Methods &
LooseObject &
Weapp.Component &
Weapp.FormField &
ComponentInstance & {
data: Data & LooseObject & RecordToAny<Props> & RecordToReturn<Computed>;
};
type VantComponentOptions<
Data,
Props,
Watch,
Methods,
Computed,
Instance
> = {
data?: Data;
field?: boolean;
mixins?: Mixins;
props?: Props & ThisType<Instance>;
watch?: Watch & ThisType<Instance>;
computed?: Computed & ThisType<Instance>;
relation?: Relation<Instance>;
relations?: Relations<Instance>;
classes?: ExternalClasses;
methods?: Methods & ThisType<Instance>;
// lifetimes
beforeCreate?: (this: Instance) => void;
created?: (this: Instance) => void;
mounted?: (this: Instance) => void;
destroyed?: (this: Instance) => void;
};

80
types/weapp.d.ts vendored
View File

@ -1,80 +0,0 @@
type BehaviorOptions = {
[key: string]: any & ThisType<any>
};
declare function Behavior(options: BehaviorOptions): void
declare function Component(options: any): void
declare namespace Weapp {
interface Component {
[key: string]: any
getRelationNodes(selector: string): any[]
setData(data: any, callback?: Function): void
}
interface FormField {
data: {
name: string
value: any
}
}
interface Target {
id: string
tagName: string
dataset: {
[key: string]: any
}
}
interface Event {
/**
*
*/
type: string
/**
*
*/
timeStamp: number
/**
*
*/
target: Target
/**
*
*/
currentTarget: Target
/**
*
*/
detail: any
}
interface Touch {
/**
*
*/
identifier: number
/**
* X轴Y轴
*/
pageX: number
/**
* X轴Y轴
*/
pageY: number
/**
* X轴Y轴
*/
clientX: number
/**
* X轴Y轴
*/
clientY: number
}
interface TouchEvent extends Event {
touches: Array<Touch>
changedTouches: Array<Touch>
}
}

3513
yarn.lock

File diff suppressed because it is too large Load Diff