@hzab/flowlong-designer 0.0.1
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/CHANGELOG.md +2 -0
- package/README.md +67 -0
- package/package.json +51 -0
- package/src/common/flowData.ts +42 -0
- package/src/components/NodeWrap/Nodes/AddNode/index.less +38 -0
- package/src/components/NodeWrap/Nodes/AddNode/index.tsx +119 -0
- package/src/components/NodeWrap/Nodes/Approver/index.less +72 -0
- package/src/components/NodeWrap/Nodes/Approver/index.tsx +385 -0
- package/src/components/NodeWrap/Nodes/Approver/options.ts +44 -0
- package/src/components/NodeWrap/Nodes/Branch/index.less +319 -0
- package/src/components/NodeWrap/Nodes/Branch/index.tsx +387 -0
- package/src/components/NodeWrap/Nodes/Promoter/index.less +10 -0
- package/src/components/NodeWrap/Nodes/Promoter/index.tsx +178 -0
- package/src/components/NodeWrap/Nodes/Send/index.less +7 -0
- package/src/components/NodeWrap/Nodes/Send/index.tsx +201 -0
- package/src/components/NodeWrap/index.less +29 -0
- package/src/components/NodeWrap/index.tsx +30 -0
- package/src/components/ScWorkflow/index.tsx +23 -0
- package/src/components/Selector/SelectContext.tsx +32 -0
- package/src/components/Selector/index.less +139 -0
- package/src/components/Selector/index.tsx +240 -0
- package/src/index.less +466 -0
- package/src/index.tsx +134 -0
package/src/index.tsx
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Button, Drawer } from "antd";
|
|
3
|
+
|
|
4
|
+
import ScWorkflow from "./components/ScWorkflow";
|
|
5
|
+
|
|
6
|
+
import { SelectContext, ISelectHandlerI } from "./components/Selector/SelectContext";
|
|
7
|
+
import { getInitNodeData } from "./common/flowData";
|
|
8
|
+
|
|
9
|
+
import "./index.less";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 复制指定字符串
|
|
13
|
+
* @param str
|
|
14
|
+
*/
|
|
15
|
+
function copy(str) {
|
|
16
|
+
return new Promise<void>(async (resolve, reject) => {
|
|
17
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
18
|
+
try {
|
|
19
|
+
await navigator.clipboard.writeText(str);
|
|
20
|
+
resolve();
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error("Failed to write clipboard contents: ", err);
|
|
23
|
+
reject();
|
|
24
|
+
}
|
|
25
|
+
} else if (document.execCommand) {
|
|
26
|
+
const textarea = document.createElement("textarea");
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
textarea.readonly = "readonly";
|
|
29
|
+
textarea.style.position = "absolute";
|
|
30
|
+
textarea.style.left = "-9999px";
|
|
31
|
+
textarea.style.zIndex = "-9999";
|
|
32
|
+
textarea.value = str;
|
|
33
|
+
document.body.appendChild(textarea);
|
|
34
|
+
textarea.select();
|
|
35
|
+
const res = document.execCommand("Copy");
|
|
36
|
+
if (res) {
|
|
37
|
+
resolve();
|
|
38
|
+
} else {
|
|
39
|
+
reject(new Error("Failed to write clipboard contents."));
|
|
40
|
+
}
|
|
41
|
+
document.body.removeChild(textarea);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function FlowlongDesigner(props) {
|
|
47
|
+
const { value, flowName, listModel, treeModel ,roleListModel} = props;
|
|
48
|
+
const [drawer, setDrawer] = useState(false);
|
|
49
|
+
const [zoom, setZoom] = useState(1);
|
|
50
|
+
const [data, setData] = useState(Object.keys(value || {}).length > 0 ? value : getInitNodeData({ name: flowName }));
|
|
51
|
+
const [selectHandler, setSelectHandler] = useState<ISelectHandlerI>({
|
|
52
|
+
open: false,
|
|
53
|
+
type: -1,
|
|
54
|
+
value: [],
|
|
55
|
+
onSave: (s) => {},
|
|
56
|
+
listModel,
|
|
57
|
+
treeModel,
|
|
58
|
+
roleListModel
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
value && setData(value);
|
|
63
|
+
}, [value]);
|
|
64
|
+
|
|
65
|
+
function saveAsPng() {}
|
|
66
|
+
function copyParseJson() {
|
|
67
|
+
copy(JSON.stringify(data, null, 2));
|
|
68
|
+
}
|
|
69
|
+
function copyJson() {
|
|
70
|
+
copy(JSON.stringify(data));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function onDrawerClose() {
|
|
74
|
+
setDrawer(false);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<div className="flowlong-designer">
|
|
79
|
+
<SelectContext.Provider
|
|
80
|
+
value={{
|
|
81
|
+
selectHandler,
|
|
82
|
+
setSelectHandler(type, value, onSave) {
|
|
83
|
+
setSelectHandler({ open: true, type, value, onSave , listModel, treeModel, roleListModel});
|
|
84
|
+
},
|
|
85
|
+
onClose() {
|
|
86
|
+
setSelectHandler({ open: false, type: -1, value: [], onSave: (s) => {} , listModel, treeModel, roleListModel});
|
|
87
|
+
},
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
<div className="designer-affix">
|
|
91
|
+
<Button className="action-btn view-json-btn" onClick={() => setDrawer(true)}>
|
|
92
|
+
查看 JSON
|
|
93
|
+
</Button>
|
|
94
|
+
{/* <Button className="action-btn save-img-btn" onClick={saveAsPng}>
|
|
95
|
+
保存图片
|
|
96
|
+
</Button> */}
|
|
97
|
+
<Button className="action-btn zoom-in-btn" onClick={() => setZoom((z) => z - 0.1)}>
|
|
98
|
+
缩小
|
|
99
|
+
</Button>
|
|
100
|
+
<Button className="action-btn zoom-out-btn" onClick={() => setZoom((z) => z + 0.1)}>
|
|
101
|
+
放大
|
|
102
|
+
</Button>
|
|
103
|
+
</div>
|
|
104
|
+
<div className="affix-container" style={{ transformOrigin: "0 0", transform: `scale(${zoom})` }}>
|
|
105
|
+
<ScWorkflow
|
|
106
|
+
className="workflow"
|
|
107
|
+
id="content-to-capture"
|
|
108
|
+
modelValue={data.nodeConfig}
|
|
109
|
+
onChange={(val) => {
|
|
110
|
+
setData((d) => {
|
|
111
|
+
d.nodeConfig = val;
|
|
112
|
+
return { ...d };
|
|
113
|
+
});
|
|
114
|
+
}}
|
|
115
|
+
/>
|
|
116
|
+
<Drawer className="drawer-wrapper" open={drawer} width={720} onClose={onDrawerClose}>
|
|
117
|
+
<div>
|
|
118
|
+
<div className="cp-parse-json-btn" onClick={copyParseJson}>
|
|
119
|
+
复制格式化后的 JSON
|
|
120
|
+
</div>
|
|
121
|
+
<div className="cp-json-btn" onClick={copyJson}>
|
|
122
|
+
复制压缩后的 JSON
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
{/* <json-editor-vue className="editor" language="zh-CN" current-mode="view" v-model="data" /> */}
|
|
126
|
+
<pre className="json-viewer">{JSON.stringify(data, null, 2)}</pre>
|
|
127
|
+
</Drawer>
|
|
128
|
+
</div>
|
|
129
|
+
</SelectContext.Provider>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export default FlowlongDesigner;
|