From 8c690d963e42723199a3b133832dc3fef387f6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20LAGIER?= Date: Tue, 25 Jan 2022 22:38:18 +0100 Subject: [PATCH] MINOR: Add DS Vue Plugin (#163) * update package.lock -_- * add DS Vue plugin --- package-lock.json | 5 ----- package.json | 1 + plugin.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 plugin.js diff --git a/package-lock.json b/package-lock.json index b10b8ee1..05f8e1d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17619,11 +17619,6 @@ "safer-buffer": "^2.0.2", "tweetnacl": "~0.14.0" }, - "bin": { - "sshpk-conv": "bin/sshpk-conv", - "sshpk-sign": "bin/sshpk-sign", - "sshpk-verify": "bin/sshpk-verify" - }, "engines": { "node": ">=0.10.0" } diff --git a/package.json b/package.json index 13cb5fdc..3579e763 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "files": [ "dist/*", "components.js", + "plugin.js", "screenshots/*" ], "scripts": { diff --git a/plugin.js b/plugin.js new file mode 100644 index 00000000..f43a0afd --- /dev/null +++ b/plugin.js @@ -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;