"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.unifySlots = unifySlots; exports.useSFC = void 0; require("../../locale"); var _ = require(".."); var _slots = require("../../mixins/slots"); var _vue = _interopRequireDefault(require("vue")); /** * Create a basic component with common options */ 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((0, _.camelize)("-" + name), this); } // unify slots & scopedSlots 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); } }; } 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(_slots.SlotsMixin); } if (sfc.props) { defaultProps(sfc.props); } sfc.name = name; sfc.install = install; return sfc; }; }; exports.useSFC = useSFC;