diff --git a/sites/x6-sites/docs/xflow/components/background.md b/sites/x6-sites/docs/xflow/components/background.md index cf8196c4fc0..c2c2ce1ac2a 100644 --- a/sites/x6-sites/docs/xflow/components/background.md +++ b/sites/x6-sites/docs/xflow/components/background.md @@ -1,6 +1,6 @@ --- title: Background 背景 -order: 3 +order: 1 redirect_from: - /zh/docs - /zh/docs/xflow diff --git a/sites/x6-sites/docs/xflow/components/clipboard.md b/sites/x6-sites/docs/xflow/components/clipboard.md index 21678c87fab..262e8d7ab41 100644 --- a/sites/x6-sites/docs/xflow/components/clipboard.md +++ b/sites/x6-sites/docs/xflow/components/clipboard.md @@ -1,6 +1,6 @@ --- title: Clipboard 复制粘贴 -order: 5 +order: 3 redirect_from: - /zh/docs - /zh/docs/xflow diff --git a/sites/x6-sites/docs/xflow/components/control.md b/sites/x6-sites/docs/xflow/components/control.md index bf82361612c..0b010aa13b1 100644 --- a/sites/x6-sites/docs/xflow/components/control.md +++ b/sites/x6-sites/docs/xflow/components/control.md @@ -1,6 +1,6 @@ --- title: Control 控制器 -order: 10 +order: 8 redirect_from: - /zh/docs - /zh/docs/xflow diff --git a/sites/x6-sites/docs/xflow/components/graph.md b/sites/x6-sites/docs/xflow/components/graph.md index c4360b32010..1c195b53c89 100644 --- a/sites/x6-sites/docs/xflow/components/graph.md +++ b/sites/x6-sites/docs/xflow/components/graph.md @@ -1,6 +1,6 @@ --- title: XFlowGraph 画布 -order: 2 +order: 0 redirect_from: - /zh/docs - /zh/docs/xflow diff --git a/sites/x6-sites/docs/xflow/components/grid.md b/sites/x6-sites/docs/xflow/components/grid.md index 1c98a21ae58..44cff63c5f0 100644 --- a/sites/x6-sites/docs/xflow/components/grid.md +++ b/sites/x6-sites/docs/xflow/components/grid.md @@ -1,6 +1,6 @@ --- title: Grid 网格 -order: 4 +order: 2 redirect_from: - /zh/docs - /zh/docs/xflow diff --git a/sites/x6-sites/docs/xflow/components/history.md b/sites/x6-sites/docs/xflow/components/history.md index 45cc67cf35d..ebe535f377b 100644 --- a/sites/x6-sites/docs/xflow/components/history.md +++ b/sites/x6-sites/docs/xflow/components/history.md @@ -1,6 +1,6 @@ --- title: History 撤销重做 -order: 6 +order: 4 redirect_from: - /zh/docs - /zh/docs/xflow diff --git a/sites/x6-sites/docs/xflow/components/minimap.md b/sites/x6-sites/docs/xflow/components/minimap.md index 06729f1045d..0ff86c2a03a 100644 --- a/sites/x6-sites/docs/xflow/components/minimap.md +++ b/sites/x6-sites/docs/xflow/components/minimap.md @@ -1,6 +1,6 @@ --- title: Minimap 小地图 -order: 7 +order: 5 redirect_from: - /zh/docs - /zh/docs/xflow diff --git a/sites/x6-sites/docs/xflow/components/snapline.md b/sites/x6-sites/docs/xflow/components/snapline.md index 18414de2b9e..5c80267b983 100644 --- a/sites/x6-sites/docs/xflow/components/snapline.md +++ b/sites/x6-sites/docs/xflow/components/snapline.md @@ -1,6 +1,6 @@ --- title: Snapline 对齐线 -order: 8 +order: 6 redirect_from: - /zh/docs - /zh/docs/xflow diff --git a/sites/x6-sites/docs/xflow/components/transform.md b/sites/x6-sites/docs/xflow/components/transform.md index f3a8f5504a1..ca6bc68546b 100644 --- a/sites/x6-sites/docs/xflow/components/transform.md +++ b/sites/x6-sites/docs/xflow/components/transform.md @@ -1,6 +1,6 @@ --- title: Transform 图形变换 -order: 9 +order: 7 redirect_from: - /zh/docs - /zh/docs/xflow diff --git a/sites/x6-sites/docs/xflow/components/wrapper.md b/sites/x6-sites/docs/xflow/components/wrapper.md deleted file mode 100644 index 2dd5f12d161..00000000000 --- a/sites/x6-sites/docs/xflow/components/wrapper.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: Wrapper 包裹组件 -order: 1 -redirect_from: - - /zh/docs - - /zh/docs/xflow - - /zh/docs/xflow/components ---- - -画布包裹组件, 只有当画布实例存在的时候,才去渲染 `children` - -## 基础用法 - -```tsx - - {children} - -``` - -## API - -### Wrapper - -| 参数名 | 描述 | 类型 | 默认值 | -|--------|------|------|-------| -| children| 渲染元素 | ReactNode | - | diff --git a/sites/x6-sites/docs/xflow/components/xflow.md b/sites/x6-sites/docs/xflow/components/xflow.md deleted file mode 100644 index 4facca55dde..00000000000 --- a/sites/x6-sites/docs/xflow/components/xflow.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: XFlow 根组件 -order: 0 -redirect_from: -- /zh/docs -- /zh/docs/xflow -- /zh/docs/xflow/components ---- - -XFlow 的根组件,提供画布消费上下文的默认环境。 - -## 基础用法 - -```tsx - - {children} - -``` - -## API - -### XFlow - -| 参数名 | 描述 | 类型 | 默认值 | -|--------|------|------|-------| -| children| 渲染元素 | ReactNode | - | diff --git a/sites/x6-sites/docs/xflow/guide/quick-start.md b/sites/x6-sites/docs/xflow/guide/quick-start.md index 1bda6aab3e2..e7f6a8c599d 100644 --- a/sites/x6-sites/docs/xflow/guide/quick-start.md +++ b/sites/x6-sites/docs/xflow/guide/quick-start.md @@ -29,22 +29,6 @@ $ yarn add @antv/xflow $ pnpm add @antv/xflow ``` -## 通过 CDN - -你可以借助 script 标签直接通过 CDN 来使用 XFlow: - -```html - -``` - -这里我们使用了 [unpkg](https://unpkg.com/@antv/xflow/dist/index.umd.js),但你也可以使用任何提供 npm 包服务的 CDN,例如 [jsdelivr](https://cdn.jsdelivr.net/npm/@antv/xflow/dist/index.umd.js)。当然你也可以下载此文件并自行提供服务。 - -对于生产环境, 我们推荐使用一个明确的版本号, 以避免新版本升级造成不可预期的破坏, 例如: - -- - -- - # 基础使用 接下来我们就一起使用 XFlow 来构建一个简单的图形应用,来体验一下 XFlow 的魅力吧。 diff --git a/sites/x6-sites/docs/xflow/store.md b/sites/x6-sites/docs/xflow/store.md index d41ef8e5476..58487f3ea4b 100644 --- a/sites/x6-sites/docs/xflow/store.md +++ b/sites/x6-sites/docs/xflow/store.md @@ -80,9 +80,3 @@ xflow 对画布的数据进行了统一的管理,整个画布的数据存在 - `id`:要更新的边的ID。 - `data`:一个对象或者一个函数,包含要更新的数据。 - `options`:一个可选的对象。当`{ silent: true }`时,更新操作不会被记录在变动列表中。 - -## 变动列表操作 - -### `clearChangeList()` - -清空变动列表`changeList`,这个列表记录了所有非静默(非silent)的操作。 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 ( -
- - - Paste Offset - - - - - - - setOffset(value)} - /> - - - - - props.setLocalStorage(e.target.checked)} - > - useLocalStorage - - - - - - - - - - - - -
- ) -} diff --git a/sites/x6-sites/src/xflow/components/clipboard/setting.tsx b/sites/x6-sites/src/xflow/components/clipboard/setting.tsx new file mode 100644 index 00000000000..ee0fa8c1185 --- /dev/null +++ b/sites/x6-sites/src/xflow/components/clipboard/setting.tsx @@ -0,0 +1,125 @@ +import { useGraphStore, useClipboard } from '@antv/xflow' +import React, { useEffect, useState, useCallback } from 'react' +import { Card, Row, Col, Slider, Checkbox, Button, Badge } from 'antd' + +export 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 ( +
+ + + Paste Offset + + + + + + + setOffset(value)} + /> + + + + + props.setLocalStorage(e.target.checked)} + > + useLocalStorage + + + + + + + + + + + + +
+ ) +} diff --git a/sites/x6-sites/src/xflow/components/control/index.tsx b/sites/x6-sites/src/xflow/components/control/index.tsx index 916546bba89..8d5bb935e7d 100644 --- a/sites/x6-sites/src/xflow/components/control/index.tsx +++ b/sites/x6-sites/src/xflow/components/control/index.tsx @@ -1,12 +1,6 @@ -import { - XFlow, - XFlowGraph, - Background, - useGraphStore, - Control, -} from '@antv/xflow' -import React, { useEffect, useState, useCallback } from 'react' -import { Card, Row, Col, Segmented, Select } from 'antd' +import { XFlow, XFlowGraph, Background, Control } from '@antv/xflow' +import React, { useState } from 'react' +import { Setting } from './setting' import './index.less' const Page = () => { @@ -47,135 +41,3 @@ const Page = () => { } export default Page - -const Setting = ({ setOptions }) => { - 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 controlItems = [ - 'zoomOut', - 'zoomTo', - 'zoomIn', - 'zoomToFit', - 'zoomToOrigin', - ] - const selectOptions = controlItems.map((item) => ({ - label: item, - value: item, - })) - - return ( -
- - - - - setOptions((prev) => ({ ...prev, direction: value })) - } - /> - - - Tooltip - - - - setOptions((prev) => ({ ...prev, placement: value })) - } - /> - - - - Options - - + setOptions((prev) => ({ ...prev, items: value })) + } + options={selectOptions} + /> + + + +
+ ) +} diff --git a/sites/x6-sites/src/xflow/components/graph/index.tsx b/sites/x6-sites/src/xflow/components/graph/index.tsx index 862529be849..06433e8dda2 100644 --- a/sites/x6-sites/src/xflow/components/graph/index.tsx +++ b/sites/x6-sites/src/xflow/components/graph/index.tsx @@ -1,6 +1,6 @@ -import { XFlow, XFlowGraph, Background, useGraphStore } from '@antv/xflow' -import React, { useEffect, useState, useCallback } from 'react' -import { Card, Row, Col, Checkbox } from 'antd' +import { XFlow, XFlowGraph, Background } from '@antv/xflow' +import React, { useState } from 'react' +import { Setting } from './setting' import './index.less' const Page = () => { @@ -77,209 +77,3 @@ const Page = () => { } export default Page - -const ports = { - groups: { - group1: { - position: 'top', - attrs: { - circle: { - stroke: '#D06269', - strokeWidth: 1, - r: 4, - magnet: true, - }, - }, - }, - group2: { - position: 'right', - attrs: { - circle: { - stroke: '#D06269', - strokeWidth: 1, - r: 4, - magnet: true, - }, - }, - }, - group3: { - position: 'bottom', - attrs: { - circle: { - stroke: '#D06269', - strokeWidth: 1, - r: 4, - magnet: true, - }, - }, - }, - group4: { - position: 'left', - attrs: { - circle: { - stroke: '#D06269', - strokeWidth: 1, - r: 4, - magnet: true, - }, - }, - }, - }, - items: [ - { id: 'group1', group: 'group1' }, - { id: 'group2', group: 'group2' }, - { id: 'group3', group: 'group3' }, - { id: 'group4', group: 'group4' }, - ], -} - -const Setting = ({ setOptions }) => { - 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, - }, - }, - ports: { - ...ports, - }, - }, - { - id: '2', - x: 160, - y: 180, - width: 60, - height: 60, - label: 'World', - attrs: { - body: { - stroke: '#8f8f8f', - strokeWidth: 1, - fill: '#fff', - }, - }, - ports: { - ...ports, - }, - }, - { - id: '3', - x: 300, - y: 180, - width: 100, - height: 40, - label: 'Text', - attrs: { - body: { - stroke: '#8f8f8f', - strokeWidth: 1, - fill: '#fff', - }, - }, - ports: { - ...ports, - }, - }, - ], - edges: [ - { - source: { - cell: '1', - port: 'group2', - }, - target: { - cell: '2', - port: 'group1', - }, - attrs: { - line: { - stroke: '#8f8f8f', - strokeWidth: 1, - }, - }, - }, - ], - }) - }, [initData]) - - useEffect(() => { - setInitData() - }, [setInitData]) - - return ( -
- - - - - setOptions((prev) => ({ ...prev, readonly: e.target.checked })) - } - > - readonly - - - - - - - setOptions((prev) => ({ ...prev, zoomable: e.target.checked })) - } - > - zoomable - - - - - - - setOptions((prev) => ({ ...prev, pannable: e.target.checked })) - } - > - pannable - - - - - - - setOptions((prev) => ({ ...prev, embedable: e.target.checked })) - } - > - embedable - - - - - - - setOptions((prev) => ({ ...prev, restrict: e.target.checked })) - } - > - restrict - - - - -
- ) -} diff --git a/sites/x6-sites/src/xflow/components/graph/ports.ts b/sites/x6-sites/src/xflow/components/graph/ports.ts new file mode 100644 index 00000000000..40b86b18c65 --- /dev/null +++ b/sites/x6-sites/src/xflow/components/graph/ports.ts @@ -0,0 +1,54 @@ +export const ports = { + groups: { + group1: { + position: 'top', + attrs: { + circle: { + stroke: '#D06269', + strokeWidth: 1, + r: 4, + magnet: true, + }, + }, + }, + group2: { + position: 'right', + attrs: { + circle: { + stroke: '#D06269', + strokeWidth: 1, + r: 4, + magnet: true, + }, + }, + }, + group3: { + position: 'bottom', + attrs: { + circle: { + stroke: '#D06269', + strokeWidth: 1, + r: 4, + magnet: true, + }, + }, + }, + group4: { + position: 'left', + attrs: { + circle: { + stroke: '#D06269', + strokeWidth: 1, + r: 4, + magnet: true, + }, + }, + }, + }, + items: [ + { id: 'group1', group: 'group1' }, + { id: 'group2', group: 'group2' }, + { id: 'group3', group: 'group3' }, + { id: 'group4', group: 'group4' }, + ], +} diff --git a/sites/x6-sites/src/xflow/components/graph/setting.tsx b/sites/x6-sites/src/xflow/components/graph/setting.tsx new file mode 100644 index 00000000000..e068fbf36ce --- /dev/null +++ b/sites/x6-sites/src/xflow/components/graph/setting.tsx @@ -0,0 +1,156 @@ +import { useGraphStore } from '@antv/xflow' +import React, { useEffect, useCallback } from 'react' +import { Card, Row, Col, Checkbox } from 'antd' + +import { ports } from './ports' + +export const Setting = ({ setOptions }) => { + 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, + }, + }, + ports: { + ...ports, + }, + }, + { + id: '2', + x: 160, + y: 180, + width: 60, + height: 60, + label: 'World', + attrs: { + body: { + stroke: '#8f8f8f', + strokeWidth: 1, + fill: '#fff', + }, + }, + ports: { + ...ports, + }, + }, + { + id: '3', + x: 300, + y: 180, + width: 100, + height: 40, + label: 'Text', + attrs: { + body: { + stroke: '#8f8f8f', + strokeWidth: 1, + fill: '#fff', + }, + }, + ports: { + ...ports, + }, + }, + ], + edges: [ + { + source: { + cell: '1', + port: 'group2', + }, + target: { + cell: '2', + port: 'group1', + }, + attrs: { + line: { + stroke: '#8f8f8f', + strokeWidth: 1, + }, + }, + }, + ], + }) + }, [initData]) + + useEffect(() => { + setInitData() + }, [setInitData]) + + return ( +
+ + + + + setOptions((prev) => ({ ...prev, readonly: e.target.checked })) + } + > + readonly + + + + + + + setOptions((prev) => ({ ...prev, zoomable: e.target.checked })) + } + > + zoomable + + + + + + + setOptions((prev) => ({ ...prev, pannable: e.target.checked })) + } + > + pannable + + + + + + + setOptions((prev) => ({ ...prev, embedable: e.target.checked })) + } + > + embedable + + + + + + + setOptions((prev) => ({ ...prev, restrict: e.target.checked })) + } + > + restrict + + + + +
+ ) +} diff --git a/sites/x6-sites/src/xflow/components/history/header.tsx b/sites/x6-sites/src/xflow/components/history/header.tsx new file mode 100644 index 00000000000..5087794aedc --- /dev/null +++ b/sites/x6-sites/src/xflow/components/history/header.tsx @@ -0,0 +1,51 @@ +import { useGraphStore, useHistory } from '@antv/xflow' +import React, { useEffect, useCallback } from 'react' +import { Button, Space } from 'antd' + +export const HistoryButton = () => { + const { undo, redo, canUndo, canRedo } = useHistory() + 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 ( +
+ + + + +
+ ) +} diff --git a/sites/x6-sites/src/xflow/components/history/index.tsx b/sites/x6-sites/src/xflow/components/history/index.tsx index d481aa4a10c..4f0d4573c13 100644 --- a/sites/x6-sites/src/xflow/components/history/index.tsx +++ b/sites/x6-sites/src/xflow/components/history/index.tsx @@ -1,63 +1,8 @@ -import { - XFlow, - XFlowGraph, - Background, - useGraphStore, - useHistory, - History, -} from '@antv/xflow' -import React, { useEffect, useCallback } from 'react' -import { Button, Space } from 'antd' +import { XFlow, XFlowGraph, Background, History } from '@antv/xflow' +import React from 'react' +import { HistoryButton } from './header' import './index.less' -const HistoryButton = () => { - const { undo, redo, canUndo, canRedo } = useHistory() - 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 ( -
- - - - -
- ) -} - const Page = () => { 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 aedffe88127..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 }, + })) + } + /> + + + + + + +
+ ) +} diff --git a/sites/x6-sites/src/xflow/hooks/use-graph-event/index.tsx b/sites/x6-sites/src/xflow/hooks/use-graph-event/index.tsx index fc1924c3743..ca9396f1fe1 100644 --- a/sites/x6-sites/src/xflow/hooks/use-graph-event/index.tsx +++ b/sites/x6-sites/src/xflow/hooks/use-graph-event/index.tsx @@ -1,64 +1,8 @@ -import { - XFlow, - XFlowGraph, - Background, - useGraphStore, - useGraphEvent, -} from '@antv/xflow' -import React, { useCallback, useEffect } from 'react' +import { XFlow, XFlowGraph, Background } from '@antv/xflow' +import React from 'react' +import { InitNode } from './init-node' import './index.less' -const InitNode = () => { - const addNodes = useGraphStore((state) => state.addNodes) - const updateNode = useGraphStore((state) => state.updateNode) - - useGraphEvent('node:click', ({ node }) => { - const { id } = node - const randomColor = Math.floor(Math.random() * 16777215).toString(16) - const fillColor = `#${randomColor}` - updateNode(id, { - attrs: { - body: { - stroke: '#8f8f8f', - strokeWidth: 1, - fill: fillColor, - rx: 6, - ry: 6, - }, - }, - }) - }) - - const addNodeInit = useCallback(() => { - addNodes([ - { - id: '3', - shape: 'rect', - x: 200, - y: 200, - width: 100, - height: 40, - attrs: { - body: { - stroke: '#8f8f8f', - strokeWidth: 1, - fill: '#fff', - rx: 6, - ry: 6, - }, - }, - label: 'added', - }, - ]) - }, [addNodes]) - - useEffect(() => { - addNodeInit() - }, [addNodeInit]) - - return null -} - const Page = () => { return (
diff --git a/sites/x6-sites/src/xflow/hooks/use-graph-event/init-node.tsx b/sites/x6-sites/src/xflow/hooks/use-graph-event/init-node.tsx new file mode 100644 index 00000000000..f95cc3e72da --- /dev/null +++ b/sites/x6-sites/src/xflow/hooks/use-graph-event/init-node.tsx @@ -0,0 +1,53 @@ +import { useGraphStore, useGraphEvent } from '@antv/xflow' +import { useCallback, useEffect } from 'react' + +export const InitNode = () => { + const addNodes = useGraphStore((state) => state.addNodes) + const updateNode = useGraphStore((state) => state.updateNode) + + useGraphEvent('node:click', ({ node }) => { + const { id } = node + const randomColor = Math.floor(Math.random() * 16777215).toString(16) + const fillColor = `#${randomColor}` + updateNode(id, { + attrs: { + body: { + stroke: '#8f8f8f', + strokeWidth: 1, + fill: fillColor, + rx: 6, + ry: 6, + }, + }, + }) + }) + + const addNodeInit = useCallback(() => { + addNodes([ + { + id: '3', + shape: 'rect', + x: 200, + y: 200, + width: 100, + height: 40, + attrs: { + body: { + stroke: '#8f8f8f', + strokeWidth: 1, + fill: '#fff', + rx: 6, + ry: 6, + }, + }, + label: 'added', + }, + ]) + }, [addNodes]) + + useEffect(() => { + addNodeInit() + }, [addNodeInit]) + + return null +} diff --git a/sites/x6-sites/src/xflow/hooks/use-graph-store/index.tsx b/sites/x6-sites/src/xflow/hooks/use-graph-store/index.tsx index 9bf908b4eed..0f4fc946dc8 100644 --- a/sites/x6-sites/src/xflow/hooks/use-graph-store/index.tsx +++ b/sites/x6-sites/src/xflow/hooks/use-graph-store/index.tsx @@ -1,48 +1,8 @@ -import { XFlow, XFlowGraph, Background, useGraphStore } from '@antv/xflow' +import { XFlow, XFlowGraph, Background } from '@antv/xflow' import React from 'react' -import { Button, Space } from 'antd' -import './index.less' - -const ToolsButton = () => { - const addNodes = useGraphStore((state) => state.addNodes) - const removeNodes = useGraphStore((state) => state.removeNodes) - - const onAddNodes = () => { - addNodes([ - { - id: '3', - shape: 'rect', - x: 200, - y: 100, - width: 100, - height: 40, - attrs: { - body: { - stroke: '#8f8f8f', - strokeWidth: 1, - fill: '#fff', - rx: 6, - ry: 6, - }, - }, - label: 'added', - }, - ]) - } +import { ToolsButton } from './tools-button' - const onRemoveNodes = () => { - removeNodes(['3']) - } - - return ( -
- - - - -
- ) -} +import './index.less' const Page = () => { return ( diff --git a/sites/x6-sites/src/xflow/hooks/use-graph-store/tools-button.tsx b/sites/x6-sites/src/xflow/hooks/use-graph-store/tools-button.tsx new file mode 100644 index 00000000000..bcfb63c22fc --- /dev/null +++ b/sites/x6-sites/src/xflow/hooks/use-graph-store/tools-button.tsx @@ -0,0 +1,46 @@ +import React from 'react' +import { useGraphStore } from '@antv/xflow' +import { Button, Space } from 'antd' + +import './index.less' + +export const ToolsButton = () => { + const addNodes = useGraphStore((state) => state.addNodes) + const removeNodes = useGraphStore((state) => state.removeNodes) + + const onAddNodes = () => { + addNodes([ + { + id: '3', + shape: 'rect', + x: 200, + y: 100, + width: 100, + height: 40, + attrs: { + body: { + stroke: '#8f8f8f', + strokeWidth: 1, + fill: '#fff', + rx: 6, + ry: 6, + }, + }, + label: 'added', + }, + ]) + } + + const onRemoveNodes = () => { + removeNodes(['3']) + } + + return ( +
+ + + + +
+ ) +} diff --git a/sites/x6-sites/src/xflow/hooks/use-key-board/header.tsx b/sites/x6-sites/src/xflow/hooks/use-key-board/header.tsx new file mode 100644 index 00000000000..12dbd677302 --- /dev/null +++ b/sites/x6-sites/src/xflow/hooks/use-key-board/header.tsx @@ -0,0 +1,84 @@ +import { useEffect, useCallback } from 'react' +import { useGraphStore, useClipboard, useKeyboard } from '@antv/xflow' + +export const Header = () => { + const { copy, paste } = useClipboard() + + const addNodes = useGraphStore((state) => state.addNodes) + const addEdges = useGraphStore((state) => state.addEdges) + const nodes = useGraphStore((state) => state.nodes) + + const setAddNodes = useCallback(() => { + addNodes([ + { + id: 'source', + x: 32, + y: 32, + width: 100, + height: 40, + label: 'Hello', + attrs: { + body: { + stroke: '#8f8f8f', + strokeWidth: 1, + fill: '#fff', + rx: 6, + ry: 6, + }, + }, + }, + { + id: 'target', + shape: 'circle', + x: 160, + y: 180, + width: 60, + height: 60, + label: 'World', + attrs: { + body: { + stroke: '#8f8f8f', + strokeWidth: 1, + fill: '#fff', + }, + }, + }, + ]) + }, [addNodes]) + + const setAddEdges = useCallback(() => { + addEdges([ + { + source: 'source', + target: 'target', + attrs: { + line: { + stroke: '#8f8f8f', + strokeWidth: 1, + }, + }, + }, + ]) + }, [addEdges]) + + const onCopy = () => { + const selected = nodes.filter((node) => node.selected) + const ids: string[] = selected.map((node) => node.id || '') + copy(ids) + } + + useKeyboard('ctrl+c', () => { + onCopy() + }) + + useKeyboard('ctrl+v', () => { + paste() + }) + + useEffect(() => { + setAddNodes() + setAddEdges() + }, [setAddEdges, setAddNodes]) + + return null +} diff --git a/sites/x6-sites/src/xflow/hooks/use-key-board/index.tsx b/sites/x6-sites/src/xflow/hooks/use-key-board/index.tsx index 447cfdd55b7..939816ccd5a 100644 --- a/sites/x6-sites/src/xflow/hooks/use-key-board/index.tsx +++ b/sites/x6-sites/src/xflow/hooks/use-key-board/index.tsx @@ -1,13 +1,7 @@ -import { - XFlow, - XFlowGraph, - Background, - useGraphStore, - useClipboard, - useKeyboard, - Clipboard, -} from '@antv/xflow' -import React, { useEffect, useCallback } from 'react' +import { XFlow, XFlowGraph, Background, Clipboard } from '@antv/xflow' +import React from 'react' +import { Header } from './header' + import './index.less' const Page = () => { @@ -23,86 +17,4 @@ const Page = () => { ) } -const Header = () => { - const { copy, paste } = useClipboard() - - const addNodes = useGraphStore((state) => state.addNodes) - const addEdges = useGraphStore((state) => state.addEdges) - const nodes = useGraphStore((state) => state.nodes) - - const setAddNodes = useCallback(() => { - addNodes([ - { - id: 'source', - x: 32, - y: 32, - width: 100, - height: 40, - label: 'Hello', - attrs: { - body: { - stroke: '#8f8f8f', - strokeWidth: 1, - fill: '#fff', - rx: 6, - ry: 6, - }, - }, - }, - { - id: 'target', - shape: 'circle', - x: 160, - y: 180, - width: 60, - height: 60, - label: 'World', - attrs: { - body: { - stroke: '#8f8f8f', - strokeWidth: 1, - fill: '#fff', - }, - }, - }, - ]) - }, [addNodes]) - - const setAddEdges = useCallback(() => { - addEdges([ - { - source: 'source', - target: 'target', - attrs: { - line: { - stroke: '#8f8f8f', - strokeWidth: 1, - }, - }, - }, - ]) - }, [addEdges]) - - const onCopy = () => { - const selected = nodes.filter((node) => node.selected) - const ids: string[] = selected.map((node) => node.id || '') - copy(ids) - } - - useKeyboard('ctrl+c', () => { - onCopy() - }) - - useKeyboard('ctrl+v', () => { - paste() - }) - - useEffect(() => { - setAddNodes() - setAddEdges() - }, [setAddEdges, setAddNodes]) - - return null -} - export default Page