Coder Social home page Coder Social logo

Comments (7)

x6-bot avatar x6-bot commented on June 28, 2024

👋 @fengxiaodong28

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.

from x6.

lloydzhou avatar lloydzhou commented on June 28, 2024

使用 https://www.npmjs.com/package/vue2-teleport 改写一下 https://github.com/antvis/X6/blob/master/packages/x6-vue-shape/src/teleport.ts 或许可以

from x6.

lloydzhou avatar lloydzhou commented on June 28, 2024

如果觉得改写 x6-vue-shape有难度,可以参考https://github.com/lloydzhou/x6-html-shape写一个 vue2-teleport的版本,这个改起来比较简单。

from x6.

fengxiaodong28 avatar fengxiaodong28 commented on June 28, 2024

@lloydzhou 我这里试着改了一下,但是Object.keys(items)拿到的总是个空数组

import { h, reactive, markRaw } from '@vue/composition-api';
import { Fragment } from 'vue-fragment';
import Teleport from 'vue2-teleport';
import type { Graph } from '@antv/x6';
import type { VueShape } from '@antv/x6-vue-shape';
import Vue, { type VueConstructor } from 'vue';

let active = false;
const items = reactive<{ [key: string]: VueConstructor<Vue> }>({});

export function connect(id: string, component: VueConstructor<Vue>, node: VueShape, graph: Graph) {
    if (active) {
        // eslint-disable-next-line vue/one-component-per-file
        const vm = Vue.extend({
            provide: () => ({
                getNode: () => node,
                getGraph: () => graph
            }),
            render: () =>
                h(
                    Teleport,
                    {
                        attrs: {
                            to: '#test-teleport' // 测试
                        }
                    },
                    [
                        h(component, {
                            props: {
                                node,
                                graph
                            }
                        })
                    ]
                )
        });
        items[id] = markRaw(vm);
    }
}

export function disconnect(id: string) {
    if (active) {
        delete items[id];
    }
}

export function isGraphActive() {
    return active;
}

function getVNodes(): Promise<VNode[]> {
    return new Promise(resolve => {
        const VNodes = Object.keys(items).map(id => h(items[id]));
        resolve(VNodes);
    });
}

export async function getTeleport(): Promise<VueConstructor<Vue>> {
    active = true;

    const VNodes = await getVNodes();

    return new Promise(resolve => {
        // eslint-disable-next-line vue/one-component-per-file
        const vm = Vue.extend({
            render: () => h(Fragment, {}, VNodes)
        });
        resolve(vm);
    });
}

from x6.

fengxiaodong28 avatar fengxiaodong28 commented on June 28, 2024

@lloydzhou 另外这里好像不需要自己connet了,因为可以直接拿到shapeMaps ,值和items是一样的,不过在Object.kyes时也是个空的

import  { shapeMaps } from '@antv/x6-vue-shape'

export async function getTeleport(): Promise<VueConstructor<Vue>> {
    return new Promise(resolve => {
        const vm = Vue.extend({
            render: () => h(Fragment, {}, Object.keys(shapeMaps).map(id => h(shapeMaps[id])))
        });
        resolve(vm);
    });
}

from x6.

lloydzhou avatar lloydzhou commented on June 28, 2024

shapeMaps不是vue里面的reactive的变量,只是一个常量。所以在vue里面使用的时候,如果值变化了,组件并不会更新

from x6.

fengxiaodong28 avatar fengxiaodong28 commented on June 28, 2024

@lloydzhou 嗯嗯,后面还是用的items,但是没啥效果,渲染不到teleport上

from x6.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.