UNPKG

@meve/ui

Version:

Argon design system components library

85 lines (77 loc) 2.35 kB
import { bigCamelize, isArray, isFunction, kebabCase } from './shared'; import { SlotsMixin } from './mixins/slots'; export function mergeSlots(context) { var _ref, _context$scopedSlots; var scopedSlots = (_ref = (_context$scopedSlots = context.scopedSlots) != null ? _context$scopedSlots : context.data.scopedSlots) != null ? _ref : {}; var slots = context.slots(); Object.keys(slots).forEach(function (key) { if (!scopedSlots[key]) { scopedSlots[key] = function () { return slots[key]; }; } }); return scopedSlots; } export function wrapFunctionComponent(functionComponent) { return { functional: true, props: functionComponent.props, render: function render(h, context) { return functionComponent(h, context.props, mergeSlots(context), context); } }; } export function install(Vue) { Vue.component(this.name, this); } function _createComponent(name, sfc) { if (isFunction(sfc)) { sfc = wrapFunctionComponent(sfc); } else if (sfc.mixins) { ; sfc.mixins.push(SlotsMixin); } else { ; sfc.mixins = [SlotsMixin]; } sfc.name = "M" + bigCamelize(name); sfc.install = install; return sfc; } export { _createComponent as createComponent }; export function createNamespace(name) { return { createComponent: function createComponent(sfc) { return _createComponent(name, sfc); }, namespace: function namespace(suffix) { if (suffix === void 0) { suffix = ''; } return "m-" + kebabCase(name) + suffix; } }; } var inheritKeys = ['ref', 'key', 'style', 'class', 'attrs', 'refInFor', 'nativeOn', 'directives', 'staticClass', 'staticStyle']; export function inherit(context) { return inheritKeys.reduce(function (ret, key) { if (context.data[key]) { ret[key === 'nativeOn' ? 'on' : key] = context.data[key]; } return ret; }, {}); } export function emit(context, eventName) { for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { args[_key - 2] = arguments[_key]; } var listeners = context.listeners[eventName]; if (isArray(listeners)) { listeners.forEach(function (listener) { return listener.apply(void 0, args); }); } else { listeners == null ? void 0 : listeners.apply(void 0, args); } }