| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /**
- * Create a basic component with common options
- */
- import '../../locale';
- import { camelize } from '..';
- import { SlotsMixin } from '../../mixins/slots';
- import Vue from 'vue';
- var arrayProp = {
- type: Array,
- "default": function _default() {
- return [];
- }
- };
- var numberProp = {
- type: Number,
- "default": 0
- };
- function defaultProps(props) {
- Object.keys(props).forEach(function (key) {
- if (props[key] === Array) {
- props[key] = arrayProp;
- } else if (props[key] === Number) {
- props[key] = numberProp;
- }
- });
- }
- 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 var useSFC = function useSFC(name) {
- return function (sfc) {
- if (typeof sfc === 'function') {
- sfc = transformFunctionComponent(sfc);
- }
- if (!sfc.functional) {
- sfc.mixins = sfc.mixins || [];
- sfc.mixins.push(SlotsMixin);
- }
- if (sfc.props) {
- defaultProps(sfc.props);
- }
- sfc.name = name;
- sfc.install = install;
- return sfc;
- };
- };
|