Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vue3]使用Stencil时,拖拽/点击Stencil中的Node时报错,Uncaught TypeError: Cannot read properties of null (reading 'undelegateEvents') #3082

Closed
xkkjiayou opened this issue Dec 21, 2022 · 8 comments
Labels

Comments

@xkkjiayou
Copy link

xkkjiayou commented Dec 21, 2022

Describe the bug

index.ts:147 Uncaught TypeError: Cannot read properties of null (reading 'undelegateEvents')
    at Dnd.prepareDragging (index.ts:147:18)
    at Dnd.start (index.ts:87:10)
    at Stencil.onDragStart (index.ts:251:14)
    at Object.apply (function.ts:15:19)
    at call2 (util.ts:9:29)
    at Graph.trigger (events.ts:146:20)
    at NodeView.notify (cell.ts:620:16)
    at NodeView.onMouseDown (cell.ts:659:10)
    at NodeView.notifyMouseDown (node.ts:456:11)
    at NodeView.onMouseDown (node.ts:489:10)

Your Example Website or App

Steps to Reproduce the Bug or Issue

1.使用Stencil时,拖拽/点击Stencil中的Node时报错,Uncaught TypeError: Cannot read properties of null (reading 'undelegateEvents')
我的代码时直接参考X6文档中复制的:

<template>
    <div class="content">
        <div id="stencil" class="app-stencil" ref="stencil"></div>
        <div id="container" class="app-content" ref="container"></div>
    </div>
</template>
  
<script lang="ts">
// import "@antv/x6-vue-shape";
import { Graph, Node, Path, Cell } from "@antv/x6";
import { Stencil } from "@antv/x6-plugin-stencil";
import { Snapline } from '@antv/x6-plugin-snapline'
import { Dnd } from "@antv/x6-plugin-dnd";
import { Shape } from '@antv/x6'
export default {
    data() {
        return {
            moduleList: [
                {
                    id: 1,
                    name: '开始模块',
                    type: 'initial' // 初始模块(用于区分样式)
                },
                {
                    id: 2,
                    name: '结束模块',
                    type: 'initial'
                },
                {
                    id: 3,
                    name: '逻辑模块1',
                    type: 'logic' // 逻辑模块(用于区分样式)
                },
                {
                    id: 4,
                    name: '逻辑模块2',
                    type: 'logic'
                }
            ], // 列表可拖动模块
            graph: null, // 画布实例对象
            curSelectNode: null, // 当前选中的节点
            stencil: {},
            stencilContainer: {}
        }
    },
    mounted() {
        this.initGraph()
    },
    methods: {
        // 初始化流程图画布
        initGraph() {
            const graph = new Graph({
                container: this.$refs.container,
                width: 800,
                height: 600,
                background: {
                    color: "#F2F7FA",
                },
                panning: true,
                mousewheel: true,
                background: {
                    color: '#F2F7FA',
                },
                grid: {
                    visible: true,
                    type: 'doubleMesh',
                    args: [
                        {
                            color: '#eee', // 主网格线颜色
                            thickness: 1, // 主网格线宽度
                        },
                        {
                            color: '#ddd', // 次网格线颜色
                            thickness: 1, // 次网格线宽度
                            factor: 4, // 主次网格线间隔
                        },
                    ],
                },
            });
            // graph.fromJSON(data)
            graph.centerContent()

            const source = graph.addNode({
                x: 130,
                y: 30,
                width: 100,
                height: 40,
                label: 'Hello',
                attrs: {
                    body: {
                        stroke: '#8f8f8f',
                        strokeWidth: 1,
                        fill: '#fff',
                        rx: 6,
                        ry: 6,
                    },
                },
            })

            const target = graph.addNode({
                x: 320,
                y: 240,
                width: 100,
                height: 40,
                label: 'World',
                attrs: {
                    body: {
                        stroke: '#8f8f8f',
                        strokeWidth: 1,
                        fill: '#fff',
                        rx: 6,
                        ry: 6,
                    },
                },
            })

            graph.addEdge({
                source,
                target,
                attrs: {
                    line: {
                        stroke: '#8f8f8f',
                        strokeWidth: 1,
                    },
                },
            })
            this.graph = graph
            graph.centerContent()

            this.stencil = new Stencil({
                title: 'Components',
                target: this.graph,
                search(cell, keyword) {
                    return cell.shape.indexOf(keyword) !== -1
                },
                placeholder: 'Search by shape name',
                notFoundText: 'Not Found',
                collapsable: true,
                stencilGraphWidth: 200,
                stencilGraphHeight: 100,
                groups: [
                    {
                        name: 'group1',
                        title: 'Group(Collapsable)',
                    },
                    {
                        name: 'group2',
                        title: 'Group',
                        collapsable: false,
                    },
                ],
            })
            this.$refs.stencil.appendChild(this.stencil.container)

            const r = new Shape.Rect({
                width: 70,
                height: 40,
                attrs: {
                    rect: {
                        fill: "#31D0C6",
                        stroke: "#4B4A67",
                        strokeWidth: 6,
                    },
                    text: { text: "rect", fill: "white" },
                },
            });

            this.stencil.load([r], 'group1')
            // stencil.load([n3, n4], 'group2')


        },


    },
}
</script>

