From 753f7070c7917d46094a80715a22924cefa06b38 Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Sat, 10 Jul 2021 14:07:39 +0200 Subject: [PATCH] feat: plugin config update: package.json --- package.json | 2 +- src/index.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 47a1c701..7cf31170 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "d3-zoom": "^3.0.0", "fast-deep-equal": "^3.1.3", "pinia": "^2.0.0-beta.3", - "vue": "^3.0.5", "vue-demi": "latest" }, "devDependencies": { @@ -76,6 +75,7 @@ "rollup-plugin-vue": "^6.0.0", "typescript": "^4.3.5", "vite": "^2.3.8", + "vue": "^3.0.5", "vue-tsc": "^0.0.24" }, "peerDependencies": { diff --git a/src/index.ts b/src/index.ts index 8d33b3e4..06369387 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import RevueFlow from './container/RevueFlow'; +import { App, inject, InjectionKey } from 'vue-demi'; export default RevueFlow; @@ -25,3 +26,32 @@ export { default as useUpdateNodeInternals } from './hooks/useUpdateNodeInternal export * from './additional-components'; export * from './types'; + +export interface RevueFlowOptions { + theme: string; +} + +export interface RevueFlowPlugin { + options?: RevueFlowOptions; + + install(app: App): void; +} + +export const RevueFlowPluginSymbol: InjectionKey = Symbol(); + +export function RevueFlowPlugin(): RevueFlowPlugin { + const RevueFlowPlugin = inject(RevueFlowPluginSymbol); + if (!RevueFlowPlugin) throw new Error('No RevueFlowPlugin provided.'); + + return RevueFlowPlugin; +} + +export function createVueCounterPlugin(options?: RevueFlowOptions): RevueFlowPlugin { + return { + options, + install(app: App) { + app.component('revue-flow', RevueFlow); + app.provide(RevueFlowPluginSymbol, this); + } + }; +}