@wzyjs/uis 0.3.28 → 0.3.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/advanced/Com2Canvas/index.d.ts +8 -0
- package/dist/advanced/Com2Canvas/index.js +39 -0
- package/dist/advanced/Crud/components/CardList/index.d.ts +2 -0
- package/dist/advanced/Crud/components/CardList/index.js +90 -0
- package/dist/advanced/Crud/components/CreateUpdate/index.d.ts +2 -0
- package/dist/advanced/Crud/components/CreateUpdate/index.js +78 -0
- package/dist/advanced/Crud/components/ListTabs/index.d.ts +8 -0
- package/dist/advanced/Crud/components/ListTabs/index.js +7 -0
- package/dist/advanced/Crud/components/Provider/index.d.ts +7 -0
- package/dist/advanced/Crud/components/Provider/index.js +42 -0
- package/dist/advanced/Crud/components/QuickFilters/index.d.ts +8 -0
- package/dist/advanced/Crud/components/QuickFilters/index.js +20 -0
- package/dist/advanced/Crud/components/Remove/index.d.ts +2 -0
- package/dist/advanced/Crud/components/Remove/index.js +18 -0
- package/dist/advanced/Crud/components/index.d.ts +6 -0
- package/dist/advanced/Crud/components/index.js +6 -0
- package/dist/advanced/Crud/hooks/index.d.ts +5 -0
- package/dist/advanced/Crud/hooks/index.js +5 -0
- package/dist/advanced/Crud/hooks/useColumns.d.ts +11 -0
- package/dist/advanced/Crud/hooks/useColumns.js +111 -0
- package/dist/advanced/Crud/hooks/useList.d.ts +12 -0
- package/dist/advanced/Crud/hooks/useList.js +53 -0
- package/dist/advanced/Crud/hooks/useListFilters.d.ts +11 -0
- package/dist/advanced/Crud/hooks/useListFilters.js +159 -0
- package/dist/advanced/Crud/hooks/useOrderable.d.ts +15 -0
- package/dist/advanced/Crud/hooks/useOrderable.js +75 -0
- package/dist/advanced/Crud/hooks/useRequest.d.ts +13 -0
- package/dist/advanced/Crud/hooks/useRequest.js +27 -0
- package/dist/advanced/Crud/index.d.ts +3 -0
- package/dist/advanced/Crud/index.js +46 -0
- package/dist/advanced/Crud/types/index.d.ts +176 -0
- package/dist/advanced/Crud/types/index.js +1 -0
- package/dist/advanced/Crud/utils/index.d.ts +7 -0
- package/dist/advanced/Crud/utils/index.js +80 -0
- package/dist/advanced/Crud/utils/query.d.ts +3 -0
- package/dist/advanced/Crud/utils/query.js +34 -0
- package/dist/advanced/MindMap/context.d.ts +12 -0
- package/dist/advanced/MindMap/context.js +12 -0
- package/dist/advanced/MindMap/hooks/useAlignmentSnap.d.ts +15 -0
- package/dist/advanced/MindMap/hooks/useAlignmentSnap.js +164 -0
- package/dist/advanced/MindMap/hooks/useCopyPaste.d.ts +11 -0
- package/dist/advanced/MindMap/hooks/useCopyPaste.js +209 -0
- package/dist/advanced/MindMap/hooks/useDropToReparent.d.ts +21 -0
- package/dist/advanced/MindMap/hooks/useDropToReparent.js +216 -0
- package/dist/advanced/MindMap/hooks/useExpandCollapse.d.ts +18 -0
- package/dist/advanced/MindMap/hooks/useExpandCollapse.js +108 -0
- package/dist/advanced/MindMap/hooks/useMoveDescendants.d.ts +12 -0
- package/dist/advanced/MindMap/hooks/useMoveDescendants.js +98 -0
- package/dist/advanced/MindMap/hooks/useUndoRedo.d.ts +14 -0
- package/dist/advanced/MindMap/hooks/useUndoRedo.js +181 -0
- package/dist/advanced/MindMap/index.d.ts +29 -0
- package/dist/advanced/MindMap/index.js +52 -0
- package/dist/advanced/index.d.ts +5 -0
- package/dist/advanced/index.js +5 -0
- package/dist/antd/index.d.ts +6 -0
- package/dist/antd/index.js +5 -0
- package/dist/buttons/ButtonGroup/index.d.ts +8 -0
- package/dist/buttons/ButtonGroup/index.js +13 -0
- package/dist/buttons/ConfirmButton/index.d.ts +5 -0
- package/dist/buttons/ConfirmButton/index.js +9 -0
- package/dist/buttons/CopyButton/index.d.ts +6 -0
- package/dist/buttons/CopyButton/index.js +26 -0
- package/dist/buttons/DrawerButton/index.d.ts +6 -0
- package/dist/buttons/DrawerButton/index.js +13 -0
- package/dist/buttons/ProgressButton/index.css +63 -0
- package/dist/buttons/ProgressButton/index.d.ts +17 -0
- package/dist/buttons/ProgressButton/index.js +31 -0
- package/dist/buttons/SectorButton/index.d.ts +20 -0
- package/dist/buttons/SectorButton/index.js +130 -0
- package/dist/buttons/index.d.ts +6 -0
- package/dist/buttons/index.js +6 -0
- package/dist/display/CodeView/index.d.ts +26 -0
- package/dist/display/CodeView/index.js +60 -0
- package/dist/display/EnumTag/index.d.ts +12 -0
- package/dist/display/EnumTag/index.js +10 -0
- package/dist/display/HtmlDataRenderer/index.d.ts +6 -0
- package/dist/display/HtmlDataRenderer/index.js +15 -0
- package/dist/display/HtmlView/index.d.ts +6 -0
- package/dist/display/HtmlView/index.js +6 -0
- package/dist/display/IframePro/index.d.ts +8 -0
- package/dist/display/IframePro/index.js +24 -0
- package/dist/display/JsonSchemaRenderer/index.d.ts +11 -0
- package/dist/display/JsonSchemaRenderer/index.js +62 -0
- package/dist/display/JsonView/index.d.ts +3 -0
- package/dist/display/JsonView/index.js +7 -0
- package/dist/display/MarkdownView/index.d.ts +7 -0
- package/dist/display/MarkdownView/index.js +80 -0
- package/dist/display/MarkdownView/style.d.ts +1 -0
- package/{src/components/Markdown/style.ts → dist/display/MarkdownView/style.js} +1 -1
- package/dist/display/VideoPro/index.d.ts +9 -0
- package/dist/display/VideoPro/index.js +15 -0
- package/dist/display/index.d.ts +9 -0
- package/dist/display/index.js +9 -0
- package/dist/inputs/CheckboxButton/index.css +22 -0
- package/dist/inputs/CheckboxButton/index.d.ts +12 -0
- package/dist/inputs/CheckboxButton/index.js +9 -0
- package/dist/inputs/DateSwitcher/index.css +10 -0
- package/dist/inputs/DateSwitcher/index.d.ts +8 -0
- package/dist/inputs/DateSwitcher/index.js +29 -0
- package/dist/inputs/FetchSelect/index.d.ts +3 -0
- package/dist/inputs/FetchSelect/index.js +121 -0
- package/dist/inputs/FetchSelect/types.d.ts +33 -0
- package/dist/inputs/FetchSelect/types.js +1 -0
- package/dist/inputs/FetchSelect/utils.d.ts +21 -0
- package/dist/inputs/FetchSelect/utils.js +67 -0
- package/dist/inputs/FileUploader/index.d.ts +22 -0
- package/dist/inputs/FileUploader/index.js +79 -0
- package/dist/inputs/IconSelect/index.d.ts +89 -0
- package/dist/inputs/IconSelect/index.js +54 -0
- package/dist/inputs/ImageUploader/index.d.ts +12 -0
- package/dist/inputs/ImageUploader/index.js +192 -0
- package/dist/inputs/RadioButton/index.d.ts +15 -0
- package/dist/inputs/RadioButton/index.js +11 -0
- package/dist/inputs/RangeInput/index.d.ts +8 -0
- package/dist/inputs/RangeInput/index.js +17 -0
- package/dist/inputs/TextInput/index.d.ts +6 -0
- package/dist/inputs/TextInput/index.js +30 -0
- package/dist/inputs/index.d.ts +9 -0
- package/dist/inputs/index.js +9 -0
- package/dist/layout/DragSort/index.d.ts +16 -0
- package/dist/layout/DragSort/index.js +12 -0
- package/dist/layout/FoldCard/index.d.ts +9 -0
- package/dist/layout/FoldCard/index.js +69 -0
- package/dist/layout/PageBase/index.d.ts +6 -0
- package/dist/layout/PageBase/index.js +6 -0
- package/dist/layout/ResizableGridLayout/index.d.ts +11 -0
- package/dist/layout/ResizableGridLayout/index.js +13 -0
- package/dist/layout/SideMenu/index.d.ts +27 -0
- package/dist/layout/SideMenu/index.js +40 -0
- package/dist/layout/TabsPro/index.d.ts +9 -0
- package/dist/layout/TabsPro/index.js +87 -0
- package/dist/layout/index.d.ts +6 -0
- package/dist/layout/index.js +6 -0
- package/dist/web.d.ts +6 -0
- package/dist/web.js +6 -0
- package/package.json +28 -12
- package/src/antd/form/CheckboxButton/index.module.scss +0 -24
- package/src/antd/form/CheckboxButton/index.tsx +0 -31
- package/src/antd/form/FileUploader/index.tsx +0 -163
- package/src/antd/form/RadioButton/index.tsx +0 -32
- package/src/antd/form/Upload/index.tsx +0 -65
- package/src/antd/form/UploadImage/index.tsx +0 -338
- package/src/antd/form/index.ts +0 -6
- package/src/antd/index.ts +0 -46
- package/src/antd/pro/Alert/index.tsx +0 -24
- package/src/antd/pro/Button/components/Confirm.tsx +0 -24
- package/src/antd/pro/Button/components/Copy.tsx +0 -47
- package/src/antd/pro/Button/components/Drawer.tsx +0 -37
- package/src/antd/pro/Button/components/Group.tsx +0 -26
- package/src/antd/pro/Button/index.tsx +0 -11
- package/src/antd/pro/Card/index.tsx +0 -92
- package/src/antd/pro/Collapse/components/Item.tsx +0 -30
- package/src/antd/pro/Collapse/index.tsx +0 -27
- package/src/antd/pro/Image/index.tsx +0 -17
- package/src/antd/pro/Input/components/Range.tsx +0 -46
- package/src/antd/pro/Input/index.tsx +0 -61
- package/src/antd/pro/Popconfirm/index.tsx +0 -16
- package/src/antd/pro/Radio/components/Cancel.tsx +0 -30
- package/src/antd/pro/Radio/index.tsx +0 -7
- package/src/antd/pro/Space/index.tsx +0 -15
- package/src/antd/pro/Tabs/index.tsx +0 -135
- package/src/antd/pro/Typography/components/String.tsx +0 -72
- package/src/antd/pro/Typography/index.tsx +0 -9
- package/src/antd/pro/index.ts +0 -11
- package/src/components/BottomBar/index.tsx +0 -28
- package/src/components/CodeView/index.tsx +0 -85
- package/src/components/Collapse/index.tsx +0 -26
- package/src/components/Com2Canvas/index.tsx +0 -60
- package/src/components/CompileHtml/index.tsx +0 -26
- package/src/components/Crud/components/CardList/index.tsx +0 -174
- package/src/components/Crud/components/CreateUpdate/index.tsx +0 -179
- package/src/components/Crud/components/Provider/index.tsx +0 -83
- package/src/components/Crud/components/Remove/index.tsx +0 -56
- package/src/components/Crud/components/index.ts +0 -4
- package/src/components/Crud/hooks/index.ts +0 -4
- package/src/components/Crud/hooks/useColumns.tsx +0 -169
- package/src/components/Crud/hooks/useList.ts +0 -65
- package/src/components/Crud/hooks/useOrderable.tsx +0 -107
- package/src/components/Crud/hooks/useRequest.ts +0 -41
- package/src/components/Crud/index.tsx +0 -91
- package/src/components/Crud/types/index.ts +0 -188
- package/src/components/Crud/utils/index.ts +0 -87
- package/src/components/DateSwitcher/index.module.scss +0 -10
- package/src/components/DateSwitcher/index.tsx +0 -75
- package/src/components/DownloadLink/index.tsx +0 -36
- package/src/components/DragSort/index.tsx +0 -77
- package/src/components/DynamicSelect/index.tsx +0 -74
- package/src/components/DynamicSelect/utils.ts +0 -45
- package/src/components/EnumTag/index.tsx +0 -24
- package/src/components/FetchSelect/index.tsx +0 -57
- package/src/components/Fold/index.tsx +0 -52
- package/src/components/FormPro/index.tsx +0 -28
- package/src/components/GroupLayout/index.tsx +0 -45
- package/src/components/HtmlPro/index.tsx +0 -18
- package/src/components/IframePro/index.tsx +0 -52
- package/src/components/JsonRenderer/index.tsx +0 -114
- package/src/components/JsonView/index.tsx +0 -21
- package/src/components/Markdown/index.tsx +0 -152
- package/src/components/MindMap/context.tsx +0 -29
- package/src/components/MindMap/hooks/useAlignmentSnap.ts +0 -220
- package/src/components/MindMap/hooks/useCopyPaste.ts +0 -272
- package/src/components/MindMap/hooks/useDropToReparent.ts +0 -288
- package/src/components/MindMap/hooks/useExpandCollapse.ts +0 -146
- package/src/components/MindMap/hooks/useMoveDescendants.ts +0 -136
- package/src/components/MindMap/hooks/useUndoRedo.ts +0 -232
- package/src/components/MindMap/index.tsx +0 -117
- package/src/components/MultiImageDisplay/index.tsx +0 -63
- package/src/components/ProgressButton/index.module.scss +0 -65
- package/src/components/ProgressButton/index.tsx +0 -96
- package/src/components/SectorButton/index.tsx +0 -247
- package/src/components/TextInput/index.tsx +0 -61
- package/src/components/TimelineBar/components/CurrentWeekHighlight/index.tsx +0 -64
- package/src/components/TimelineBar/components/Guides/index.tsx +0 -61
- package/src/components/TimelineBar/components/Ticks/index.tsx +0 -56
- package/src/components/TimelineBar/components/TodayIndicator/index.tsx +0 -54
- package/src/components/TimelineBar/components/index.ts +0 -4
- package/src/components/TimelineBar/const.ts +0 -3
- package/src/components/TimelineBar/hooks/index.ts +0 -5
- package/src/components/TimelineBar/hooks/useHighlightRange.ts +0 -21
- package/src/components/TimelineBar/hooks/useMonthGuides.ts +0 -40
- package/src/components/TimelineBar/hooks/useTickValues.ts +0 -18
- package/src/components/TimelineBar/hooks/useVisibleRange.ts +0 -43
- package/src/components/TimelineBar/hooks/useWeekGuides.ts +0 -39
- package/src/components/TimelineBar/index.tsx +0 -63
- package/src/components/TimelineBar/utils.ts +0 -27
- package/src/components/Video/index.tsx +0 -37
- package/src/components/index.ts +0 -27
- package/src/rn.ts +0 -1
- package/src/rns/index.ts +0 -0
- package/src/web.ts +0 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useMemo } from 'react';
|
|
3
|
+
const buildChildrenById = (edges) => {
|
|
4
|
+
const map = new Map();
|
|
5
|
+
edges.forEach(edge => {
|
|
6
|
+
const prev = map.get(edge.source) ?? [];
|
|
7
|
+
map.set(edge.source, [...prev, edge.target]);
|
|
8
|
+
});
|
|
9
|
+
return map;
|
|
10
|
+
};
|
|
11
|
+
const getDescendantIdSet = (childrenById, rootId) => {
|
|
12
|
+
const visited = new Set([rootId]);
|
|
13
|
+
const result = new Set();
|
|
14
|
+
const queue = [rootId];
|
|
15
|
+
while (queue.length > 0) {
|
|
16
|
+
const currentId = queue.shift();
|
|
17
|
+
if (!currentId) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const children = childrenById.get(currentId) ?? [];
|
|
21
|
+
for (const childId of children) {
|
|
22
|
+
if (visited.has(childId)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
visited.add(childId);
|
|
26
|
+
result.add(childId);
|
|
27
|
+
queue.push(childId);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
export const useExpandCollapse = (params) => {
|
|
33
|
+
const { nodes, edges, onNodesChange, onEdgesChange } = params;
|
|
34
|
+
const childrenById = useMemo(() => {
|
|
35
|
+
return buildChildrenById(edges);
|
|
36
|
+
}, [edges]);
|
|
37
|
+
const nodeById = useMemo(() => {
|
|
38
|
+
return new Map(nodes.map(n => [n.id, n]));
|
|
39
|
+
}, [nodes]);
|
|
40
|
+
const edgeById = useMemo(() => {
|
|
41
|
+
return new Map(edges.map(e => [e.id, e]));
|
|
42
|
+
}, [edges]);
|
|
43
|
+
const getCounts = useCallback((nodeId) => {
|
|
44
|
+
const childCount = (childrenById.get(nodeId) ?? []).length;
|
|
45
|
+
const descendantCount = getDescendantIdSet(childrenById, nodeId).size;
|
|
46
|
+
return { childCount, descendantCount };
|
|
47
|
+
}, [childrenById]);
|
|
48
|
+
const setSubtreeHidden = useCallback((nodeId, hidden) => {
|
|
49
|
+
const descendantIdSet = getDescendantIdSet(childrenById, nodeId);
|
|
50
|
+
if (descendantIdSet.size === 0) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (onNodesChange) {
|
|
54
|
+
const nodeChanges = [];
|
|
55
|
+
descendantIdSet.forEach(id => {
|
|
56
|
+
const node = nodeById.get(id);
|
|
57
|
+
if (!node) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if ((node.hidden ?? false) === hidden) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
nodeChanges.push({
|
|
64
|
+
type: 'replace',
|
|
65
|
+
id,
|
|
66
|
+
item: {
|
|
67
|
+
...node,
|
|
68
|
+
hidden,
|
|
69
|
+
selected: false,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
if (nodeChanges.length > 0) {
|
|
74
|
+
onNodesChange(nodeChanges);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (onEdgesChange) {
|
|
78
|
+
const idSet = new Set([nodeId, ...Array.from(descendantIdSet)]);
|
|
79
|
+
const edgeChanges = edges
|
|
80
|
+
.filter(edge => idSet.has(edge.source) && idSet.has(edge.target))
|
|
81
|
+
.map(edge => edgeById.get(edge.id))
|
|
82
|
+
.filter((edge) => !!edge)
|
|
83
|
+
.filter(edge => (edge.hidden ?? false) !== hidden)
|
|
84
|
+
.map(edge => ({
|
|
85
|
+
type: 'replace',
|
|
86
|
+
id: edge.id,
|
|
87
|
+
item: {
|
|
88
|
+
...edge,
|
|
89
|
+
hidden,
|
|
90
|
+
},
|
|
91
|
+
}));
|
|
92
|
+
if (edgeChanges.length > 0) {
|
|
93
|
+
onEdgesChange(edgeChanges);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}, [childrenById, edgeById, edges, nodeById, onEdgesChange, onNodesChange]);
|
|
97
|
+
const expand = useCallback((nodeId) => {
|
|
98
|
+
setSubtreeHidden(nodeId, false);
|
|
99
|
+
}, [setSubtreeHidden]);
|
|
100
|
+
const collapse = useCallback((nodeId) => {
|
|
101
|
+
setSubtreeHidden(nodeId, true);
|
|
102
|
+
}, [setSubtreeHidden]);
|
|
103
|
+
return {
|
|
104
|
+
getCounts,
|
|
105
|
+
expand,
|
|
106
|
+
collapse,
|
|
107
|
+
};
|
|
108
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Edge, Node, NodeChange } from '@xyflow/react';
|
|
2
|
+
interface UseMoveDescendantsParams<TNodeData extends Record<string, unknown>> {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
nodes: Array<Node<TNodeData>>;
|
|
5
|
+
edges: Edge[];
|
|
6
|
+
onNodesChange?: (changes: Array<NodeChange<Node<TNodeData>>>) => void;
|
|
7
|
+
}
|
|
8
|
+
interface UseMoveDescendantsResult<TNodeData extends Record<string, unknown>> {
|
|
9
|
+
onNodesChange: (changes: Array<NodeChange<Node<TNodeData>>>) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const useMoveDescendants: <TNodeData extends Record<string, unknown>>(params: UseMoveDescendantsParams<TNodeData>) => UseMoveDescendantsResult<TNodeData>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useMemo } from 'react';
|
|
3
|
+
const getDescendants = (sourceToTargets, rootId) => {
|
|
4
|
+
const visited = new Set([rootId]);
|
|
5
|
+
const result = new Set();
|
|
6
|
+
const queue = [rootId];
|
|
7
|
+
while (queue.length > 0) {
|
|
8
|
+
const currentId = queue.shift();
|
|
9
|
+
if (!currentId) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const targets = sourceToTargets.get(currentId) ?? [];
|
|
13
|
+
for (const targetId of targets) {
|
|
14
|
+
if (visited.has(targetId)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
visited.add(targetId);
|
|
18
|
+
result.add(targetId);
|
|
19
|
+
queue.push(targetId);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
export const useMoveDescendants = (params) => {
|
|
25
|
+
const { enabled = true, nodes, edges, onNodesChange: onNodesChangeExternal } = params;
|
|
26
|
+
// 用 edge.source -> edge.target 作为父子关系(默认把 source 当作父节点)
|
|
27
|
+
const sourceToTargets = useMemo(() => {
|
|
28
|
+
const map = new Map();
|
|
29
|
+
edges.forEach(edge => {
|
|
30
|
+
const prev = map.get(edge.source) ?? [];
|
|
31
|
+
map.set(edge.source, [...prev, edge.target]);
|
|
32
|
+
});
|
|
33
|
+
return map;
|
|
34
|
+
}, [edges]);
|
|
35
|
+
const onNodesChange = useCallback((changes) => {
|
|
36
|
+
if (!onNodesChangeExternal) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!enabled || edges.length === 0) {
|
|
40
|
+
onNodesChangeExternal(changes);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// 用旧节点位置计算拖拽的 dx/dy,再把位移叠加到后代节点
|
|
44
|
+
const nodeMap = new Map(nodes.map(node => [node.id, node]));
|
|
45
|
+
const changedIdSet = new Set(changes.filter(change => change.type === 'position').map(change => change.id));
|
|
46
|
+
const deltaMap = new Map();
|
|
47
|
+
changes.forEach(change => {
|
|
48
|
+
if (change.type !== 'position' || !change.position) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const prev = nodeMap.get(change.id);
|
|
52
|
+
if (!prev) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const dx = change.position.x - prev.position.x;
|
|
56
|
+
const dy = change.position.y - prev.position.y;
|
|
57
|
+
if (dx === 0 && dy === 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const dragging = change.dragging === true;
|
|
61
|
+
// 只影响“未被本次 change 显式更新”的节点,避免和多选拖拽冲突
|
|
62
|
+
const descendants = getDescendants(sourceToTargets, change.id);
|
|
63
|
+
descendants.forEach(descId => {
|
|
64
|
+
if (changedIdSet.has(descId)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const prevDelta = deltaMap.get(descId);
|
|
68
|
+
if (!prevDelta) {
|
|
69
|
+
deltaMap.set(descId, { dx, dy, dragging });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
deltaMap.set(descId, { dx: prevDelta.dx + dx, dy: prevDelta.dy + dy, dragging: prevDelta.dragging || dragging });
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
if (deltaMap.size === 0) {
|
|
76
|
+
onNodesChangeExternal(changes);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const extraChanges = [];
|
|
80
|
+
deltaMap.forEach((delta, nodeId) => {
|
|
81
|
+
const node = nodeMap.get(nodeId);
|
|
82
|
+
if (!node) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
extraChanges.push({
|
|
86
|
+
type: 'position',
|
|
87
|
+
id: nodeId,
|
|
88
|
+
position: {
|
|
89
|
+
x: node.position.x + delta.dx,
|
|
90
|
+
y: node.position.y + delta.dy,
|
|
91
|
+
},
|
|
92
|
+
dragging: delta.dragging,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
onNodesChangeExternal([...changes, ...extraChanges]);
|
|
96
|
+
}, [edges.length, enabled, nodes, onNodesChangeExternal, sourceToTargets]);
|
|
97
|
+
return { onNodesChange };
|
|
98
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Edge, EdgeChange, Node, NodeChange } from '@xyflow/react';
|
|
2
|
+
interface UseUndoRedoParams<TNodeData extends Record<string, unknown>> {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
nodes: Array<Node<TNodeData>>;
|
|
5
|
+
edges: Edge[];
|
|
6
|
+
onNodesChange?: (changes: Array<NodeChange<Node<TNodeData>>>) => void;
|
|
7
|
+
onEdgesChange?: (changes: Array<EdgeChange<Edge>>) => void;
|
|
8
|
+
}
|
|
9
|
+
interface UseUndoRedoResult<TNodeData extends Record<string, unknown>> {
|
|
10
|
+
onNodesChange: (changes: Array<NodeChange<Node<TNodeData>>>) => void;
|
|
11
|
+
onEdgesChange: (changes: Array<EdgeChange<Edge>>) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const useUndoRedo: <TNodeData extends Record<string, unknown>>(params: UseUndoRedoParams<TNodeData>) => UseUndoRedoResult<TNodeData>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
3
|
+
const clone = (value) => {
|
|
4
|
+
const anyGlobal = globalThis;
|
|
5
|
+
if (typeof anyGlobal.structuredClone === 'function') {
|
|
6
|
+
return anyGlobal.structuredClone(value);
|
|
7
|
+
}
|
|
8
|
+
return JSON.parse(JSON.stringify(value));
|
|
9
|
+
};
|
|
10
|
+
const isEditableTarget = (target) => {
|
|
11
|
+
const el = target;
|
|
12
|
+
if (!el) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const tag = el.tagName?.toLowerCase();
|
|
16
|
+
if (tag === 'input' || tag === 'textarea') {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return el.isContentEditable;
|
|
20
|
+
};
|
|
21
|
+
const buildNodeChanges = (current, next) => {
|
|
22
|
+
const currentById = new Map(current.map(n => [n.id, n]));
|
|
23
|
+
const nextById = new Map(next.map(n => [n.id, n]));
|
|
24
|
+
const changes = [];
|
|
25
|
+
current.forEach(node => {
|
|
26
|
+
if (!nextById.has(node.id)) {
|
|
27
|
+
changes.push({ type: 'remove', id: node.id });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
next.forEach(node => {
|
|
31
|
+
if (!currentById.has(node.id)) {
|
|
32
|
+
changes.push({ type: 'add', item: clone(node) });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
changes.push({ type: 'replace', id: node.id, item: clone(node) });
|
|
36
|
+
});
|
|
37
|
+
return changes;
|
|
38
|
+
};
|
|
39
|
+
const buildEdgeChanges = (current, next) => {
|
|
40
|
+
const currentById = new Map(current.map(e => [e.id, e]));
|
|
41
|
+
const nextById = new Map(next.map(e => [e.id, e]));
|
|
42
|
+
const changes = [];
|
|
43
|
+
current.forEach(edge => {
|
|
44
|
+
if (!nextById.has(edge.id)) {
|
|
45
|
+
changes.push({ type: 'remove', id: edge.id });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
next.forEach(edge => {
|
|
49
|
+
if (!currentById.has(edge.id)) {
|
|
50
|
+
changes.push({ type: 'add', item: clone(edge) });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
changes.push({ type: 'replace', id: edge.id, item: clone(edge) });
|
|
54
|
+
});
|
|
55
|
+
return changes;
|
|
56
|
+
};
|
|
57
|
+
export const useUndoRedo = (params) => {
|
|
58
|
+
const { enabled = true, nodes, edges, onNodesChange, onEdgesChange } = params;
|
|
59
|
+
const snapshot = useMemo(() => {
|
|
60
|
+
return { nodes: clone(nodes), edges: clone(edges) };
|
|
61
|
+
}, [edges, nodes]);
|
|
62
|
+
const pastRef = useRef([]);
|
|
63
|
+
const futureRef = useRef([]);
|
|
64
|
+
const applyingRef = useRef(false);
|
|
65
|
+
const commitNextRef = useRef(false);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!enabled) {
|
|
68
|
+
pastRef.current = [];
|
|
69
|
+
futureRef.current = [];
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (pastRef.current.length === 0) {
|
|
73
|
+
pastRef.current = [snapshot];
|
|
74
|
+
futureRef.current = [];
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (applyingRef.current) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!commitNextRef.current) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
commitNextRef.current = false;
|
|
84
|
+
pastRef.current = [...pastRef.current, snapshot];
|
|
85
|
+
futureRef.current = [];
|
|
86
|
+
}, [enabled, snapshot]);
|
|
87
|
+
const applySnapshot = useCallback((next) => {
|
|
88
|
+
applyingRef.current = true;
|
|
89
|
+
commitNextRef.current = false;
|
|
90
|
+
const nodeChanges = onNodesChange ? buildNodeChanges(nodes, next.nodes) : [];
|
|
91
|
+
const edgeChanges = onEdgesChange ? buildEdgeChanges(edges, next.edges) : [];
|
|
92
|
+
if (nodeChanges.length > 0) {
|
|
93
|
+
onNodesChange?.(nodeChanges);
|
|
94
|
+
}
|
|
95
|
+
if (edgeChanges.length > 0) {
|
|
96
|
+
onEdgesChange?.(edgeChanges);
|
|
97
|
+
}
|
|
98
|
+
queueMicrotask(() => {
|
|
99
|
+
applyingRef.current = false;
|
|
100
|
+
});
|
|
101
|
+
}, [edges, nodes, onEdgesChange, onNodesChange]);
|
|
102
|
+
const undo = useCallback(() => {
|
|
103
|
+
const past = pastRef.current;
|
|
104
|
+
const current = past.at(-1);
|
|
105
|
+
const prev = past.at(-2);
|
|
106
|
+
if (!current || !prev) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
pastRef.current = past.slice(0, -1);
|
|
110
|
+
futureRef.current = [current, ...futureRef.current];
|
|
111
|
+
applySnapshot(prev);
|
|
112
|
+
}, [applySnapshot]);
|
|
113
|
+
const redo = useCallback(() => {
|
|
114
|
+
const next = futureRef.current.at(0);
|
|
115
|
+
if (!next) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
futureRef.current = futureRef.current.slice(1);
|
|
119
|
+
pastRef.current = [...pastRef.current, next];
|
|
120
|
+
applySnapshot(next);
|
|
121
|
+
}, [applySnapshot]);
|
|
122
|
+
const onNodesChangeWrapped = useCallback((changes) => {
|
|
123
|
+
onNodesChange?.(changes);
|
|
124
|
+
if (!enabled) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const shouldCommit = changes.some(change => {
|
|
128
|
+
if (change.type === 'position') {
|
|
129
|
+
return change.dragging !== true;
|
|
130
|
+
}
|
|
131
|
+
return change.type === 'add' || change.type === 'remove';
|
|
132
|
+
});
|
|
133
|
+
if (shouldCommit) {
|
|
134
|
+
commitNextRef.current = true;
|
|
135
|
+
}
|
|
136
|
+
}, [enabled, onNodesChange]);
|
|
137
|
+
const onEdgesChangeWrapped = useCallback((changes) => {
|
|
138
|
+
onEdgesChange?.(changes);
|
|
139
|
+
if (!enabled) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const shouldCommit = changes.some(change => {
|
|
143
|
+
return change.type === 'add' || change.type === 'remove';
|
|
144
|
+
});
|
|
145
|
+
if (shouldCommit) {
|
|
146
|
+
commitNextRef.current = true;
|
|
147
|
+
}
|
|
148
|
+
}, [enabled, onEdgesChange]);
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (!enabled) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const onKeyDown = (event) => {
|
|
154
|
+
if (isEditableTarget(event.target)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const isMac = /Mac|iPhone|iPad|iPod/.test(navigator.platform);
|
|
158
|
+
const mod = isMac ? event.metaKey : event.ctrlKey;
|
|
159
|
+
if (!mod) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (event.key.toLowerCase() !== 'z') {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
if (event.shiftKey) {
|
|
167
|
+
redo();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
undo();
|
|
171
|
+
};
|
|
172
|
+
document.addEventListener('keydown', onKeyDown);
|
|
173
|
+
return () => {
|
|
174
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
175
|
+
};
|
|
176
|
+
}, [enabled, redo, undo]);
|
|
177
|
+
return {
|
|
178
|
+
onNodesChange: onNodesChangeWrapped,
|
|
179
|
+
onEdgesChange: onEdgesChangeWrapped,
|
|
180
|
+
};
|
|
181
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import { type Edge, type EdgeChange, type EdgeTypes, type Node, type NodeChange, type NodeTypes } from '@xyflow/react';
|
|
3
|
+
import '@xyflow/react/dist/style.css';
|
|
4
|
+
import { useExpandCollapse } from './hooks/useExpandCollapse';
|
|
5
|
+
import { useMindMapDndState } from './context';
|
|
6
|
+
export interface MindMapNodeData extends Record<string, unknown> {
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
export { useMindMapDndState, useExpandCollapse };
|
|
10
|
+
interface MindMapProps {
|
|
11
|
+
className?: string;
|
|
12
|
+
enableSnap?: boolean;
|
|
13
|
+
moveDescendants?: boolean;
|
|
14
|
+
enableDropToNode?: boolean;
|
|
15
|
+
enableCopyPaste?: boolean;
|
|
16
|
+
enableUndoRedo?: boolean;
|
|
17
|
+
dropHighlightClassName?: string;
|
|
18
|
+
canDropOnNode?: (params: {
|
|
19
|
+
draggingNode: Node<MindMapNodeData>;
|
|
20
|
+
targetNode: Node<MindMapNodeData>;
|
|
21
|
+
}) => boolean;
|
|
22
|
+
nodeTypes?: NodeTypes;
|
|
23
|
+
edgeTypes?: EdgeTypes;
|
|
24
|
+
nodes: Array<Node<MindMapNodeData>>;
|
|
25
|
+
edges?: Edge[];
|
|
26
|
+
onNodesChange?: (changes: Array<NodeChange<Node<MindMapNodeData>>>) => void;
|
|
27
|
+
onEdgesChange?: (changes: Array<EdgeChange<Edge>>) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare const MindMap: (props: MindMapProps) => ReactElement;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ReactFlow } from '@xyflow/react';
|
|
4
|
+
import '@xyflow/react/dist/style.css';
|
|
5
|
+
import { useAlignmentSnap } from './hooks/useAlignmentSnap';
|
|
6
|
+
import { useMoveDescendants } from './hooks/useMoveDescendants';
|
|
7
|
+
import { useDropToReparent } from './hooks/useDropToReparent';
|
|
8
|
+
import { useCopyPaste } from './hooks/useCopyPaste';
|
|
9
|
+
import { useUndoRedo } from './hooks/useUndoRedo';
|
|
10
|
+
import { useExpandCollapse } from './hooks/useExpandCollapse';
|
|
11
|
+
import { MindMapDndProvider, useMindMapDndState } from './context';
|
|
12
|
+
export { useMindMapDndState, useExpandCollapse };
|
|
13
|
+
export const MindMap = (props) => {
|
|
14
|
+
const { nodes, edges = [], onNodesChange, onEdgesChange, enableSnap = false, moveDescendants = true, enableDropToNode = true, enableCopyPaste = true, enableUndoRedo = true, dropHighlightClassName, canDropOnNode, nodeTypes, edgeTypes, className = 'w-full h-full', } = props;
|
|
15
|
+
// 先把“联动后代移动”合并进节点变更回调,后续其它能力(如吸附)再基于它叠加
|
|
16
|
+
const { onNodesChange: onNodesChangeWithDescendants } = useMoveDescendants({
|
|
17
|
+
enabled: moveDescendants,
|
|
18
|
+
nodes,
|
|
19
|
+
edges,
|
|
20
|
+
onNodesChange,
|
|
21
|
+
});
|
|
22
|
+
// 在节点变更回调上叠加对齐线与吸附逻辑,并由 hook 直接给出对齐线元素
|
|
23
|
+
const { helperLines, onMove, onNodesChange: onNodesChangeWithSnap } = useAlignmentSnap({
|
|
24
|
+
enabled: enableSnap,
|
|
25
|
+
nodes,
|
|
26
|
+
onNodesChange: onNodesChangeWithDescendants,
|
|
27
|
+
});
|
|
28
|
+
const { onNodesChange: onNodesChangeWithUndoRedo, onEdgesChange: onEdgesChangeWithUndoRedo } = useUndoRedo({
|
|
29
|
+
enabled: enableUndoRedo,
|
|
30
|
+
nodes,
|
|
31
|
+
edges,
|
|
32
|
+
onNodesChange: onNodesChangeWithSnap,
|
|
33
|
+
onEdgesChange,
|
|
34
|
+
});
|
|
35
|
+
const { onNodeDrag, onNodeDragStop, draggingNodeId, dropTargetNodeId } = useDropToReparent({
|
|
36
|
+
enabled: enableDropToNode,
|
|
37
|
+
nodes,
|
|
38
|
+
edges,
|
|
39
|
+
dropHighlightClassName,
|
|
40
|
+
canDropOnNode,
|
|
41
|
+
onNodesChange: onNodesChangeWithUndoRedo,
|
|
42
|
+
onEdgesChange: onEdgesChangeWithUndoRedo,
|
|
43
|
+
});
|
|
44
|
+
useCopyPaste({
|
|
45
|
+
enabled: enableCopyPaste,
|
|
46
|
+
nodes,
|
|
47
|
+
edges,
|
|
48
|
+
onNodesChange: onNodesChangeWithUndoRedo,
|
|
49
|
+
onEdgesChange: onEdgesChangeWithUndoRedo,
|
|
50
|
+
});
|
|
51
|
+
return (_jsx(MindMapDndProvider, { value: { draggingNodeId, dropTargetNodeId }, children: _jsxs("div", { className: `relative ${className}`, children: [_jsx(ReactFlow, { fitView: true, nodes: nodes, edges: edges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesChange: onNodesChangeWithUndoRedo, onEdgesChange: onEdgesChangeWithUndoRedo, onMove: enableSnap ? onMove : undefined, onNodeDrag: onNodeDrag, onNodeDragStop: onNodeDragStop }), helperLines] }) }));
|
|
52
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from 'antd';
|
|
2
|
+
export { default as zh_CN } from 'antd/locale/zh_CN';
|
|
3
|
+
export { AntdRegistry } from '@ant-design/nextjs-registry';
|
|
4
|
+
export * from '@ant-design/icons';
|
|
5
|
+
export { PageLoading, PageHeader, ProCard, ProList, ProTable, ProDescriptions, ProForm, ProFormList, ProFormText, ProFormCaptcha, ProFormCheckbox, ProFormSelect, ProFormUploadButton, LoginForm, BetaSchemaForm, StepsForm, CheckCard, EditableProTable, DragSortTable, ProProvider, } from '@ant-design/pro-components';
|
|
6
|
+
export type { ProTableProps, ProFormProps, ProColumns, ProLayoutProps, ProFormInstance, ActionType, ProFormColumnsType, } from '@ant-design/pro-components';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from 'antd';
|
|
2
|
+
export { default as zh_CN } from 'antd/locale/zh_CN';
|
|
3
|
+
export { AntdRegistry } from '@ant-design/nextjs-registry';
|
|
4
|
+
export * from '@ant-design/icons';
|
|
5
|
+
export { PageLoading, PageHeader, ProCard, ProList, ProTable, ProDescriptions, ProForm, ProFormList, ProFormText, ProFormCaptcha, ProFormCheckbox, ProFormSelect, ProFormUploadButton, LoginForm, BetaSchemaForm, StepsForm, CheckCard, EditableProTable, DragSortTable, ProProvider, } from '@ant-design/pro-components';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ConfirmButtonProps } from '../ConfirmButton';
|
|
2
|
+
export interface ButtonGroupProps {
|
|
3
|
+
list?: (ConfirmButtonProps & {
|
|
4
|
+
visible?: boolean;
|
|
5
|
+
title?: string;
|
|
6
|
+
})[];
|
|
7
|
+
}
|
|
8
|
+
export declare const ButtonGroup: (props: ButtonGroupProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Fragment } from 'react';
|
|
4
|
+
import { Space } from 'antd';
|
|
5
|
+
import { ConfirmButton } from '../ConfirmButton';
|
|
6
|
+
// 1. 按钮组
|
|
7
|
+
export const ButtonGroup = (props) => {
|
|
8
|
+
const { list = [] } = props;
|
|
9
|
+
if (!list?.length) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return (_jsx(Space.Compact, { children: list.filter(item => item.visible).map((item, index) => (_jsx(Fragment, { children: _jsx(ConfirmButton, { ...item, children: item.title }) }, index))) }));
|
|
13
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { _ } from '@wzyjs/utils/web';
|
|
4
|
+
import { Button, Popconfirm } from 'antd';
|
|
5
|
+
// 1. 给按钮增加了确认功能
|
|
6
|
+
export const ConfirmButton = (props) => {
|
|
7
|
+
const { children, btnProps } = props;
|
|
8
|
+
return (_jsx(Popconfirm, { okText: '\u662F', cancelText: '\u5426', ..._.omit(props, ['children', 'btnProps']), children: _jsx(Button, { type: 'link', ...btnProps, children: children }) }));
|
|
9
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { App, Button } from 'antd';
|
|
5
|
+
import { CheckOutlined } from '@ant-design/icons';
|
|
6
|
+
import { copy, readClipboard } from '@wzyjs/utils/web';
|
|
7
|
+
import { useControllableValue } from '@wzyjs/hooks/web';
|
|
8
|
+
export const CopyButton = (props) => {
|
|
9
|
+
const [icon, setIcon] = useState(null);
|
|
10
|
+
const { message } = App.useApp();
|
|
11
|
+
const [value, setValue] = useControllableValue(props, {
|
|
12
|
+
defaultValue: props.value,
|
|
13
|
+
});
|
|
14
|
+
const onContextMenu = async () => {
|
|
15
|
+
setValue(await readClipboard());
|
|
16
|
+
};
|
|
17
|
+
return (_jsx(Button, { ...props, icon: icon, onContextMenu: props.canPaste ? onContextMenu : undefined, children: props.children || value || '记录', onClick: (ev) => {
|
|
18
|
+
props.onClick?.(ev);
|
|
19
|
+
copy(value);
|
|
20
|
+
message.success('复制成功');
|
|
21
|
+
setIcon(_jsx(CheckOutlined, {}));
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
setIcon(null);
|
|
24
|
+
}, 1000);
|
|
25
|
+
} }));
|
|
26
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DrawerProps as AntdDrawerProps, ButtonProps } from 'antd';
|
|
2
|
+
export interface DrawerButtonProps extends AntdDrawerProps {
|
|
3
|
+
btnProps?: ButtonProps;
|
|
4
|
+
defaultOpen?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const DrawerButton: (props: DrawerButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { _ } from '@wzyjs/utils/web';
|
|
5
|
+
import { Button, Drawer as AntdDrawer } from 'antd';
|
|
6
|
+
export const DrawerButton = (props) => {
|
|
7
|
+
const { children, defaultOpen, btnProps } = props;
|
|
8
|
+
const [open, setOpen] = useState(defaultOpen ?? false);
|
|
9
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { type: 'link', ...btnProps, onClick: ev => {
|
|
10
|
+
btnProps?.onClick?.(ev);
|
|
11
|
+
setOpen(true);
|
|
12
|
+
} }), _jsx(AntdDrawer, { title: btnProps?.children, open: open, onClose: () => setOpen(false), destroyOnHidden: true, ..._.omit(props, ['children', 'btnProps']), children: children })] }));
|
|
13
|
+
};
|