<style >
.content {
    font-family: sans-serif;
    display: flex;
}

.app-stencil {
    width: 250px;
    border: 1px solid #f0f0f0;
    position: relative;
}

.app-content {
    flex: 1;
    height: 520px;
    margin-left: 8px;
    margin-right: 8px;
    box-shadow: 0 0 10px 1px #e9e9e9;
}

.x6-graph-scroller {
    border: 1px solid #f0f0f0;
    margin-left: -1px;
}
</style>

Expected behavior

应该拖拽成功,结果失败了

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 15

Additional context

No response

包信息


{
  "name": "cloud",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "@antv/x6": "^2.1.1",
    "@antv/x6-plugin-dnd": "^2.0.3",
    "@antv/x6-plugin-snapline": "^2.1.6",
    "@antv/x6-plugin-stencil": "^2.0.2",
    "@antv/x6-vue-shape": "^2.0.7",
    "@antv/xflow": "^1.0.52",
    "@element-plus/icons-vue": "^2.0.10",
    "af-table-column": "^1.0.3",
    "axios": "^1.2.1",
    "core-js": "^3.8.3",
    "echarts": "^5.4.1",
    "element-plus": "^2.2.27",
    "less": "^4.1.3",
    "pinia": "^2.0.28",
    "screenfull": "^6.0.2",
    "three": "^0.147.0",
    "vanta": "^0.5.24",
    "vue": "^3.2.45",
    "vue-router": "^4.1.6",
    "vuedraggable": "next"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^4.0.0",
    "typescript": "^4.9.3",
    "vite": "^4.0.0",
    "vue-tsc": "^1.0.11"
  }
}

@x6-bot x6-bot bot added the bug label Dec 21, 2022
@x6-bot
Copy link
Contributor

x6-bot bot commented Dec 21, 2022

👋 @xkkjiayou

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@xkkjiayou
Copy link
Author

xkkjiayou commented Dec 21, 2022 via email

@lloydzhou

This comment was marked as off-topic.

@NewByVector
Copy link
Contributor

我本地试了一下,demo 能完整跑起来,并没有报错,这个先关闭了,如果可以提供一个可以复现的项目,请重新提一个 issue。

@panzhengtao
Copy link

2.0 版本官方文档,参考stencil插件提供的示例,复制源码到项目里面打开就有这个问题

我本地试了一下,demo 能完整跑起来,并没有报错,这个先关闭了,如果可以提供一个可以复现的项目,请重新提一个 issue。

@xkkjiayou
Copy link
Author

xkkjiayou commented Feb 8, 2023 via email

@Hemomoo
Copy link

Hemomoo commented Jul 8, 2023

2.0 版本官方文档,参考stencil插件提供的示例,复制源码到项目里面打开就有这个问题

我本地试了一下,demo 能完整跑起来,并没有报错,这个先关闭了,如果可以提供一个可以复现的项目,请重新提一个 issue。

你好 这个问题您解决了吗? 我也遇到了同样的问题

@x6-bot
Copy link
Contributor

x6-bot bot commented Jul 8, 2024

This thread has been automatically locked because it has not had recent activity.

Please open a new issue for related bugs and link to relevant comments in this thread.

@x6-bot x6-bot bot locked as resolved and limited conversation to collaborators Jul 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants