Skip to content

Commit

Permalink
MINOR: Add DS Vue Plugin (#163)
Browse files Browse the repository at this point in the history
* update package.lock -_-

* add DS Vue plugin
  • Loading branch information
Kurtil committed Jan 25, 2022
1 parent 9d47291 commit 8c690d9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"files": [
"dist/*",
"components.js",
"plugin.js",
"screenshots/*"
],
"scripts": {
Expand Down
42 changes: 42 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as Components from "./dist/js/BIMDataComponents/index.js";
import * as Directives from "./dist/js/BIMDataDirectives/index.js";

/**
* Instal components and directives from the design system.
* WARNING: The css needs to be added manually.
* @param { { directives?: boolean, includedComponents?: string[], excludedComponents?: string[] } } [cfg]
*/
const pluginFactory = cfg => {
return {
install(Vue) {
// COMPONENTS
Object.entries(Components).forEach(([componentName, component]) => {
if (
cfg &&
cfg.excludedComponents &&
cfg.excludedComponents.length > 0 &&
cfg.excludedComponents.includes(componentName)
) {
return;
}

if (
!cfg ||
!cfg.includedComponents ||
cfg.includedComponents.includes(componentName)
) {
Vue.component(componentName, component);
}
});

// DIRECTIVES
if (!cfg || cfg.directives === false) {
Object.entries(Directives).forEach(([directiveName, directive]) =>
Vue.directive(directiveName.split("BIMData")[1], directive)
);
}
},
};
};

export default pluginFactory;

0 comments on commit 8c690d9

Please sign in to comment.