From 6a81805075959528572769a54dfb043200ea2a4e Mon Sep 17 00:00:00 2001 From: vector Date: Tue, 29 Nov 2022 21:22:49 +0800 Subject: [PATCH] fix: render react shape in dnd graph (#2970) --- packages/x6-plugin-snapline/src/index.ts | 4 +++- packages/x6-plugin-snapline/src/snapline.ts | 2 +- packages/x6-react-shape/src/view.ts | 5 ++++- packages/x6/src/renderer/queueJob.ts | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/x6-plugin-snapline/src/index.ts b/packages/x6-plugin-snapline/src/index.ts index 8c0a16cf373..e76d508c16e 100644 --- a/packages/x6-plugin-snapline/src/index.ts +++ b/packages/x6-plugin-snapline/src/index.ts @@ -5,10 +5,12 @@ import './api' export class Snapline extends Disposable { private snaplineImpl: SnaplineImpl + public options: Snapline.Options public name = 'snapline' - constructor(public readonly options: Snapline.Options) { + constructor(options: Snapline.Options) { super() + this.options = { tolerance: 10, ...options } CssLoader.ensure(this.name, content) } diff --git a/packages/x6-plugin-snapline/src/snapline.ts b/packages/x6-plugin-snapline/src/snapline.ts index 0acbd98a8b6..90f618dbb0d 100644 --- a/packages/x6-plugin-snapline/src/snapline.ts +++ b/packages/x6-plugin-snapline/src/snapline.ts @@ -47,7 +47,7 @@ export class SnaplineImpl extends View implements IDisablable { const { graph, ...others } = options this.graph = graph - this.options = { tolerance: 10, ...others } + this.options = { ...others } this.offset = { x: 0, y: 0 } this.render() if (!this.disabled) { diff --git a/packages/x6-react-shape/src/view.ts b/packages/x6-react-shape/src/view.ts index 284b2524c5b..3227ad56f11 100644 --- a/packages/x6-react-shape/src/view.ts +++ b/packages/x6-react-shape/src/view.ts @@ -29,7 +29,10 @@ export class ReactShapeView extends NodeView { const node = this.cell if (container) { - const elem = React.createElement(Wrap, { node, graph: node.model!.graph }) + const graph = node.model ? node.model.graph : null + // Actually in the dnd plugin, this graph is empty, + // in order to make the external perception type of graph is a graph, rather than graph | null, so hack this. + const elem = React.createElement(Wrap, { node, graph: graph! }) if (Portal.isActive()) { const portal = createPortal(elem, container) as ReactPortal Portal.connect(this.cell.id, portal) diff --git a/packages/x6/src/renderer/queueJob.ts b/packages/x6/src/renderer/queueJob.ts index 7e7624c05ad..96c964adc9f 100644 --- a/packages/x6/src/renderer/queueJob.ts +++ b/packages/x6/src/renderer/queueJob.ts @@ -72,7 +72,8 @@ export class JobQueue { try { job.cb() } catch (error) { - // pass + // eslint-disable-next-line + console.log(error) } }