first
This commit is contained in:
39
node_modules/vant/es/utils/create/bem.js
generated
vendored
Normal file
39
node_modules/vant/es/utils/create/bem.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* bem helper
|
||||
* b() // 'button'
|
||||
* b('text') // 'button__text'
|
||||
* b({ disabled }) // 'button button--disabled'
|
||||
* b('text', { disabled }) // 'button__text button__text--disabled'
|
||||
* b(['disabled', 'primary']) // 'button button--disabled button--primary'
|
||||
*/
|
||||
function gen(name, mods) {
|
||||
if (!mods) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (typeof mods === 'string') {
|
||||
return " " + name + "--" + mods;
|
||||
}
|
||||
|
||||
if (Array.isArray(mods)) {
|
||||
return mods.reduce(function (ret, item) {
|
||||
return ret + gen(name, item);
|
||||
}, '');
|
||||
}
|
||||
|
||||
return Object.keys(mods).reduce(function (ret, key) {
|
||||
return ret + (mods[key] ? gen(name, key) : '');
|
||||
}, '');
|
||||
}
|
||||
|
||||
export function createBEM(name) {
|
||||
return function (el, mods) {
|
||||
if (el && typeof el !== 'string') {
|
||||
mods = el;
|
||||
el = '';
|
||||
}
|
||||
|
||||
el = el ? name + "__" + el : name;
|
||||
return "" + el + gen(el, mods);
|
||||
};
|
||||
}
|
57
node_modules/vant/es/utils/create/component.js
generated
vendored
Normal file
57
node_modules/vant/es/utils/create/component.js
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Create a basic component with common options
|
||||
*/
|
||||
import '../../locale';
|
||||
import { isFunction } from '..';
|
||||
import { camelize } from '../format/string';
|
||||
import { SlotsMixin } from '../../mixins/slots';
|
||||
import Vue from 'vue';
|
||||
|
||||
function install(Vue) {
|
||||
var name = this.name;
|
||||
Vue.component(name, this);
|
||||
Vue.component(camelize("-" + name), this);
|
||||
} // unify slots & scopedSlots
|
||||
|
||||
|
||||
export function unifySlots(context) {
|
||||
// use data.scopedSlots in lower Vue version
|
||||
var scopedSlots = context.scopedSlots || context.data.scopedSlots || {};
|
||||
var slots = context.slots();
|
||||
Object.keys(slots).forEach(function (key) {
|
||||
if (!scopedSlots[key]) {
|
||||
scopedSlots[key] = function () {
|
||||
return slots[key];
|
||||
};
|
||||
}
|
||||
});
|
||||
return scopedSlots;
|
||||
} // should be removed after Vue 3
|
||||
|
||||
function transformFunctionComponent(pure) {
|
||||
return {
|
||||
functional: true,
|
||||
props: pure.props,
|
||||
model: pure.model,
|
||||
render: function render(h, context) {
|
||||
return pure(h, context.props, unifySlots(context), context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function createComponent(name) {
|
||||
return function (sfc) {
|
||||
if (isFunction(sfc)) {
|
||||
sfc = transformFunctionComponent(sfc);
|
||||
}
|
||||
|
||||
if (!sfc.functional) {
|
||||
sfc.mixins = sfc.mixins || [];
|
||||
sfc.mixins.push(SlotsMixin);
|
||||
}
|
||||
|
||||
sfc.name = name;
|
||||
sfc.install = install;
|
||||
return sfc;
|
||||
};
|
||||
}
|
16
node_modules/vant/es/utils/create/i18n.js
generated
vendored
Normal file
16
node_modules/vant/es/utils/create/i18n.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
import { get, isFunction } from '..';
|
||||
import { camelize } from '../format/string';
|
||||
import locale from '../../locale';
|
||||
export function createI18N(name) {
|
||||
var prefix = camelize(name) + '.';
|
||||
return function (path) {
|
||||
var messages = locale.messages();
|
||||
var message = get(messages, prefix + path) || get(messages, path);
|
||||
|
||||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
args[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
return isFunction(message) ? message.apply(void 0, args) : message;
|
||||
};
|
||||
}
|
7
node_modules/vant/es/utils/create/index.js
generated
vendored
Normal file
7
node_modules/vant/es/utils/create/index.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import { createBEM } from './bem';
|
||||
import { createComponent } from './component';
|
||||
import { createI18N } from './i18n';
|
||||
export function createNamespace(name) {
|
||||
name = 'van-' + name;
|
||||
return [createComponent(name), createBEM(name), createI18N(name)];
|
||||
}
|
Reference in New Issue
Block a user