Skip to content

Commit 8a8c8f5

Browse files
committed
feat(core): add missing styles warning
1 parent 9eb5769 commit 8a8c8f5

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { onMounted } from 'vue'
2+
import { ErrorCode, VueFlowError, isDev } from '../utils'
3+
import { useVueFlow } from './useVueFlow'
4+
5+
export function useStylesLoadedWarning() {
6+
const { emits } = useVueFlow()
7+
8+
onMounted(() => {
9+
if (isDev()) {
10+
const pane = document.querySelector('.vue-flow__pane')
11+
12+
if (pane && !(window.getComputedStyle(pane).zIndex === '1')) {
13+
emits.error(new VueFlowError(ErrorCode.MISSING_STYLES))
14+
}
15+
}
16+
})
17+
}

packages/core/src/container/VueFlow/VueFlow.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useVueFlow } from '../../composables/useVueFlow'
1111
import { useHooks } from '../../store/hooks'
1212
import EdgeRenderer from '../EdgeRenderer/EdgeRenderer.vue'
1313
import NodeRenderer from '../NodeRenderer/NodeRenderer.vue'
14+
import { useStylesLoadedWarning } from '../../composables/useStylesLoadedWarning'
1415
1516
const props = withDefaults(defineProps<FlowProps>(), {
1617
snapToGrid: undefined,
@@ -70,6 +71,8 @@ useHooks(emit, hooks)
7071
7172
useOnInitHandler()
7273
74+
useStylesLoadedWarning()
75+
7376
// slots will be passed via provide
7477
// this is to avoid having to pass them down through all the components
7578
// as that would require a lot of boilerplate and causes significant performance drops

packages/core/src/utils/errors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum ErrorCode {
2+
MISSING_STYLES = 'MISSING_STYLES',
23
MISSING_VIEWPORT_DIMENSIONS = 'MISSING_VIEWPORT_DIMENSIONS',
34
NODE_INVALID = 'NODE_INVALID',
45
NODE_NOT_FOUND = 'NODE_NOT_FOUND',
@@ -16,6 +17,8 @@ export enum ErrorCode {
1617
}
1718

1819
const messages = {
20+
[ErrorCode.MISSING_STYLES]: () =>
21+
`It seems that you haven't loaded the necessary styles. Please import '@vue-flow/core/dist/style.css' to ensure that the graph is rendered correctly`,
1922
[ErrorCode.MISSING_VIEWPORT_DIMENSIONS]: () => 'The Vue Flow parent container needs a width and a height to render the graph',
2023
[ErrorCode.NODE_INVALID]: (id?: string) => `Node is invalid\nNode: ${id}`,
2124
[ErrorCode.NODE_NOT_FOUND]: (id: string | null) => `Node not found\nNode: ${id}`,

packages/core/src/utils/log.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
const productionEnvs = ['production', 'prod']
22

33
export function warn(message: string, ...args: any[]) {
4-
if (!productionEnvs.includes(__ENV__ || '')) {
4+
if (isDev()) {
55
console.warn(`[Vue Flow]: ${message}`, ...args)
66
}
77
}
8+
9+
export function isDev() {
10+
return !productionEnvs.includes(__ENV__ || '')
11+
}

0 commit comments

Comments
 (0)