From 48a59f54a92f171473678d52f2cf902b80e17a57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BD=A0=E6=8D=89=E4=B8=8D=E5=88=B0=E7=9A=84this?=
<2228429150@qq.com>
Date: Sun, 28 Jan 2024 11:16:20 +0800
Subject: [PATCH] fix: update xflow components demo
---
.../src/xflow/components/clipboard/index.tsx | 135 +---------
.../xflow/components/clipboard/setting.tsx | 125 ++++++++++
.../src/xflow/components/control/index.tsx | 144 +----------
.../src/xflow/components/control/setting.tsx | 135 ++++++++++
.../src/xflow/components/graph/index.tsx | 212 +---------------
.../src/xflow/components/graph/ports.ts | 54 ++++
.../src/xflow/components/graph/setting.tsx | 156 ++++++++++++
.../src/xflow/components/history/header.tsx | 51 ++++
.../src/xflow/components/history/index.tsx | 61 +----
.../src/xflow/components/minimap/header.tsx | 54 ++++
.../src/xflow/components/minimap/index.tsx | 64 +----
.../src/xflow/components/snapline/index.tsx | 150 +----------
.../src/xflow/components/snapline/setting.tsx | 140 +++++++++++
.../src/xflow/components/transform/index.tsx | 234 +-----------------
.../xflow/components/transform/setting.tsx | 225 +++++++++++++++++
15 files changed, 962 insertions(+), 978 deletions(-)
create mode 100644 sites/x6-sites/src/xflow/components/clipboard/setting.tsx
create mode 100644 sites/x6-sites/src/xflow/components/control/setting.tsx
create mode 100644 sites/x6-sites/src/xflow/components/graph/ports.ts
create mode 100644 sites/x6-sites/src/xflow/components/history/header.tsx
create mode 100644 sites/x6-sites/src/xflow/components/minimap/header.tsx
create mode 100644 sites/x6-sites/src/xflow/components/snapline/setting.tsx
create mode 100644 sites/x6-sites/src/xflow/components/transform/setting.tsx
diff --git a/sites/x6-sites/src/xflow/components/clipboard/index.tsx b/sites/x6-sites/src/xflow/components/clipboard/index.tsx
index a63213ab7a3..ca7b935b706 100644
--- a/sites/x6-sites/src/xflow/components/clipboard/index.tsx
+++ b/sites/x6-sites/src/xflow/components/clipboard/index.tsx
@@ -1,13 +1,6 @@
-import {
- XFlow,
- XFlowGraph,
- Background,
- useGraphStore,
- useClipboard,
- Clipboard,
-} from '@antv/xflow'
-import React, { useEffect, useState, useCallback } from 'react'
-import { Card, Row, Col, Slider, Checkbox, Button, Badge } from 'antd'
+import { XFlow, XFlowGraph, Background, Clipboard } from '@antv/xflow'
+import React, { useState } from 'react'
+import { Setting } from './setting'
import './index.less'
const Page = () => {
@@ -30,125 +23,3 @@ const Page = () => {
}
export default Page
-
-const Setting = (props) => {
- const initData = useGraphStore((state) => state.initData)
-
- const setInitData = useCallback(() => {
- initData({
- nodes: [
- {
- id: '1',
- x: 32,
- y: 32,
- width: 100,
- height: 40,
- label: 'Hello',
- attrs: {
- body: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- fill: '#fff',
- rx: 6,
- ry: 6,
- },
- },
- },
- {
- id: '2',
- shape: 'circle',
- x: 160,
- y: 180,
- width: 60,
- height: 60,
- label: 'World',
- attrs: {
- body: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- fill: '#fff',
- },
- },
- },
- ],
- edges: [
- {
- source: '1',
- target: '2',
- attrs: {
- line: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- },
- },
- },
- ],
- })
- }, [initData])
-
- useEffect(() => {
- setInitData()
- }, [setInitData])
- const [offset, setOffset] = useState(30)
- const nodes = useGraphStore((state) => state.nodes)
- const { copy, paste } = useClipboard()
-
- const onCopy = () => {
- const selected = nodes.filter((node) => node.selected)
- const ids: string[] = selected.map((node) => node.id || '')
- copy(ids)
- }
-
- const onPaste = () => {
- paste({ offset })
- }
-
- return (
-
diff --git a/sites/x6-sites/src/xflow/components/minimap/header.tsx b/sites/x6-sites/src/xflow/components/minimap/header.tsx
new file mode 100644
index 00000000000..aa77377cbfa
--- /dev/null
+++ b/sites/x6-sites/src/xflow/components/minimap/header.tsx
@@ -0,0 +1,54 @@
+import { useGraphStore } from '@antv/xflow'
+import React, { useEffect, useCallback } from 'react'
+import { Segmented } from 'antd'
+
+export const SegmentedHeader = ({ setOptions }) => {
+ const initData = useGraphStore((state) => state.initData)
+ const setInitData = useCallback(() => {
+ initData({
+ nodes: [
+ {
+ id: '1',
+ shape: 'rect',
+ x: 200,
+ y: 100,
+ width: 100,
+ height: 40,
+ attrs: {
+ body: {
+ stroke: '#8f8f8f',
+ strokeWidth: 1,
+ fill: '#fff',
+ rx: 6,
+ ry: 6,
+ },
+ },
+ label: 'move',
+ },
+ ],
+ edges: [],
+ })
+ }, [initData])
+
+ useEffect(() => {
+ setInitData()
+ }, [setInitData])
+
+ return (
+
+ setOptions((prev) => ({ ...prev, simple: value }))}
+ />
+
+ )
+}
diff --git a/sites/x6-sites/src/xflow/components/minimap/index.tsx b/sites/x6-sites/src/xflow/components/minimap/index.tsx
index 5c38b2af67c..20be617f67c 100644
--- a/sites/x6-sites/src/xflow/components/minimap/index.tsx
+++ b/sites/x6-sites/src/xflow/components/minimap/index.tsx
@@ -1,64 +1,8 @@
-import {
- XFlow,
- XFlowGraph,
- Background,
- useGraphStore,
- Minimap,
-} from '@antv/xflow'
-import React, { useEffect, useState, useCallback } from 'react'
-import { Segmented } from 'antd'
-import './index.less'
-
-const SegmentedHeader = ({ setOptions }) => {
- const initData = useGraphStore((state) => state.initData)
- const setInitData = useCallback(() => {
- initData({
- nodes: [
- {
- id: '1',
- shape: 'rect',
- x: 200,
- y: 100,
- width: 100,
- height: 40,
- attrs: {
- body: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- fill: '#fff',
- rx: 6,
- ry: 6,
- },
- },
- label: 'move',
- },
- ],
- edges: [],
- })
- }, [initData])
+import { XFlow, XFlowGraph, Background, Minimap } from '@antv/xflow'
+import React, { useState } from 'react'
+import { SegmentedHeader } from './header'
- useEffect(() => {
- setInitData()
- }, [setInitData])
-
- return (
-
- setOptions((prev) => ({ ...prev, simple: value }))}
- />
-
- )
-}
+import './index.less'
const Page = () => {
const [options, setOptions] = useState({
diff --git a/sites/x6-sites/src/xflow/components/snapline/index.tsx b/sites/x6-sites/src/xflow/components/snapline/index.tsx
index c08f2c3acbb..3e7f2b08a32 100644
--- a/sites/x6-sites/src/xflow/components/snapline/index.tsx
+++ b/sites/x6-sites/src/xflow/components/snapline/index.tsx
@@ -1,13 +1,6 @@
-import {
- XFlow,
- XFlowGraph,
- Background,
- Snapline,
- useGraphStore,
- Transform,
-} from '@antv/xflow'
-import React, { useEffect, useState, useCallback } from 'react'
-import { Card, Row, Col, Slider, Checkbox, Badge } from 'antd'
+import { XFlow, XFlowGraph, Background, Snapline, Transform } from '@antv/xflow'
+import React, { useState } from 'react'
+import { Setting } from './setting'
import './index.less'
const Page = () => {
@@ -31,140 +24,3 @@ const Page = () => {
}
export default Page
-
-const Setting = ({ setOptions, options }) => {
- const initData = useGraphStore((state) => state.initData)
- const setInitData = useCallback(() => {
- initData({
- nodes: [
- {
- id: '1',
- x: 32,
- y: 32,
- width: 100,
- height: 40,
- label: 'Hello',
- attrs: {
- body: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- fill: '#fff',
- rx: 6,
- ry: 6,
- },
- },
- },
- {
- id: '2',
- shape: 'circle',
- x: 160,
- y: 180,
- width: 60,
- height: 60,
- label: 'World',
- attrs: {
- body: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- fill: '#fff',
- },
- },
- },
- {
- id: '3',
- x: 200,
- y: 100,
- width: 100,
- height: 40,
- label: 'Drag Me',
- attrs: {
- body: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- fill: '#fff',
- rx: 6,
- ry: 6,
- },
- },
- },
- ],
- edges: [
- {
- source: '1',
- target: '2',
- attrs: {
- line: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- },
- },
- },
- ],
- })
- }, [initData])
- useEffect(() => {
- setInitData()
- }, [setInitData])
-
- return (
-
-
-
- Tolerance
-
-
-
-
-
-
-
- setOptions((prev) => ({ ...prev, tolerance: value }))
- }
- />
-
-
-
-
-
- setOptions((prev) => ({ ...prev, sharp: e.target.checked }))
- }
- >
- Sharp Line
-
-
-
-
-
-
- setOptions((prev) => ({ ...prev, resizing: e.target.checked }))
- }
- >
- Snap on Resizing
-
-
-
-
-
-
- setOptions((prev) => ({
- ...prev,
- filter: e.target.checked ? ['circle'] : undefined,
- }))
- }
- >
- Add Filter(only circle)
-
-
-
-
-
- )
-}
diff --git a/sites/x6-sites/src/xflow/components/snapline/setting.tsx b/sites/x6-sites/src/xflow/components/snapline/setting.tsx
new file mode 100644
index 00000000000..f4d8ec27c50
--- /dev/null
+++ b/sites/x6-sites/src/xflow/components/snapline/setting.tsx
@@ -0,0 +1,140 @@
+import { useGraphStore } from '@antv/xflow'
+import React, { useEffect, useCallback } from 'react'
+import { Card, Row, Col, Slider, Checkbox, Badge } from 'antd'
+
+export const Setting = ({ setOptions, options }) => {
+ const initData = useGraphStore((state) => state.initData)
+ const setInitData = useCallback(() => {
+ initData({
+ nodes: [
+ {
+ id: '1',
+ x: 32,
+ y: 32,
+ width: 100,
+ height: 40,
+ label: 'Hello',
+ attrs: {
+ body: {
+ stroke: '#8f8f8f',
+ strokeWidth: 1,
+ fill: '#fff',
+ rx: 6,
+ ry: 6,
+ },
+ },
+ },
+ {
+ id: '2',
+ shape: 'circle',
+ x: 160,
+ y: 180,
+ width: 60,
+ height: 60,
+ label: 'World',
+ attrs: {
+ body: {
+ stroke: '#8f8f8f',
+ strokeWidth: 1,
+ fill: '#fff',
+ },
+ },
+ },
+ {
+ id: '3',
+ x: 200,
+ y: 100,
+ width: 100,
+ height: 40,
+ label: 'Drag Me',
+ attrs: {
+ body: {
+ stroke: '#8f8f8f',
+ strokeWidth: 1,
+ fill: '#fff',
+ rx: 6,
+ ry: 6,
+ },
+ },
+ },
+ ],
+ edges: [
+ {
+ source: '1',
+ target: '2',
+ attrs: {
+ line: {
+ stroke: '#8f8f8f',
+ strokeWidth: 1,
+ },
+ },
+ },
+ ],
+ })
+ }, [initData])
+ useEffect(() => {
+ setInitData()
+ }, [setInitData])
+
+ return (
+
+
+
+ Tolerance
+
+
+
+
+
+
+
+ setOptions((prev) => ({ ...prev, tolerance: value }))
+ }
+ />
+
+
+
+
+
+ setOptions((prev) => ({ ...prev, sharp: e.target.checked }))
+ }
+ >
+ Sharp Line
+
+
+
+
+
+
+ setOptions((prev) => ({ ...prev, resizing: e.target.checked }))
+ }
+ >
+ Snap on Resizing
+
+
+
+
+
+
+ setOptions((prev) => ({
+ ...prev,
+ filter: e.target.checked ? ['circle'] : undefined,
+ }))
+ }
+ >
+ Add Filter(only circle)
+
+
+
+
+
+ )
+}
diff --git a/sites/x6-sites/src/xflow/components/transform/index.tsx b/sites/x6-sites/src/xflow/components/transform/index.tsx
index 0c7fff8fb68..fd4e6400d03 100644
--- a/sites/x6-sites/src/xflow/components/transform/index.tsx
+++ b/sites/x6-sites/src/xflow/components/transform/index.tsx
@@ -1,12 +1,6 @@
-import {
- XFlow,
- XFlowGraph,
- Background,
- useGraphStore,
- Transform,
-} from '@antv/xflow'
-import React, { useEffect, useState, useCallback } from 'react'
-import { Card, Row, Col, Slider, Checkbox, Badge } from 'antd'
+import { XFlow, XFlowGraph, Background, Transform } from '@antv/xflow'
+import React, { useState } from 'react'
+import { Setting } from './setting'
import './index.less'
const Page = () => {
@@ -29,225 +23,3 @@ const Page = () => {
}
export default Page
-
-const Setting = ({ setOptions, options }) => {
- const initData = useGraphStore((state) => state.initData)
-
- const setInitData = useCallback(() => {
- initData({
- nodes: [
- {
- id: '1',
- x: 32,
- y: 32,
- width: 100,
- height: 40,
- label: 'Hello',
- attrs: {
- body: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- fill: '#fff',
- rx: 6,
- ry: 6,
- },
- },
- },
- {
- id: '2',
- shape: 'circle',
- x: 160,
- y: 180,
- width: 60,
- height: 60,
- label: 'World',
- attrs: {
- body: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- fill: '#fff',
- },
- },
- },
- ],
- edges: [
- {
- source: '1',
- target: '2',
- attrs: {
- line: {
- stroke: '#8f8f8f',
- strokeWidth: 1,
- },
- },
- },
- ],
- })
- }, [initData])
-
- useEffect(() => {
- setInitData()
- }, [setInitData])
-
- return (
-
-
-
-
-
- setOptions((prev) => ({
- ...prev,
- resizing: { ...prev.resizing, enabled: e.target.checked },
- }))
- }
- >
- resizing
-
-
-
-
- minWidth
-
-
- setOptions((prev) => ({
- ...prev,
- resizing: { ...prev.resizing, minWidth: value },
- }))
- }
- />
-
-
-
-
-
-
-
- maxWidth
-
-
- setOptions((prev) => ({
- ...prev,
- resizing: { ...prev.resizing, maxWidth: value },
- }))
- }
- />
-
-
-
-
-
-
- minHeight
-
-
- setOptions((prev) => ({
- ...prev,
- resizing: { ...prev.resizing, minHeight: value },
- }))
- }
- />
-
-
-
-
-
-
-
- maxHeight
-
-
- setOptions((prev) => ({
- ...prev,
- resizing: { ...prev.resizing, maxHeight: value },
- }))
- }
- />
-
-
-
-
-
-
-
-
- setOptions((prev) => ({
- ...prev,
- rotating: { ...prev.rotating, enabled: e.target.checked },
- }))
- }
- >
- rotating
-
-
-
-
- grid
-
-
- setOptions((prev) => ({
- ...prev,
- rotating: { ...prev.rotating, grid: value },
- }))
- }
- />
-
-
-
-
-
-
-
- )
-}
diff --git a/sites/x6-sites/src/xflow/components/transform/setting.tsx b/sites/x6-sites/src/xflow/components/transform/setting.tsx
new file mode 100644
index 00000000000..b135bd1e7f6
--- /dev/null
+++ b/sites/x6-sites/src/xflow/components/transform/setting.tsx
@@ -0,0 +1,225 @@
+import React, { useEffect, useCallback } from 'react'
+import { useGraphStore } from '@antv/xflow'
+import { Card, Row, Col, Slider, Checkbox, Badge } from 'antd'
+
+export const Setting = ({ setOptions, options }) => {
+ const initData = useGraphStore((state) => state.initData)
+
+ const setInitData = useCallback(() => {
+ initData({
+ nodes: [
+ {
+ id: '1',
+ x: 32,
+ y: 32,
+ width: 100,
+ height: 40,
+ label: 'Hello',
+ attrs: {
+ body: {
+ stroke: '#8f8f8f',
+ strokeWidth: 1,
+ fill: '#fff',
+ rx: 6,
+ ry: 6,
+ },
+ },
+ },
+ {
+ id: '2',
+ shape: 'circle',
+ x: 160,
+ y: 180,
+ width: 60,
+ height: 60,
+ label: 'World',
+ attrs: {
+ body: {
+ stroke: '#8f8f8f',
+ strokeWidth: 1,
+ fill: '#fff',
+ },
+ },
+ },
+ ],
+ edges: [
+ {
+ source: '1',
+ target: '2',
+ attrs: {
+ line: {
+ stroke: '#8f8f8f',
+ strokeWidth: 1,
+ },
+ },
+ },
+ ],
+ })
+ }, [initData])
+
+ useEffect(() => {
+ setInitData()
+ }, [setInitData])
+
+ return (
+
+
+
+
+
+ setOptions((prev) => ({
+ ...prev,
+ resizing: { ...prev.resizing, enabled: e.target.checked },
+ }))
+ }
+ >
+ resizing
+
+
+
+
+ minWidth
+
+
+ setOptions((prev) => ({
+ ...prev,
+ resizing: { ...prev.resizing, minWidth: value },
+ }))
+ }
+ />
+
+
+
+
+
+
+
+ maxWidth
+
+
+ setOptions((prev) => ({
+ ...prev,
+ resizing: { ...prev.resizing, maxWidth: value },
+ }))
+ }
+ />
+
+
+
+
+
+
+ minHeight
+
+
+ setOptions((prev) => ({
+ ...prev,
+ resizing: { ...prev.resizing, minHeight: value },
+ }))
+ }
+ />
+
+
+
+
+
+
+
+ maxHeight
+
+
+ setOptions((prev) => ({
+ ...prev,
+ resizing: { ...prev.resizing, maxHeight: value },
+ }))
+ }
+ />
+
+
+
+
+
+
+
+
+ setOptions((prev) => ({
+ ...prev,
+ rotating: { ...prev.rotating, enabled: e.target.checked },
+ }))
+ }
+ >
+ rotating
+
+
+
+
+ grid
+
+
+ setOptions((prev) => ({
+ ...prev,
+ rotating: { ...prev.rotating, grid: value },
+ }))
+ }
+ />
+
+
+
+
+
+
+
+ )
+}