From 88f808711a52ce3a9fc03097d4d03a54efc445f5 Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Sun, 10 Apr 2022 17:40:27 +0200 Subject: [PATCH] feat: Allow node/edge template per element * Allow templates to be overwritten per element with template option --- .eslintrc.js | 1 + docs/src/.vuepress/auto-imports.d.ts | 22 +++++++++- docs/src/guide/edge.md | 46 ++++++++++++++++++++ docs/src/guide/node.md | 38 ++++++++++++++++ package/src/components/Edges/EdgeWrapper.vue | 3 +- package/src/components/Nodes/NodeWrapper.vue | 5 ++- package/src/types/edge.ts | 23 ++++------ package/src/types/flow.ts | 4 +- package/src/types/node.ts | 7 ++- 9 files changed, 126 insertions(+), 23 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c15ec840..3531dfeb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,5 @@ const baseRules = { + 'no-console': 0, 'chai-friendly/no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true }], 'prettier/prettier': ['error', {}, { usePrettierrc: true }], } diff --git a/docs/src/.vuepress/auto-imports.d.ts b/docs/src/.vuepress/auto-imports.d.ts index d7d68940..e9ff9a17 100644 --- a/docs/src/.vuepress/auto-imports.d.ts +++ b/docs/src/.vuepress/auto-imports.d.ts @@ -3,14 +3,17 @@ declare global { const asyncComputed: typeof import('@vueuse/core')['asyncComputed'] const autoResetRef: typeof import('@vueuse/core')['autoResetRef'] - const biSyncRef: typeof import('@vueuse/core')['biSyncRef'] const computed: typeof import('vue')['computed'] + const computedAsync: typeof import('@vueuse/core')['computedAsync'] + const computedEager: typeof import('@vueuse/core')['computedEager'] const computedInject: typeof import('@vueuse/core')['computedInject'] + const computedWithControl: typeof import('@vueuse/core')['computedWithControl'] const controlledComputed: typeof import('@vueuse/core')['controlledComputed'] const controlledRef: typeof import('@vueuse/core')['controlledRef'] const createApp: typeof import('vue')['createApp'] const createEventHook: typeof import('@vueuse/core')['createEventHook'] const createGlobalState: typeof import('@vueuse/core')['createGlobalState'] + const createInjectionState: typeof import('@vueuse/core')['createInjectionState'] const createReactiveFn: typeof import('@vueuse/core')['createReactiveFn'] const createSharedComposable: typeof import('@vueuse/core')['createSharedComposable'] const createUnrefFn: typeof import('@vueuse/core')['createUnrefFn'] @@ -31,6 +34,9 @@ declare global { const isDefined: typeof import('@vueuse/core')['isDefined'] const isReadonly: typeof import('vue')['isReadonly'] const isRef: typeof import('vue')['isRef'] + const logicAnd: typeof import('@vueuse/core')['logicAnd'] + const logicNot: typeof import('@vueuse/core')['logicNot'] + const logicOr: typeof import('@vueuse/core')['logicOr'] const makeDestructurable: typeof import('@vueuse/core')['makeDestructurable'] const markRaw: typeof import('vue')['markRaw'] const nextTick: typeof import('vue')['nextTick'] @@ -61,12 +67,17 @@ declare global { const reactivePick: typeof import('@vueuse/core')['reactivePick'] const readonly: typeof import('vue')['readonly'] const ref: typeof import('vue')['ref'] + const refAutoReset: typeof import('@vueuse/core')['refAutoReset'] + const refDebounced: typeof import('@vueuse/core')['refDebounced'] const refDefault: typeof import('@vueuse/core')['refDefault'] + const refThrottled: typeof import('@vueuse/core')['refThrottled'] + const refWithControl: typeof import('@vueuse/core')['refWithControl'] const resolveComponent: typeof import('vue')['resolveComponent'] const shallowReactive: typeof import('vue')['shallowReactive'] const shallowReadonly: typeof import('vue')['shallowReadonly'] const shallowRef: typeof import('vue')['shallowRef'] const syncRef: typeof import('@vueuse/core')['syncRef'] + const syncRefs: typeof import('@vueuse/core')['syncRefs'] const templateRef: typeof import('@vueuse/core')['templateRef'] const throttledRef: typeof import('@vueuse/core')['throttledRef'] const throttledWatch: typeof import('@vueuse/core')['throttledWatch'] @@ -75,6 +86,7 @@ declare global { const toRef: typeof import('vue')['toRef'] const toRefs: typeof import('vue')['toRefs'] const triggerRef: typeof import('vue')['triggerRef'] + const tryOnBeforeMount: typeof import('@vueuse/core')['tryOnBeforeMount'] const tryOnBeforeUnmount: typeof import('@vueuse/core')['tryOnBeforeUnmount'] const tryOnMounted: typeof import('@vueuse/core')['tryOnMounted'] const tryOnScopeDispose: typeof import('@vueuse/core')['tryOnScopeDispose'] @@ -102,6 +114,7 @@ declare global { const useCssVars: typeof import('vue')['useCssVars'] const useCycleList: typeof import('@vueuse/core')['useCycleList'] const useDark: typeof import('@vueuse/core')['useDark'] + const useDateFormat: typeof import('@vueuse/core')['useDateFormat'] const useDebounce: typeof import('@vueuse/core')['useDebounce'] const useDebouncedRefHistory: typeof import('@vueuse/core')['useDebouncedRefHistory'] const useDebounceFn: typeof import('@vueuse/core')['useDebounceFn'] @@ -123,10 +136,12 @@ declare global { const useEyeDropper: typeof import('@vueuse/core')['useEyeDropper'] const useFavicon: typeof import('@vueuse/core')['useFavicon'] const useFetch: typeof import('@vueuse/core')['useFetch'] + const useFileSystemAccess: typeof import('@vueuse/core')['useFileSystemAccess'] const useFocus: typeof import('@vueuse/core')['useFocus'] const useFocusWithin: typeof import('@vueuse/core')['useFocusWithin'] const useFps: typeof import('@vueuse/core')['useFps'] const useFullscreen: typeof import('@vueuse/core')['useFullscreen'] + const useGamepad: typeof import('@vueuse/core')['useGamepad'] const useGeolocation: typeof import('@vueuse/core')['useGeolocation'] const useIdle: typeof import('@vueuse/core')['useIdle'] const useInfiniteScroll: typeof import('@vueuse/core')['useInfiniteScroll'] @@ -184,6 +199,7 @@ declare global { const useTimeAgo: typeof import('@vueuse/core')['useTimeAgo'] const useTimeout: typeof import('@vueuse/core')['useTimeout'] const useTimeoutFn: typeof import('@vueuse/core')['useTimeoutFn'] + const useTimeoutPoll: typeof import('@vueuse/core')['useTimeoutPoll'] const useTimestamp: typeof import('@vueuse/core')['useTimestamp'] const useTitle: typeof import('@vueuse/core')['useTitle'] const useToggle: typeof import('@vueuse/core')['useToggle'] @@ -204,8 +220,12 @@ declare global { const useWindowSize: typeof import('@vueuse/core')['useWindowSize'] const watch: typeof import('vue')['watch'] const watchAtMost: typeof import('@vueuse/core')['watchAtMost'] + const watchDebounced: typeof import('@vueuse/core')['watchDebounced'] const watchEffect: typeof import('vue')['watchEffect'] + const watchIgnorable: typeof import('@vueuse/core')['watchIgnorable'] const watchOnce: typeof import('@vueuse/core')['watchOnce'] + const watchPausable: typeof import('@vueuse/core')['watchPausable'] + const watchThrottled: typeof import('@vueuse/core')['watchThrottled'] const watchWithFilter: typeof import('@vueuse/core')['watchWithFilter'] const whenever: typeof import('@vueuse/core')['whenever'] } diff --git a/docs/src/guide/edge.md b/docs/src/guide/edge.md index 323300bd..82f2808f 100644 --- a/docs/src/guide/edge.md +++ b/docs/src/guide/edge.md @@ -271,6 +271,52 @@ const elements = ref([ ``` +### Edge Template + +You can also set a template per edge, which will overwrite the edge-type component but will retain +the type otherwise. + +```vue:no-line-numbers + + +``` + ### Custom Edge Props Your custom edges are wrapped so that the basic functions like selecting work. diff --git a/docs/src/guide/node.md b/docs/src/guide/node.md index ad2e186b..56811bd8 100644 --- a/docs/src/guide/node.md +++ b/docs/src/guide/node.md @@ -266,6 +266,44 @@ const elements = ref([ You can find a more advanced example here. ::: +### Node Template + +You can also set a template per node, which will overwrite the node-type component but will retain +the type otherwise. + +```vue:no-line-numbers + + +``` + ### Custom Node Props Your custom nodes are wrapped so that the basic functions like dragging or selecting work. diff --git a/package/src/components/Edges/EdgeWrapper.vue b/package/src/components/Edges/EdgeWrapper.vue index c571b1cb..ed8c55e2 100644 --- a/package/src/components/Edges/EdgeWrapper.vue +++ b/package/src/components/Edges/EdgeWrapper.vue @@ -124,8 +124,9 @@ watch( ) const type = computed(() => { + let edgeType = edge.value.template ?? store.getEdgeTypes[name.value] const instance = getCurrentInstance() - let edgeType = store.getEdgeTypes[name.value] + if (typeof edgeType === 'string') { if (instance) { const components = Object.keys(instance.appContext.components) diff --git a/package/src/components/Nodes/NodeWrapper.vue b/package/src/components/Nodes/NodeWrapper.vue index 34b9c53b..7bdec652 100644 --- a/package/src/components/Nodes/NodeWrapper.vue +++ b/package/src/components/Nodes/NodeWrapper.vue @@ -1,6 +1,6 @@