@ishitatsuyuki/oruga-next
Version:
UI components for Vue.js and CSS framework agnostic
36 lines (32 loc) • 1.26 kB
JavaScript
;
// oruga object for programmatic components
const oruga = {};
// add components to the oruga object
function addProgrammatic(property, component) {
oruga[property] = component;
}
// composable for internal and external usage
function useProgrammatic() {
return { oruga, addProgrammatic };
}
const registerPlugin = (app, plugin) => {
app.use(plugin);
};
const registerComponent = (app, component) => {
app.component(component.name, component);
};
const registerComponentProgrammatic = (app, property, component) => {
// use composable for unified access to programmatic oruga object
const { oruga, addProgrammatic } = useProgrammatic();
// add component (manipulates the programmatic oruga object)
addProgrammatic(property, component);
// add provide and $oruga (only needed once)
if (!(app._context.provides && app._context.provides.oruga))
app.provide('oruga', oruga);
if (!app.config.globalProperties.$oruga)
app.config.globalProperties.$oruga = oruga;
};
exports.registerComponent = registerComponent;
exports.registerComponentProgrammatic = registerComponentProgrammatic;
exports.registerPlugin = registerPlugin;
exports.useProgrammatic = useProgrammatic;