[Build] optimize build process (#421)

This commit is contained in:
neverland 2018-08-13 17:39:25 +08:00 committed by GitHub
parent 5497890a5c
commit 45576807b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 397 additions and 540 deletions

View File

@ -1,7 +0,0 @@
const path = require('path');
const extracter = require('./extracter');
extracter({
src: path.resolve(__dirname, '../packages'),
dist: path.resolve(__dirname, '../dist')
});

View File

@ -1,42 +0,0 @@
const path = require('path');
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const cssmin = require('gulp-clean-css');
const rename = require('gulp-rename');
const gutil = require('gulp-util');
const removeLogging = require('gulp-remove-logging');
const babel = require('gulp-babel');
const options = gutil.env;
const isProduction = process.env.NODE_ENV === 'production';
gulp.task('compile-css', () => {
return gulp
.src(['../packages/**/*.pcss', '!../packages/**/_*.pcss'])
.pipe(postcss())
.pipe(cssmin())
.pipe(
rename(path => {
path.extname = '.wxss';
})
)
.pipe(gulp.dest(options.dist));
});
gulp.task('compile-js', () => {
return gulp
.src(['../packages/**/*.js'])
.pipe(
removeLogging({
methods: isProduction ? ['log', 'info'] : []
})
)
.pipe(
babel({
extends: path.join(__dirname, '../.babelrc')
})
)
.pipe(gulp.dest(options.dist));
});
gulp.task('build', ['compile-css', 'compile-js']);

38
build/compiler.js Normal file
View File

@ -0,0 +1,38 @@
const gulp = require('gulp');
const path = require('path');
const postcss = require('gulp-postcss');
const cssmin = require('gulp-clean-css');
const rename = require('gulp-rename');
const isProduction = process.env.NODE_ENV === 'production';
const src = path.join(__dirname, '../packages');
const dist = path.join(__dirname, isProduction ? '../dist' : '../example/dist');
const ext = ['js', 'pcss', 'json', 'wxml'];
function copy(ext) {
return gulp.src([src + '/**/*.' + ext]).pipe(gulp.dest(dist));
}
gulp.task('compile-pcss', () => {
return gulp
.src([src + '/**/*.pcss'])
.pipe(postcss())
.pipe(cssmin())
.pipe(
rename(path => {
path.extname = '.wxss';
})
)
.pipe(gulp.dest(dist));
});
gulp.task('compile-js', () => copy('js'));
gulp.task('compile-json', () => copy('json'));
gulp.task('compile-wxml', () => copy('wxml'));
gulp.task('build', ext.map(ext => 'compile-' + ext));
gulp.start('build');
if (!isProduction) {
ext.forEach(ext => {
gulp.watch(src + '/**/*.' + ext, ['compile-' + ext]);
});
}

View File

@ -1,17 +1,23 @@
require('./compiler');
const fs = require('fs-extra');
const glob = require('fast-glob');
const path = require('path');
const glob = require('fast-glob');
const serve = require('webpack-serve');
const config = require('./webpack.doc.dev');
const tips = '// This file is auto gererated by build/build-entry.js';
const root = path.join(__dirname, '../');
const join = dir => path.join(root, dir);
const serve = require('webpack-serve');
const config = require('./webpack.dev');
const extracter = require('./extracter');
// generate webpack entry file for markdown docs
function buildDocsEntry() {
function buildEntry() {
const output = join('docs/src/docs-entry.js');
const getName = fullPath => fullPath.replace(/(\/README)|(\.md)/g, '').split('/').pop();
const getName = fullPath =>
fullPath
.replace(/(\/README)|(\.md)/g, '')
.split('/')
.pop();
const docs = glob
.sync([
join('docs/**/*.md'),
@ -20,7 +26,10 @@ function buildDocsEntry() {
])
.map(fullPath => {
const name = getName(fullPath);
return `'${name}': () => import('${path.relative(join('docs/src'), fullPath)}')`;
return `'${name}': () => import('${path.relative(
join('docs/src'),
fullPath
)}')`;
});
const content = `${tips}
@ -28,15 +37,9 @@ export default {
${docs.join(',\n ')}
};
`;
fs.writeFileSync(output, content);
}
buildDocsEntry();
buildEntry();
serve({}, { config });
extracter({
src: path.resolve(__dirname, '../packages'),
dist: path.resolve(__dirname, '../example/dist'),
watch: true
});

View File

@ -1,31 +0,0 @@
const path = require('path');
const fs = require('fs-extra');
const nodeWatch = require('node-watch');
const debounce = require('lodash/debounce');
const shelljs = require('shelljs');
module.exports = function(config = {}) {
// 清空 dist 目录
fs.emptyDirSync(config.dist);
extracter(config);
if (config.watch) {
nodeWatch(config.src, { recursive: true }, () => debouncedFunc(config));
}
};
const debouncedFunc = debounce(config => extracter(config), 100);
function extracter(config = {}) {
// 复制 src
fs.copySync(config.src, config.dist, {
filter(src = '') {
const extname = path.extname(src);
return ['.js', '.pcss', '.md'].indexOf(extname) < 0;
}
});
// 编译 js wxss 文件
shelljs.exec(`gulp build --gulpfile build/build.js --dist ${config.dist} --color`);
}

View File

@ -10,8 +10,6 @@ read -p "Releasing $VERSION - are you sure? (y/n)" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Releasing $VERSION ..."
# build
npm run build:lib
@ -22,17 +20,13 @@ then
npm version $VERSION --message "[release] $VERSION"
# publish
echo "publishing git..."
git push origin master
git push origin refs/tags/v$VERSION
echo "publishing npm..."
npm publish
# sync dev
echo "sync dev..."
git checkout dev
git rebase master
git push origin dev
fi

View File

@ -29,10 +29,7 @@ module.exports = {
}
},
resolve: {
extensions: ['.js', '.vue', '.css'],
alias: {
packages: path.join(__dirname, '../packages')
}
extensions: ['.js', '.vue', '.css']
},
module: {
rules: [
@ -68,10 +65,6 @@ module.exports = {
'vue-loader',
'fast-vue-md-loader'
]
},
{
test: /\.(ttf|svg)$/,
loader: 'url-loader'
}
]
},

View File

@ -1,5 +1,3 @@
'use strict';
Component({
properties: {
show: Boolean,
@ -20,19 +18,20 @@ Component({
},
methods: {
onSelect: function onSelect(event) {
var index = event.currentTarget.dataset.index;
var item = this.data.actions[index];
onSelect(event) {
const { index } = event.currentTarget.dataset;
const item = this.data.actions[index];
if (item && !item.disabled && !item.loading) {
this.triggerEvent('select', item);
}
},
onCancel: function onCancel() {
onCancel() {
this.triggerEvent('cancel');
},
onClose: function onClose() {
onClose() {
this.triggerEvent('close');
}
}
});
});

View File

@ -1,32 +1,29 @@
'use strict';
var _relations;
var BADGE_PATH = '../badge/index';
const BADGE_PATH = '../badge/index';
Component({
externalClasses: ['custom-class'],
relations: (_relations = {}, _relations[BADGE_PATH] = {
type: 'descendant',
relations: {
[BADGE_PATH]: {
type: 'descendant',
linked: function linked(target) {
this.data.badges.push(target);
this.setActive();
},
unlinked: function unlinked(target) {
this.data.badges = this.data.badges.filter(function (item) {
return item !== target;
});
this.setActive();
linked(target) {
this.data.badges.push(target);
this.setActive();
},
unlinked(target) {
this.data.badges = this.data.badges.filter(item => item !== target);
this.setActive();
}
}
}, _relations),
},
properties: {
active: {
type: Number,
value: 0,
observer: function observer() {
observer() {
this.setActive();
}
}
@ -36,15 +33,13 @@ Component({
badges: []
},
attached: function attached() {
attached() {
this.currentActive = -1;
},
methods: {
setActive: function setActive(badge) {
var active = this.data.active;
setActive(badge) {
let { active } = this.data;
if (badge) {
active = this.data.badges.indexOf(badge);
}
@ -58,9 +53,9 @@ Component({
}
this.currentActive = active;
this.data.badges.forEach(function (badge, index) {
this.data.badges.forEach((badge, index) => {
badge.setActive(index === active);
});
}
}
});
});

25
dist/badge/index.js vendored
View File

@ -1,15 +1,13 @@
'use strict';
var _relations;
var BADGE_GROUP_PATH = '../badge-group/index';
const BADGE_GROUP_PATH = '../badge-group/index';
Component({
externalClasses: ['custom-class'],
relations: (_relations = {}, _relations[BADGE_GROUP_PATH] = {
type: 'ancestor'
}, _relations),
relations: {
[BADGE_GROUP_PATH]: {
type: 'ancestor'
}
},
properties: {
info: Number,
@ -17,14 +15,15 @@ Component({
},
methods: {
onClick: function onClick() {
var group = this.getRelationNodes(BADGE_GROUP_PATH)[0];
onClick() {
const group = this.getRelationNodes(BADGE_GROUP_PATH)[0];
if (group) {
group.setActive(this);
}
},
setActive: function setActive(active) {
this.setData({ active: active });
setActive(active) {
this.setData({ active });
}
}
});
});

View File

@ -1,5 +1,3 @@
'use strict';
module.exports = Behavior({
properties: {
loading: Boolean,
@ -36,30 +34,24 @@ module.exports = Behavior({
},
methods: {
bindgetuserinfo: function bindgetuserinfo() {
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
bindgetuserinfo(event = {}) {
this.triggerEvent('getuserinfo', event.detail || {});
},
bindcontact: function bindcontact() {
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
bindcontact(event = {}) {
this.triggerEvent('contact', event.detail || {});
},
bindgetphonenumber: function bindgetphonenumber() {
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
bindgetphonenumber(event = {}) {
this.triggerEvent('getphonenumber', event.detail || {});
},
bindopensetting: function bindopensetting() {
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
bindopensetting(event = {}) {
this.triggerEvent('opensetting', event.detail || {});
},
binderror: function binderror() {
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
binderror(event = {}) {
this.triggerEvent('error', event.detail || {});
}
}
});
});

39
dist/button/index.js vendored
View File

@ -1,9 +1,7 @@
'use strict';
const nativeBehaviors = require('./behaviors');
const classnames = require('../common/classnames');
var nativeBehaviors = require('./behaviors');
var classnames = require('../common/classnames');
var observer = function observer() {
const observer = function() {
this.setClasses();
};
@ -16,53 +14,46 @@ Component({
type: {
type: String,
value: 'default',
observer: observer
observer
},
size: {
type: String,
value: 'normal',
observer: observer
observer
},
plain: {
type: Boolean,
observer: observer
observer
},
disabled: {
type: Boolean,
observer: observer
observer
},
loading: {
type: Boolean,
observer: observer
observer
},
block: {
type: Boolean,
observer: observer
observer
}
},
attached: function attached() {
attached() {
this.setClasses();
},
methods: {
onClick: function onClick() {
onClick() {
if (!this.data.disabled && !this.data.loading) {
this.triggerEvent('click');
}
},
setClasses: function setClasses() {
var _data = this.data,
type = _data.type,
size = _data.size,
plain = _data.plain,
disabled = _data.disabled,
loading = _data.loading,
block = _data.block;
setClasses() {
const { type, size, plain, disabled, loading, block } = this.data;
this.setData({
classes: classnames('van-button--' + type, 'van-button--' + size, {
classes: classnames(`van-button--${type}`, `van-button--${size}`, {
'van-button--block': block,
'van-button--plain': plain,
'van-button--loading': loading,
@ -72,4 +63,4 @@ Component({
});
}
}
});
});

13
dist/card/index.js vendored
View File

@ -1,11 +1,16 @@
'use strict';
Component({
options: {
multipleSlots: true
},
externalClasses: ['custom-class', 'thumb-class', 'title-class', 'price-class', 'desc-class', 'num-class'],
externalClasses: [
'custom-class',
'thumb-class',
'title-class',
'price-class',
'desc-class',
'num-class'
],
properties: {
num: String,
@ -19,4 +24,4 @@ Component({
default: '¥'
}
}
});
});

View File

@ -1,5 +1,3 @@
'use strict';
Component({
externalClasses: ['custom-class'],
@ -9,4 +7,4 @@ Component({
value: true
}
}
});
});

20
dist/cell/index.js vendored
View File

@ -1,7 +1,12 @@
'use strict';
Component({
externalClasses: ['custom-class', 'title-class', 'label-class', 'value-class', 'left-icon-class', 'right-icon-class'],
externalClasses: [
'custom-class',
'title-class',
'label-class',
'value-class',
'left-icon-class',
'right-icon-class'
],
options: {
multipleSlots: true
@ -31,13 +36,12 @@ Component({
},
methods: {
onClick: function onClick() {
var url = this.data.url;
onClick() {
const { url } = this.data;
if (url) {
wx[this.data.linkType]({ url: url });
wx[this.data.linkType]({ url });
}
this.triggerEvent('click');
}
}
});
});

24
dist/col/index.js vendored
View File

@ -1,15 +1,13 @@
'use strict';
var _relations;
var ROW_PATH = '../row/index';
const ROW_PATH = '../row/index';
Component({
externalClasses: ['custom-class'],
relations: (_relations = {}, _relations[ROW_PATH] = {
type: 'ancestor'
}, _relations),
relations: {
[ROW_PATH]: {
type: 'ancestor'
}
},
properties: {
span: Number,
@ -17,10 +15,10 @@ Component({
},
methods: {
setGutter: function setGutter(gutter) {
var padding = gutter / 2 + 'px';
var style = gutter ? 'padding-left: ' + padding + '; padding-right: ' + padding + ';' : '';
this.setData({ style: style });
setGutter(gutter) {
const padding = `${gutter / 2}px`;
const style = gutter ? `padding-left: ${padding}; padding-right: ${padding};` : '';
this.setData({ style });
}
}
});
});

View File

@ -1,25 +1,23 @@
'use strict';
var hasOwn = {}.hasOwnProperty;
const hasOwn = {}.hasOwnProperty;
module.exports = function classNames() {
var classes = [];
const classes = [];
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
for (let i = 0; i < arguments.length; i++) {
const arg = arguments[i];
if (!arg) continue;
var argType = typeof arg;
const argType = typeof arg;
if (argType === 'string' || argType === 'number') {
classes.push(arg);
} else if (Array.isArray(arg) && arg.length) {
var inner = classNames.apply(null, arg);
const inner = classNames.apply(null, arg);
if (inner) {
classes.push(inner);
}
} else if (argType === 'object') {
for (var key in arg) {
for (const key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(key);
}
@ -28,4 +26,4 @@ module.exports = function classNames() {
}
return classes.join(' ');
};
};

49
dist/field/index.js vendored
View File

@ -1,9 +1,9 @@
'use strict';
Component({
behaviors: ['wx://form-field'],
externalClasses: ['input-class'],
externalClasses: [
'input-class'
],
options: {
multipleSlots: true
@ -43,8 +43,8 @@ Component({
value: {
type: null,
value: '',
observer: function observer(currentValue) {
this.setData({ currentValue: currentValue });
observer(currentValue) {
this.setData({ currentValue });
}
},
type: {
@ -63,34 +63,32 @@ Component({
currentValue: ''
},
attached: function attached() {
attached() {
this.setData({
currentValue: this.data.value
});
},
methods: {
onInput: function onInput(event) {
var _ref = event.detail || {},
_ref$value = _ref.value,
value = _ref$value === undefined ? '' : _ref$value;
onInput(event) {
const { value = '' } = event.detail || {};
this.triggerEvent('input', value);
this.triggerEvent('change', value);
this.setData({
currentValue: value,
showClear: this.getShowClear({ value: value })
showClear: this.getShowClear({ value })
});
},
onFocus: function onFocus(event) {
onFocus(event) {
this.triggerEvent('focus', event);
this.setData({
focused: true,
showClear: this.getShowClear({ focused: true })
});
},
onBlur: function onBlur(event) {
onBlur(event) {
this.focused = false;
this.triggerEvent('blur', event);
this.setData({
@ -98,19 +96,21 @@ Component({
showClear: this.getShowClear({ focused: false })
});
},
onClickIcon: function onClickIcon() {
onClickIcon() {
this.triggerEvent('click-icon');
},
getShowClear: function getShowClear(options) {
var _options$focused = options.focused,
focused = _options$focused === undefined ? this.data.focused : _options$focused,
_options$value = options.value,
value = _options$value === undefined ? this.data.currentValue : _options$value;
getShowClear(options) {
const {
focused = this.data.focused,
value = this.data.currentValue
} = options;
return this.data.clearable && focused && value !== '' && !this.data.readonly;
},
onClear: function onClear() {
onClear() {
this.setData({
currentValue: '',
showClear: this.getShowClear({ value: '' })
@ -118,8 +118,9 @@ Component({
this.triggerEvent('input', '');
this.triggerEvent('change', '');
},
onConfirm: function onConfirm() {
onConfirm() {
this.triggerEvent('confirm', this.data.currentValue);
}
}
});
});

6
dist/icon/index.js vendored
View File

@ -1,5 +1,3 @@
'use strict';
Component({
externalClasses: ['custom-class'],
@ -11,8 +9,8 @@ Component({
},
methods: {
onClick: function onClick() {
onClick() {
this.triggerEvent('click');
}
}
});
});

1
dist/index.js vendored
View File

@ -1 +0,0 @@
"use strict";

View File

@ -1,5 +1,3 @@
'use strict';
Component({
externalClasses: ['custom-class'],
@ -17,4 +15,4 @@ Component({
value: '#c9c9c9'
}
}
});
});

14
dist/nav-bar/index.js vendored
View File

@ -1,7 +1,8 @@
'use strict';
Component({
externalClasses: ['custom-class', 'title-class'],
externalClasses: [
'custom-class',
'title-class'
],
options: {
multipleSlots: true
@ -20,11 +21,12 @@ Component({
},
methods: {
onClickLeft: function onClickLeft() {
onClickLeft() {
this.triggerEvent('click-left');
},
onClickRight: function onClickRight() {
onClickRight() {
this.triggerEvent('click-right');
}
}
});
});

View File

@ -1,8 +1,6 @@
'use strict';
var VALID_MODE = ['closeable', 'link'];
var FONT_COLOR = '#f60';
var BG_COLOR = '#fff7cc';
const VALID_MODE = ['closeable', 'link'];
const FONT_COLOR = '#f60';
const BG_COLOR = '#fff7cc';
Component({
externalClasses: ['custom-class'],
@ -11,7 +9,7 @@ Component({
text: {
type: String,
value: '',
observer: function observer() {
observer() {
this.setData({}, this._init);
}
},
@ -64,118 +62,116 @@ Component({
timer: null
},
attached: function attached() {
var mode = this.data.mode;
attached() {
const { mode } = this.data;
if (mode && this._checkMode(mode)) {
this.setData({
hasRightIcon: true
});
}
},
detached: function detached() {
var timer = this.data.timer;
detached() {
const { timer } = this.data;
timer && clearTimeout(timer);
},
methods: {
_checkMode: function _checkMode(val) {
var isValidMode = ~VALID_MODE.indexOf(val);
_checkMode(val) {
const isValidMode = ~VALID_MODE.indexOf(val);
if (!isValidMode) {
console.warn('mode only accept value of ' + VALID_MODE + ', now get ' + val + '.');
console.warn(`mode only accept value of ${VALID_MODE}, now get ${val}.`);
}
return isValidMode;
},
_init: function _init() {
var _this = this;
wx.createSelectorQuery().in(this).select('.van-notice-bar__content').boundingClientRect(function (rect) {
if (!rect || !rect.width) {
return;
}
_this.setData({
width: rect.width
});
wx.createSelectorQuery().in(_this).select('.van-notice-bar__content-wrap').boundingClientRect(function (rect) {
_init() {
wx.createSelectorQuery()
.in(this)
.select('.van-notice-bar__content')
.boundingClientRect((rect) => {
if (!rect || !rect.width) {
return;
}
this.setData({
width: rect.width
});
var wrapWidth = rect.width;
var _data = _this.data,
width = _data.width,
speed = _data.speed,
scrollable = _data.scrollable,
delay = _data.delay;
wx.createSelectorQuery()
.in(this)
.select('.van-notice-bar__content-wrap')
.boundingClientRect((rect) => {
if (!rect || !rect.width) {
return;
}
const wrapWidth = rect.width;
const {
width, speed, scrollable, delay
} = this.data;
if (scrollable && wrapWidth < width) {
var elapse = width / speed * 1000;
var animation = wx.createAnimation({
duration: elapse,
timeingFunction: 'linear',
delay: delay
});
var resetAnimation = wx.createAnimation({
duration: 0,
timeingFunction: 'linear'
});
if (scrollable && wrapWidth < width) {
const elapse = width / speed * 1000;
const animation = wx.createAnimation({
duration: elapse,
timeingFunction: 'linear',
delay
});
const resetAnimation = wx.createAnimation({
duration: 0,
timeingFunction: 'linear'
});
_this.setData({
elapse: elapse,
wrapWidth: wrapWidth,
animation: animation,
resetAnimation: resetAnimation
}, function () {
_this._scroll();
});
}
}).exec();
}).exec();
this.setData({
elapse,
wrapWidth,
animation,
resetAnimation
}, () => {
this._scroll();
});
}
})
.exec();
})
.exec();
},
_scroll: function _scroll() {
var _this2 = this;
var _data2 = this.data,
animation = _data2.animation,
resetAnimation = _data2.resetAnimation,
wrapWidth = _data2.wrapWidth,
elapse = _data2.elapse,
speed = _data2.speed;
_scroll() {
const {
animation, resetAnimation, wrapWidth, elapse, speed
} = this.data;
resetAnimation.translateX(wrapWidth).step();
var animationData = animation.translateX(-(elapse * speed) / 1000).step();
const animationData = animation.translateX(-(elapse * speed) / 1000).step();
this.setData({
animationData: resetAnimation.export()
});
setTimeout(function () {
_this2.setData({
setTimeout(() => {
this.setData({
animationData: animationData.export()
});
}, 100);
var timer = setTimeout(function () {
_this2._scroll();
const timer = setTimeout(() => {
this._scroll();
}, elapse);
this.setData({
timer: timer
timer
});
},
_handleButtonClick: function _handleButtonClick() {
var timer = this.data.timer;
_handleButtonClick() {
const { timer } = this.data;
timer && clearTimeout(timer);
this.setData({
show: false,
timer: null
});
},
onClick: function onClick(event) {
onClick(event) {
this.triggerEvent('click', event);
}
}
});
});

40
dist/notify/index.js vendored
View File

@ -1,7 +1,3 @@
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
Component({
properties: {
text: String,
@ -20,11 +16,8 @@ Component({
},
methods: {
show: function show() {
var _this = this;
var duration = this.data.duration;
show() {
const { duration } = this.data;
clearTimeout(this.timer);
this.setData({
@ -32,12 +25,13 @@ Component({
});
if (duration > 0 && duration !== Infinity) {
this.timer = setTimeout(function () {
_this.hide();
this.timer = setTimeout(() => {
this.hide();
}, duration);
}
},
hide: function hide() {
hide() {
clearTimeout(this.timer);
this.setData({
show: false
@ -46,32 +40,30 @@ Component({
}
});
var defaultOptions = {
const defaultOptions = {
selector: '#van-notify',
duration: 3000
};
function Notify() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var pages = getCurrentPages();
var ctx = pages[pages.length - 1];
function Notify(options = {}) {
const pages = getCurrentPages();
const ctx = pages[pages.length - 1];
options = Object.assign({}, defaultOptions, parseParam(options));
var el = ctx.selectComponent(options.selector);
const el = ctx.selectComponent(options.selector);
delete options.selector;
if (el) {
el.setData(_extends({}, options));
el.setData({
...options
});
el.show();
}
}
function parseParam() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
function parseParam(params = '') {
return typeof params === 'object' ? params : { text: params };
}
module.exports = Notify;
module.exports = Notify;

9
dist/panel/index.js vendored
View File

@ -1,7 +1,8 @@
'use strict';
Component({
externalClasses: ['custom-class', 'footer-class'],
externalClasses: [
'custom-class',
'footer-class'
],
options: {
multipleSlots: true
@ -14,4 +15,4 @@ Component({
headerClass: String,
useFooterSlot: Boolean
}
});
});

11
dist/popup/index.js vendored
View File

@ -1,7 +1,8 @@
'use strict';
Component({
externalClasses: ['custom-class', 'overlay-class'],
externalClasses: [
'custom-class',
'overlay-class'
],
properties: {
show: Boolean,
@ -21,7 +22,7 @@ Component({
},
methods: {
onClickOverlay: function onClickOverlay() {
onClickOverlay() {
this.triggerEvent('click-overlay');
if (this.data.closeOnClickOverlay) {
@ -29,4 +30,4 @@ Component({
}
}
}
});
});

38
dist/row/index.js vendored
View File

@ -1,43 +1,37 @@
'use strict';
var _relations;
var COL_PATH = '../col/index';
const COL_PATH = '../col/index';
Component({
externalClasses: ['custom-class'],
relations: (_relations = {}, _relations[COL_PATH] = {
type: 'descendant'
}, _relations),
relations: {
[COL_PATH]: {
type: 'descendant'
}
},
properties: {
gutter: {
type: Number,
observer: function observer() {
observer() {
this.setGutter();
}
}
},
ready: function ready() {
ready() {
this.setGutter();
},
methods: {
setGutter: function setGutter() {
var _this = this;
setGutter() {
const { gutter } = this.data;
const margin = `-${Number(gutter) / 2}px`;
const style = gutter ? `margin-right: ${margin}; margin-left: ${margin};` : '';
var gutter = this.data.gutter;
var margin = '-' + Number(gutter) / 2 + 'px';
var style = gutter ? 'margin-right: ' + margin + '; margin-left: ' + margin + ';' : '';
this.setData({ style: style });
this.getRelationNodes(COL_PATH).forEach(function (col) {
col.setGutter(_this.data.gutter);
this.setData({ style });
this.getRelationNodes(COL_PATH).forEach((col) => {
col.setGutter(this.data.gutter);
});
}
}
});
});

25
dist/search/index.js vendored
View File

@ -1,5 +1,3 @@
'use strict';
Component({
externalClasses: ['custom-class', 'cancel-class'],
@ -15,8 +13,8 @@ Component({
placeholder: String,
value: {
type: String,
observer: function observer(currentValue) {
this.setData({ currentValue: currentValue });
observer(currentValue) {
this.setData({ currentValue });
}
},
background: {
@ -29,28 +27,31 @@ Component({
}
},
attached: function attached() {
attached() {
this.setData({ currentValue: this.data.value });
},
methods: {
onChange: function onChange(event) {
onChange(event) {
this.triggerEvent('change', event.detail);
},
onCancel: function onCancel() {
onCancel() {
this.setData({ currentValue: '' });
this.triggerEvent('cancel');
this.triggerEvent('change', '');
},
onSearch: function onSearch() {
onSearch() {
this.triggerEvent('search', this.data.currentValue);
},
onFocus: function onFocus() {
onFocus() {
this.triggerEvent('focus');
},
onBlur: function onBlur() {
onBlur() {
this.triggerEvent('blur');
}
}
});
});

51
dist/stepper/index.js vendored
View File

@ -1,16 +1,19 @@
'use strict';
// Note that the bitwise operators and shift operators operate on 32-bit ints
// so in that case, the max safe integer is 2^31-1, or 2147483647
var MAX = 2147483647;
const MAX = 2147483647;
Component({
externalClasses: ['custom-class', 'input-class', 'plus-class', 'minus-class'],
externalClasses: [
'custom-class',
'input-class',
'plus-class',
'minus-class'
],
properties: {
value: {
type: null,
observer: function observer(val) {
observer(val) {
if (val !== this.currentValue) {
this.setData({ currentValue: this.range(val) });
}
@ -33,51 +36,53 @@ Component({
}
},
attached: function attached() {
attached() {
this.setData({
currentValue: this.range(this.data.value)
});
},
methods: {
// limit value range
range: function range(value) {
range(value) {
return Math.max(Math.min(this.data.max, value), this.data.min);
},
onInput: function onInput(event) {
var _ref = event.detail || {},
_ref$value = _ref.value,
value = _ref$value === undefined ? '' : _ref$value;
onInput(event) {
const { value = '' } = event.detail || {};
this.triggerInput(value);
},
onChange: function onChange(type) {
if (this[type + 'Disabled']) {
onChange(type) {
if (this[`${type}Disabled`]) {
this.triggerEvent('overlimit', type);
return;
}
var diff = type === 'minus' ? -this.data.step : +this.data.step;
var value = Math.round((this.data.currentValue + diff) * 100) / 100;
const diff = type === 'minus' ? -this.data.step : +this.data.step;
const value = Math.round((this.data.currentValue + diff) * 100) / 100;
this.triggerInput(this.range(value));
this.triggerEvent(type);
},
onBlur: function onBlur(event) {
var currentValue = this.range(this.data.currentValue);
onBlur(event) {
const currentValue = this.range(this.data.currentValue);
this.triggerInput(currentValue);
this.triggerEvent('blur', event);
},
onMinus: function onMinus() {
onMinus() {
this.onChange('minus');
},
onPlus: function onPlus() {
onPlus() {
this.onChange('plus');
},
triggerInput: function triggerInput(currentValue) {
this.setData({ currentValue: currentValue });
triggerInput(currentValue) {
this.setData({ currentValue });
this.triggerEvent('input', currentValue);
this.triggerEvent('change', currentValue);
}
}
});
});

39
dist/steps/index.js vendored
View File

@ -1,21 +1,19 @@
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
Component({
externalClasses: ['custom-class'],
externalClasses: [
'custom-class'
],
properties: {
icon: String,
steps: {
type: Array,
observer: function observer() {
observer() {
this.formatSteps();
}
},
active: {
type: Number,
observer: function observer() {
observer() {
this.formatSteps();
}
},
@ -29,30 +27,27 @@ Component({
}
},
attached: function attached() {
attached() {
this.formatSteps();
},
methods: {
formatSteps: function formatSteps() {
var _this = this;
var steps = this.data.steps;
var formattedSteps = steps.map(function (step, index) {
return _extends({}, step, {
status: _this.getStatus(index)
});
formatSteps() {
const { steps } = this.data;
const formattedSteps = steps.map((step, index) => {
return {
...step,
status: this.getStatus(index)
};
});
this.setData({
formattedSteps: formattedSteps
formattedSteps
});
},
getStatus: function getStatus(index) {
var active = this.data.active;
getStatus(index) {
const { active } = this.data;
if (index < active) {
return 'finish';
@ -63,4 +58,4 @@ Component({
return '';
}
}
});
});

View File

@ -1,5 +1,3 @@
'use strict';
Component({
externalClasses: ['custom-class', 'node-class'],
@ -14,12 +12,12 @@ Component({
},
methods: {
onClick: function onClick() {
onClick() {
if (!this.data.disabled && !this.data.loading) {
var checked = !this.data.checked;
const checked = !this.data.checked;
this.triggerEvent('input', checked);
this.triggerEvent('change', checked);
}
}
}
});
});

4
dist/tag/index.js vendored
View File

@ -1,5 +1,3 @@
'use strict';
Component({
externalClasses: ['custom-class'],
@ -8,4 +6,4 @@ Component({
mark: Boolean,
plain: Boolean
}
});
});

View File

@ -1,14 +1,10 @@
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var ITEM_HEIGHT = 44;
const ITEM_HEIGHT = 44;
Component({
properties: {
items: {
type: Array,
observer: function observer() {
observer() {
this.updateSubItems();
this.updateMainHeight();
}
@ -16,7 +12,7 @@ Component({
mainActiveIndex: {
type: Number,
value: 0,
observer: function observer() {
observer() {
this.updateSubItems();
}
},
@ -27,7 +23,7 @@ Component({
maxHeight: {
type: Number,
value: 300,
observer: function observer() {
observer() {
this.updateItemHeight();
this.updateMainHeight();
}
@ -42,46 +38,40 @@ Component({
methods: {
// 当一个子项被选择时
onSelectItem: function onSelectItem(event) {
var _ref = event.currentTarget || {},
_ref$dataset = _ref.dataset,
dataset = _ref$dataset === undefined ? {} : _ref$dataset;
this.triggerEvent('click-item', _extends({}, dataset.item || {}));
onSelectItem(event) {
const {
dataset = {}
} = event.currentTarget || {};
this.triggerEvent('click-item', { ...(dataset.item || {}) });
},
// 当一个导航被点击时
onClickNav: function onClickNav(event) {
var _ref2 = event.currentTarget || {},
_ref2$dataset = _ref2.dataset,
dataset = _ref2$dataset === undefined ? {} : _ref2$dataset;
onClickNav(event) {
const {
dataset = {}
} = event.currentTarget || {};
this.triggerEvent('click-nav', { index: dataset.index });
},
// 更新子项列表
updateSubItems: function updateSubItems() {
var selectedItem = this.data.items[this.data.mainActiveIndex] || {};
updateSubItems() {
const selectedItem = this.data.items[this.data.mainActiveIndex] || {};
this.setData({ subItems: selectedItem.children || [] });
this.updateItemHeight();
},
// 更新组件整体高度,根据最大高度和当前组件需要展示的高度来决定
updateMainHeight: function updateMainHeight() {
var maxHeight = Math.max(this.data.items.length * ITEM_HEIGHT, this.data.subItems.length * ITEM_HEIGHT);
updateMainHeight() {
const maxHeight = Math.max(this.data.items.length * ITEM_HEIGHT, this.data.subItems.length * ITEM_HEIGHT);
this.setData({ mainHeight: Math.min(maxHeight, this.data.maxHeight) });
},
// 更新子项列表高度,根据可展示的最大高度和当前子项列表的高度决定
updateItemHeight: function updateItemHeight() {
updateItemHeight() {
this.setData({ itemHeight: Math.min(this.data.subItems.length * ITEM_HEIGHT, this.data.maxHeight) });
}
}
});
});

11
dist/utils/index.js vendored
View File

@ -1,14 +1,13 @@
'use strict';
exports.__esModule = true;
function isDef(value) {
return value !== undefined && value !== null;
}
function isObj(x) {
var type = typeof x;
const type = typeof x;
return x !== null && (type === 'object' || type === 'function');
}
exports.isObj = isObj;
exports.isDef = isDef;
export {
isObj,
isDef
};

View File

@ -10,8 +10,8 @@
"lint": "eslint ./packages --ext .js",
"release": "sh build/release.sh",
"build": "sh scripts/deploy.sh",
"build:lib": "cross-env NODE_ENV=production node build/build-components.js --color",
"build:site": "rm -rf docs/dist && cross-env NODE_ENV=production webpack --config build/webpack.doc.js && gh-pages -d docs/dist"
"build:lib": "NODE_ENV=production node build/compiler.js",
"build:site": "rm -rf docs/dist && cross-env NODE_ENV=production webpack --config build/webpack.doc.prd.js && gh-pages -d docs/dist"
},
"files": [
"dist"
@ -45,7 +45,6 @@
"gulp-babel": "^7.0.1",
"gulp-clean-css": "^3.9.0",
"gulp-postcss": "^8.0.0",
"gulp-remove-logging": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-util": "^3.0.8",
"html-webpack-plugin": "^3.2.0",

View File

@ -7,7 +7,7 @@ function isObj(x) {
return x !== null && (type === 'object' || type === 'function');
}
export {
module.exports = {
isObj,
isDef
};

View File

@ -1280,10 +1280,6 @@ binary-extensions@^1.0.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.11.0.tgz#46aa1751fb6a2f93ee5e689bb1087d4b14c6c205"
binaryextensions@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/binaryextensions/-/binaryextensions-1.0.1.tgz#1e637488b35b58bda5f4774bf96a5212a8c90755"
bluebird@^3.1.1, bluebird@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9"
@ -2357,7 +2353,7 @@ escape-html@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.3, escape-string-regexp@^1.0.5:
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
@ -3127,24 +3123,10 @@ gulp-postcss@^8.0.0:
postcss-load-config "^2.0.0"
vinyl-sourcemaps-apply "^0.2.1"
gulp-remove-logging@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/gulp-remove-logging/-/gulp-remove-logging-1.2.0.tgz#fd16c19d368e243430126c619a393363e2cfe5a6"
dependencies:
gulp-replace "0.5.4"
gulp-rename@^1.2.2:
version "1.4.0"
resolved "https://registry.yarnpkg.com/gulp-rename/-/gulp-rename-1.4.0.tgz#de1c718e7c4095ae861f7296ef4f3248648240bd"
gulp-replace@0.5.4:
version "0.5.4"
resolved "https://registry.yarnpkg.com/gulp-replace/-/gulp-replace-0.5.4.tgz#69a67914bbd13c562bff14f504a403796aa0daa9"
dependencies:
istextorbinary "1.0.2"
readable-stream "^2.0.1"
replacestream "^4.0.0"
gulp-util@^3.0.0, gulp-util@^3.0.8:
version "3.0.8"
resolved "https://registry.yarnpkg.com/gulp-util/-/gulp-util-3.0.8.tgz#0054e1e744502e27c04c187c3ecc505dd54bbb4f"
@ -3839,13 +3821,6 @@ istanbul-lib-instrument@^1.10.1:
istanbul-lib-coverage "^1.2.0"
semver "^5.3.0"
istextorbinary@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/istextorbinary/-/istextorbinary-1.0.2.tgz#ace19354d1a9a0173efeb1084ce0f87b0ad7decf"
dependencies:
binaryextensions "~1.0.0"
textextensions "~1.0.0"
js-base64@^2.1.9:
version "2.4.8"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.8.tgz#57a9b130888f956834aa40c5b165ba59c758f033"
@ -5840,14 +5815,6 @@ replace-ext@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-0.0.1.tgz#29bbd92078a739f0bcce2b4ee41e837953522924"
replacestream@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/replacestream/-/replacestream-4.0.3.tgz#3ee5798092be364b1cdb1484308492cb3dff2f36"
dependencies:
escape-string-regexp "^1.0.3"
object-assign "^4.0.1"
readable-stream "^2.0.2"
require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
@ -6413,10 +6380,6 @@ text-table@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
textextensions@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/textextensions/-/textextensions-1.0.2.tgz#65486393ee1f2bb039a60cbba05b0b68bd9501d2"
thenify-all@^1.0.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726"