bi-sdk-react 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.
Files changed (146) hide show
  1. package/dist/es/css/bi-sdk.css +1 -0
  2. package/dist/es/js/bi-sdk.es.js +795 -0
  3. package/dist/es/js/bi-sdk.es.js.LICENSE.txt +9 -0
  4. package/dist/types/components/PageDesigner.d.ts +10 -0
  5. package/dist/types/components/context/DesignerContext.d.ts +15 -0
  6. package/dist/types/components/context/EnvContext.d.ts +15 -0
  7. package/dist/types/components/dnd/DropContainer.d.ts +21 -0
  8. package/dist/types/components/example.d.ts +225 -0
  9. package/dist/types/components/hooks/datasource.d.ts +1 -0
  10. package/dist/types/components/hooks/useDeepCompareEffect.d.ts +1 -0
  11. package/dist/types/components/icon/IconFont.d.ts +6 -0
  12. package/dist/types/components/index.d.ts +10 -0
  13. package/dist/types/components/layout/PageCanvas.d.ts +6 -0
  14. package/dist/types/components/layout/PageItem.d.ts +27 -0
  15. package/dist/types/components/panel/AiPanel.d.ts +8 -0
  16. package/dist/types/components/panel/CascadePanel.d.ts +2 -0
  17. package/dist/types/components/panel/ChatInput.d.ts +28 -0
  18. package/dist/types/components/panel/CodePanel.d.ts +2 -0
  19. package/dist/types/components/panel/ComponentPanel.d.ts +2 -0
  20. package/dist/types/components/panel/DatasourcePanel.d.ts +2 -0
  21. package/dist/types/components/panel/LayerPanel.d.ts +2 -0
  22. package/dist/types/components/panel/PaneHeader.d.ts +6 -0
  23. package/dist/types/components/panel/PropertiesPanel.d.ts +2 -0
  24. package/dist/types/components/panel/ScriptPanel.d.ts +2 -0
  25. package/dist/types/components/panel/VariablesPanel.d.ts +2 -0
  26. package/dist/types/components/panel/index.d.ts +9 -0
  27. package/dist/types/components/plugins/@antd/index.d.ts +22 -0
  28. package/dist/types/components/plugins/@antd/item-props/ButtonProps.d.ts +8 -0
  29. package/dist/types/components/plugins/@antd/item-props/CapsuleProps.d.ts +13 -0
  30. package/dist/types/components/plugins/@antd/item-props/CardProps.d.ts +8 -0
  31. package/dist/types/components/plugins/@antd/item-props/CheckboxProps.d.ts +13 -0
  32. package/dist/types/components/plugins/@antd/item-props/ColProps.d.ts +12 -0
  33. package/dist/types/components/plugins/@antd/item-props/DatePickerProps.d.ts +8 -0
  34. package/dist/types/components/plugins/@antd/item-props/EchartsProps.d.ts +6 -0
  35. package/dist/types/components/plugins/@antd/item-props/HtmlProps.d.ts +6 -0
  36. package/dist/types/components/plugins/@antd/item-props/ImageProps.d.ts +10 -0
  37. package/dist/types/components/plugins/@antd/item-props/InputNumberProps.d.ts +9 -0
  38. package/dist/types/components/plugins/@antd/item-props/InputProps.d.ts +10 -0
  39. package/dist/types/components/plugins/@antd/item-props/ListProps.d.ts +10 -0
  40. package/dist/types/components/plugins/@antd/item-props/PageHeaderProps.d.ts +7 -0
  41. package/dist/types/components/plugins/@antd/item-props/RowProps.d.ts +6 -0
  42. package/dist/types/components/plugins/@antd/item-props/SelectProps.d.ts +16 -0
  43. package/dist/types/components/plugins/@antd/item-props/SpaceProps.d.ts +7 -0
  44. package/dist/types/components/plugins/@antd/item-props/SwitchProps.d.ts +6 -0
  45. package/dist/types/components/plugins/@antd/item-props/TableProps.d.ts +15 -0
  46. package/dist/types/components/plugins/@antd/item-props/TextProps.d.ts +6 -0
  47. package/dist/types/components/plugins/@antd/item-props/index.d.ts +19 -0
  48. package/dist/types/components/plugins/@antd/item-props/types.d.ts +5 -0
  49. package/dist/types/components/plugins/@antd/items/ButtonRender.d.ts +14 -0
  50. package/dist/types/components/plugins/@antd/items/CapsuleRender.d.ts +14 -0
  51. package/dist/types/components/plugins/@antd/items/CardRender.d.ts +12 -0
  52. package/dist/types/components/plugins/@antd/items/CheckboxRender.d.ts +14 -0
  53. package/dist/types/components/plugins/@antd/items/ColRender.d.ts +13 -0
  54. package/dist/types/components/plugins/@antd/items/DatePickerRender.d.ts +14 -0
  55. package/dist/types/components/plugins/@antd/items/EchartsRender.d.ts +10 -0
  56. package/dist/types/components/plugins/@antd/items/HtmlRender.d.ts +20 -0
  57. package/dist/types/components/plugins/@antd/items/ImageRender.d.ts +10 -0
  58. package/dist/types/components/plugins/@antd/items/InputNumberRender.d.ts +17 -0
  59. package/dist/types/components/plugins/@antd/items/InputRender.d.ts +17 -0
  60. package/dist/types/components/plugins/@antd/items/ListRender.d.ts +11 -0
  61. package/dist/types/components/plugins/@antd/items/PageHeaderRender.d.ts +8 -0
  62. package/dist/types/components/plugins/@antd/items/RowRender.d.ts +13 -0
  63. package/dist/types/components/plugins/@antd/items/SelectRender.d.ts +18 -0
  64. package/dist/types/components/plugins/@antd/items/SpaceRender.d.ts +10 -0
  65. package/dist/types/components/plugins/@antd/items/SwitchRender.d.ts +14 -0
  66. package/dist/types/components/plugins/@antd/items/TableRender.d.ts +12 -0
  67. package/dist/types/components/plugins/@antd/items/TextRender.d.ts +9 -0
  68. package/dist/types/components/plugins/@antd/items/index.d.ts +19 -0
  69. package/dist/types/components/typing.d.ts +80 -0
  70. package/dist/types/components/utils.d.ts +9 -0
  71. package/dist/types/example.d.ts +2 -0
  72. package/dist/types/index.d.ts +1 -0
  73. package/dist/umd/css/bi-sdk.css +1 -0
  74. package/dist/umd/js/bi-sdk.umd.min.js +795 -0
  75. package/dist/umd/js/bi-sdk.umd.min.js.LICENSE.txt +9 -0
  76. package/package.json +52 -0
  77. package/src/components/PageDesigner.tsx +509 -0
  78. package/src/components/context/DesignerContext.tsx +71 -0
  79. package/src/components/context/EnvContext.tsx +42 -0
  80. package/src/components/dnd/DropContainer.tsx +474 -0
  81. package/src/components/example.ts +577 -0
  82. package/src/components/hooks/datasource.ts +23 -0
  83. package/src/components/hooks/useDeepCompareEffect.ts +12 -0
  84. package/src/components/icon/IconFont.tsx +16 -0
  85. package/src/components/index.ts +29 -0
  86. package/src/components/layout/PageCanvas.tsx +145 -0
  87. package/src/components/layout/PageItem.tsx +182 -0
  88. package/src/components/panel/AiPanel.tsx +116 -0
  89. package/src/components/panel/CascadePanel.tsx +163 -0
  90. package/src/components/panel/ChatInput.tsx +550 -0
  91. package/src/components/panel/CodePanel.tsx +48 -0
  92. package/src/components/panel/ComponentPanel.tsx +119 -0
  93. package/src/components/panel/DatasourcePanel.tsx +419 -0
  94. package/src/components/panel/LayerPanel.tsx +238 -0
  95. package/src/components/panel/PaneHeader.tsx +34 -0
  96. package/src/components/panel/PropertiesPanel.tsx +394 -0
  97. package/src/components/panel/ScriptPanel.tsx +175 -0
  98. package/src/components/panel/VariablesPanel.tsx +153 -0
  99. package/src/components/panel/index.ts +9 -0
  100. package/src/components/plugins/@antd/index.ts +445 -0
  101. package/src/components/plugins/@antd/item-props/ButtonProps.tsx +91 -0
  102. package/src/components/plugins/@antd/item-props/CapsuleProps.tsx +102 -0
  103. package/src/components/plugins/@antd/item-props/CardProps.tsx +58 -0
  104. package/src/components/plugins/@antd/item-props/CheckboxProps.tsx +75 -0
  105. package/src/components/plugins/@antd/item-props/ColProps.tsx +43 -0
  106. package/src/components/plugins/@antd/item-props/DatePickerProps.tsx +72 -0
  107. package/src/components/plugins/@antd/item-props/EchartsProps.tsx +35 -0
  108. package/src/components/plugins/@antd/item-props/HtmlProps.tsx +61 -0
  109. package/src/components/plugins/@antd/item-props/ImageProps.tsx +43 -0
  110. package/src/components/plugins/@antd/item-props/InputNumberProps.tsx +18 -0
  111. package/src/components/plugins/@antd/item-props/InputProps.tsx +89 -0
  112. package/src/components/plugins/@antd/item-props/ListProps.tsx +69 -0
  113. package/src/components/plugins/@antd/item-props/PageHeaderProps.tsx +20 -0
  114. package/src/components/plugins/@antd/item-props/RowProps.tsx +21 -0
  115. package/src/components/plugins/@antd/item-props/SelectProps.tsx +136 -0
  116. package/src/components/plugins/@antd/item-props/SpaceProps.tsx +52 -0
  117. package/src/components/plugins/@antd/item-props/SwitchProps.tsx +17 -0
  118. package/src/components/plugins/@antd/item-props/TableProps.tsx +200 -0
  119. package/src/components/plugins/@antd/item-props/TextProps.tsx +41 -0
  120. package/src/components/plugins/@antd/item-props/index.ts +20 -0
  121. package/src/components/plugins/@antd/item-props/types.ts +6 -0
  122. package/src/components/plugins/@antd/items/ButtonRender.tsx +63 -0
  123. package/src/components/plugins/@antd/items/CapsuleRender.tsx +49 -0
  124. package/src/components/plugins/@antd/items/CardRender.tsx +119 -0
  125. package/src/components/plugins/@antd/items/CheckboxRender.tsx +56 -0
  126. package/src/components/plugins/@antd/items/ColRender.tsx +78 -0
  127. package/src/components/plugins/@antd/items/DatePickerRender.tsx +117 -0
  128. package/src/components/plugins/@antd/items/EchartsRender.tsx +98 -0
  129. package/src/components/plugins/@antd/items/HtmlRender.tsx +74 -0
  130. package/src/components/plugins/@antd/items/ImageRender.tsx +37 -0
  131. package/src/components/plugins/@antd/items/InputNumberRender.tsx +57 -0
  132. package/src/components/plugins/@antd/items/InputRender.tsx +75 -0
  133. package/src/components/plugins/@antd/items/ListRender.tsx +227 -0
  134. package/src/components/plugins/@antd/items/PageHeaderRender.tsx +74 -0
  135. package/src/components/plugins/@antd/items/RowRender.tsx +47 -0
  136. package/src/components/plugins/@antd/items/SelectRender.tsx +53 -0
  137. package/src/components/plugins/@antd/items/SpaceRender.tsx +54 -0
  138. package/src/components/plugins/@antd/items/SwitchRender.tsx +52 -0
  139. package/src/components/plugins/@antd/items/TableRender.tsx +99 -0
  140. package/src/components/plugins/@antd/items/TextRender.tsx +25 -0
  141. package/src/components/plugins/@antd/items/index.ts +20 -0
  142. package/src/components/styles.css +12 -0
  143. package/src/components/typing.ts +80 -0
  144. package/src/components/utils.ts +37 -0
  145. package/src/example.tsx +136 -0
  146. package/src/index.tsx +17 -0
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license React
3
+ * react-jsx-runtime.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "bi-sdk-react",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "dist/umd/js/bi-sdk.umd.min.js",
7
+ "module": "dist/es/js/bi-sdk.es.js",
8
+ "es": "dist/es/js/bi-sdk.es.js",
9
+ "types": "dist/types/components/index.d.ts",
10
+ "scripts": {
11
+ "serve": "rsbuild dev",
12
+ "dev": "rsbuild dev",
13
+ "build": "rsbuild build",
14
+ "build:types": "tsc --emitDeclarationOnly",
15
+ "build:lib": "npm run build:lib:umd && npm run build:lib:es",
16
+ "build:lib:umd": "cross-env NODE_ENV=production BUILD_TARGET=lib rsbuild build --config rsbuild.lib.config.ts",
17
+ "build:lib:es": "cross-env NODE_ENV=production BUILD_TARGET=lib rsbuild build --config rsbuild.es.config.ts",
18
+ "preview": "rsbuild preview"
19
+ },
20
+ "dependencies": {
21
+ "@ant-design/icons": "^6.1.0",
22
+ "@atlaskit/pragmatic-drag-and-drop": "^1.7.7",
23
+ "@monaco-editor/react": "^4.6.0",
24
+ "antd": "^6.1.1",
25
+ "copy-to-clipboard": "^3.3.3",
26
+ "dayjs": "^1.11.13",
27
+ "echarts": "^5.5.0",
28
+ "react": "^18",
29
+ "react-dom": "^18",
30
+ "styled-components": "^6.1.13",
31
+ "uuid": "^13.0.0",
32
+ "xlsx": "^0.18.5"
33
+ },
34
+ "devDependencies": {
35
+ "@rsbuild/core": "^1.5.0",
36
+ "@rsbuild/plugin-react": "^1.4.0",
37
+ "@types/react": "^18.3.12",
38
+ "@types/react-dom": "^18.3.2",
39
+ "cross-env": "^10.1.0",
40
+ "typescript": "^5.6.3"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^18",
44
+ "react-dom": "^18"
45
+ },
46
+ "files": [
47
+ "dist",
48
+ "src",
49
+ "package.json",
50
+ "README.md"
51
+ ]
52
+ }
@@ -0,0 +1,509 @@
1
+ import {
2
+ DesktopOutlined,
3
+ EyeInvisibleOutlined,
4
+ EyeOutlined,
5
+ MobileOutlined,
6
+ RedoOutlined,
7
+ SaveOutlined,
8
+ TabletOutlined,
9
+ UndoOutlined,
10
+ ZoomInOutlined,
11
+ ZoomOutOutlined,
12
+ } from "@ant-design/icons";
13
+ import { Button, Divider, Radio, Space, Tooltip } from "antd";
14
+ import React, {
15
+ useEffect,
16
+ useImperativeHandle,
17
+ useMemo,
18
+ useRef,
19
+ useState,
20
+ } from "react";
21
+ import styled from "styled-components";
22
+ import { IconFont } from "./icon/IconFont";
23
+ import { PageCanvas } from "./layout/PageCanvas";
24
+ import { AiPanel } from "./panel/AiPanel";
25
+ import { CascadePanel } from "./panel/CascadePanel";
26
+ import { CodePanel } from "./panel/CodePanel";
27
+ import { ComponentPanel } from "./panel/ComponentPanel";
28
+ import { DatasourcePanel } from "./panel/DatasourcePanel";
29
+ import { LayerPanel } from "./panel/LayerPanel";
30
+ import { PaneHeader } from "./panel/PaneHeader";
31
+ import { PropertiesPanel } from "./panel/PropertiesPanel";
32
+ import { ScriptPanel } from "./panel/ScriptPanel";
33
+ import { VariablesPanel } from "./panel/VariablesPanel";
34
+
35
+ import { PageSchema, PluginType } from "./typing";
36
+ import { DesignerProvider } from "./context/DesignerContext";
37
+ import { useDeepCompareEffect } from "./hooks/useDeepCompareEffect";
38
+ import "./styles.css";
39
+
40
+ export type PageDesignerProps = {
41
+ agentList?: any[];
42
+ plugins?: PluginType[];
43
+ headerExtra?: React.ReactNode;
44
+ };
45
+
46
+ const Container = styled.div`
47
+ height: 100%;
48
+ display: grid;
49
+ background: #ffffff;
50
+ * {
51
+ box-sizing: border-box;
52
+ }
53
+ & > div {
54
+ height: calc(100vh - 40px);
55
+ display: flex;
56
+ flex-direction: column;
57
+ }
58
+ & > .center {
59
+ background: #ebe7e7;
60
+ align-items: center;
61
+ min-width: 0;
62
+
63
+ .body {
64
+ flex: 1 1 auto;
65
+ overflow: auto;
66
+ position: relative;
67
+ background: #f3f3f3;
68
+ box-sizing: border-box;
69
+ max-width: 100%;
70
+ }
71
+ .body.desktop {
72
+ width: 100%;
73
+ }
74
+ .body.mobile,
75
+ .body.tablet {
76
+ padding: 0;
77
+ margin-top: 20px;
78
+ margin-bottom: 20px;
79
+ border-radius: 8px;
80
+ }
81
+ .body.tablet {
82
+ width: 1024px;
83
+ }
84
+ .body.mobile {
85
+ width: 430px;
86
+ }
87
+ }
88
+
89
+ & > .left,
90
+ & > .right {
91
+ transition: all 0.25s ease-in-out;
92
+ overflow: hidden;
93
+ }
94
+ & > .left {
95
+ border-right: 1px solid #e8e8e8;
96
+ display: flex;
97
+ flex-direction: row;
98
+ }
99
+ & > .left .body {
100
+ flex: 1 1 auto;
101
+ overflow: auto;
102
+ }
103
+ & > .right {
104
+ display: flex;
105
+ flex-direction: row;
106
+ border-left: 1px solid #e8e8e8;
107
+ }
108
+ & > .right .body {
109
+ flex: 1 1 auto;
110
+ display: flex;
111
+ flex-direction: column;
112
+ gap: 12px;
113
+ padding: 12px;
114
+ }
115
+ .left-pane-tabs > label,
116
+ .right-pane-tabs > label {
117
+ border: none;
118
+ height: 32px;
119
+ padding: 7px;
120
+ font-size: 20px;
121
+ padding: 0 12px;
122
+ border-radius: 0;
123
+
124
+ &:not(:first-child)::before {
125
+ content: none;
126
+ }
127
+ }
128
+ .left-pane-tabs > label.ant-radio-button-wrapper-checked {
129
+ border-left: solid 2px #1890ff;
130
+ background: linear-gradient(to right, #1890ff1a, #ffffff);
131
+ }
132
+ .right-pane-tabs > label.ant-radio-button-wrapper-checked {
133
+ border-right: solid 2px #1890ff;
134
+ background: linear-gradient(to left, #1890ff1a, #ffffff);
135
+ }
136
+ `;
137
+
138
+ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
139
+ ({ agentList = [], plugins = [], headerExtra }, ref) => {
140
+ const pageCanvasRef = useRef<any>(null);
141
+ const [zoom, setZoom] = useState(1);
142
+ const [history, setHistory] = useState<any[]>([]);
143
+ const [future, setFuture] = useState<any[]>([]);
144
+ const [isReplaying, setIsReplaying] = useState(false);
145
+ const [deviceType, setDeviceType] = useState<
146
+ "desktop" | "mobile" | "tablet"
147
+ >("desktop");
148
+ const [leftPanelActiveKey, setLeftPanelActiveKey] = useState<
149
+ "component" | "layer" | "datasource" | "script" | "env" | "code"
150
+ >("component");
151
+ const [rightPanelActiveKey, setRightPanelActiveKey] = useState<
152
+ "ai" | "props" | "cascade"
153
+ >("ai");
154
+ const [showLeft, setShowLeft] = useState(true);
155
+ const [showRight, setShowRight] = useState(true);
156
+ const [selectedItem, setSelectedItem] = useState<any>(null);
157
+ const [schema, setSchema] = useState<PageSchema>({
158
+ info: {},
159
+ datasources: [],
160
+ scripts: [],
161
+ variables: [],
162
+ items: [],
163
+ });
164
+ const [designable, setDesignable] = useState(true);
165
+ const containerStyle = useMemo(() => {
166
+ const left = showLeft ? "250px" : "";
167
+ const right = showRight ? "400px" : "";
168
+ return { gridTemplateColumns: `${left} 1fr ${right}` };
169
+ }, [showLeft, showRight]);
170
+ const leftStyle = useMemo(
171
+ () => ({ display: showLeft ? "flex" : "none" }),
172
+ [showLeft]
173
+ );
174
+ const rightStyle = useMemo(
175
+ () => ({ display: showRight ? "flex" : "none" }),
176
+ [showRight]
177
+ );
178
+ useDeepCompareEffect(() => {
179
+ if (isReplaying) return;
180
+ setHistory((h) => {
181
+ if (!h.length) return [JSON.parse(JSON.stringify(schema))];
182
+ return [...h, JSON.parse(JSON.stringify(schema))].slice(-50);
183
+ });
184
+ setFuture([]);
185
+ }, [schema]);
186
+
187
+ useImperativeHandle(ref, () => ({
188
+ handleOpen(s: PageSchema) {
189
+ setIsReplaying(true);
190
+ ensureIds(s.items);
191
+ setSchema(s);
192
+ setHistory([JSON.parse(JSON.stringify(s))]);
193
+ setFuture([]);
194
+ setTimeout(() => setIsReplaying(false), 0);
195
+ },
196
+ }));
197
+ const ensureIds = (items?: any[], id?: string) => {
198
+ if (!items) return;
199
+ items.forEach((item) => {
200
+ if (!item.id) {
201
+ item.id = id || Math.random().toString(36).slice(2, 10);
202
+ }
203
+ if (Array.isArray(item.children)) {
204
+ ensureIds(item.children);
205
+ } else if (typeof item.children === "object" && item.children) {
206
+ Object.keys(item.children).forEach((k) => {
207
+ if (Array.isArray(item.children[k])) {
208
+ ensureIds(
209
+ item.children[k],
210
+ Math.random().toString(36).slice(2, 10)
211
+ );
212
+ }
213
+ });
214
+ }
215
+ });
216
+ };
217
+ const handleUndo = () => {
218
+ setHistory((h) => {
219
+ if (h.length <= 1) return h;
220
+ setIsReplaying(true);
221
+ const prev = h[h.length - 2];
222
+ setFuture((f) => [...f, JSON.parse(JSON.stringify(schema))]);
223
+ setSchema(prev);
224
+ setSelectedItem(null);
225
+ setTimeout(() => setIsReplaying(false), 0);
226
+ return h.slice(0, -1);
227
+ });
228
+ };
229
+ const handleRedo = () => {
230
+ setFuture((f) => {
231
+ if (!f.length) return f;
232
+ setIsReplaying(true);
233
+ setHistory((h) => [...h, JSON.parse(JSON.stringify(schema))]);
234
+ const next = f[f.length - 1];
235
+ setSchema(next);
236
+ setSelectedItem(null);
237
+ setTimeout(() => setIsReplaying(false), 0);
238
+ return f.slice(0, -1);
239
+ });
240
+ };
241
+ const handleZoomIn = () =>
242
+ setZoom(parseFloat(Math.min(zoom + 0.1, 2).toFixed(1)));
243
+ const handleZoomOut = () =>
244
+ setZoom(parseFloat(Math.max(zoom - 0.1, 0.5).toFixed(1)));
245
+ const handleZoomReset = () => setZoom(1);
246
+ const toggleLeft = () => {
247
+ setShowLeft((s) => !s);
248
+ setTimeout(() => pageCanvasRef.current?.handleResize?.(), 0);
249
+ };
250
+ const toggleRight = () => {
251
+ setShowRight((s) => !s);
252
+ setTimeout(() => pageCanvasRef.current?.handleResize?.(), 0);
253
+ };
254
+
255
+ return (
256
+ <DesignerProvider
257
+ designable={designable}
258
+ plugins={plugins}
259
+ schema={schema}
260
+ selectedItem={selectedItem}
261
+ setSchema={setSchema}
262
+ setSelectedItem={setSelectedItem}
263
+ >
264
+ <div
265
+ style={{ display: "flex", flexDirection: "column", height: "100%" }}
266
+ >
267
+ <div
268
+ style={{
269
+ display: "flex",
270
+ alignItems: "center",
271
+ justifyContent: "space-between",
272
+ padding: "8px 24px",
273
+ borderBottom: "solid 1px #e8e8e8",
274
+ }}
275
+ >
276
+ <Space>
277
+ <span style={{ fontSize: 16, fontWeight: 500 }}>
278
+ 创建数据报表
279
+ </span>
280
+ <Divider orientation="vertical" />
281
+ <Tooltip title="保存">
282
+ <a className="toolbar">
283
+ <SaveOutlined />
284
+ </a>
285
+ </Tooltip>
286
+ <Divider orientation="vertical" />
287
+ <Tooltip title="撤销">
288
+ <a
289
+ className={`toolbar ${history.length > 1 ? "active" : ""}`}
290
+ onClick={handleUndo}
291
+ >
292
+ <UndoOutlined />
293
+ </a>
294
+ </Tooltip>
295
+ <Tooltip title="重做">
296
+ <a
297
+ className={`toolbar ${future.length > 0 ? "active" : ""}`}
298
+ onClick={handleRedo}
299
+ >
300
+ <RedoOutlined />
301
+ </a>
302
+ </Tooltip>
303
+ </Space>
304
+ <Space>
305
+ <Tooltip title="缩小">
306
+ <a className="toolbar" onClick={handleZoomOut}>
307
+ <ZoomOutOutlined />
308
+ </a>
309
+ </Tooltip>
310
+ <div style={{ fontSize: 12, color: "#999", userSelect: "none" }}>
311
+ {(zoom * 100).toFixed(0)}%
312
+ </div>
313
+ <Tooltip title="放大">
314
+ <a className="toolbar" onClick={handleZoomIn}>
315
+ <ZoomInOutlined />
316
+ </a>
317
+ </Tooltip>
318
+ <Tooltip title="重置缩放">
319
+ <a className="toolbar" onClick={handleZoomReset}>
320
+ <IconFont type="icon-zoom-reset" />
321
+ </a>
322
+ </Tooltip>
323
+ <Divider orientation="vertical" />
324
+ <Tooltip title="切换左侧栏">
325
+ <a
326
+ className={`toolbar ${showLeft ? "active" : ""}`}
327
+ onClick={toggleLeft}
328
+ >
329
+ <IconFont type="icon-sider-l" />
330
+ </a>
331
+ </Tooltip>
332
+ <Tooltip title="切换右侧栏">
333
+ <a
334
+ className={`toolbar ${showRight ? "active" : ""}`}
335
+ onClick={toggleRight}
336
+ >
337
+ <IconFont type="icon-sider-r" />
338
+ </a>
339
+ </Tooltip>
340
+ {headerExtra}
341
+ </Space>
342
+ </div>
343
+ <Container style={containerStyle as any}>
344
+ <div className="left" style={leftStyle as any}>
345
+ <div
346
+ style={{
347
+ padding: "22px 1px 22px 0",
348
+ borderRight: "solid 1px #e8e8e8",
349
+ }}
350
+ >
351
+ <Radio.Group
352
+ value={leftPanelActiveKey}
353
+ onChange={(e) => setLeftPanelActiveKey(e.target.value)}
354
+ buttonStyle="outline"
355
+ style={{
356
+ fontWeight: "normal",
357
+ display: "inline-flex",
358
+ flexDirection: "column",
359
+ gap: 14,
360
+ }}
361
+ className="left-pane-tabs"
362
+ >
363
+ <Radio.Button value="component">
364
+ <Tooltip title="组件" placement="right">
365
+ <IconFont type="icon-puzzle" />
366
+ </Tooltip>
367
+ </Radio.Button>
368
+ <Radio.Button value="layer">
369
+ <Tooltip title="图层" placement="right">
370
+ <IconFont type="icon-outline" />
371
+ </Tooltip>
372
+ </Radio.Button>
373
+ <Radio.Button value="datasource">
374
+ <Tooltip title="数据集" placement="right">
375
+ <IconFont type="icon-datasource" />
376
+ </Tooltip>
377
+ </Radio.Button>
378
+ <Radio.Button value="script">
379
+ <Tooltip title="脚本" placement="right">
380
+ <IconFont type="icon-js" />
381
+ </Tooltip>
382
+ </Radio.Button>
383
+ <Radio.Button value="env">
384
+ <Tooltip title="环境变量" placement="right">
385
+ <IconFont type="icon-variable" />
386
+ </Tooltip>
387
+ </Radio.Button>
388
+ <Radio.Button value="code">
389
+ <Tooltip title="源码" placement="right">
390
+ <IconFont type="icon-json" />
391
+ </Tooltip>
392
+ </Radio.Button>
393
+ </Radio.Group>
394
+ </div>
395
+ <div
396
+ style={{
397
+ flex: "1 1 auto",
398
+ display: "flex",
399
+ flexDirection: "column",
400
+ width: "calc(100% - 47px)",
401
+ }}
402
+ >
403
+ {leftPanelActiveKey === "component" && <ComponentPanel />}
404
+ {leftPanelActiveKey === "layer" && <LayerPanel />}
405
+ {leftPanelActiveKey === "datasource" && <DatasourcePanel />}
406
+ {leftPanelActiveKey === "script" && <ScriptPanel />}
407
+ {leftPanelActiveKey === "env" && <VariablesPanel />}
408
+ {leftPanelActiveKey === "code" && <CodePanel />}
409
+ </div>
410
+ </div>
411
+ <div className="center" style={{ flex: "1 1 auto" }}>
412
+ <PaneHeader
413
+ title="页面"
414
+ extra={
415
+ <Space>
416
+ <Button
417
+ size="small"
418
+ type={!designable ? "primary" : "default"}
419
+ icon={
420
+ designable ? <EyeInvisibleOutlined /> : <EyeOutlined />
421
+ }
422
+ onClick={() => setDesignable(!designable)}
423
+ />
424
+ <Radio.Group
425
+ value={deviceType}
426
+ onChange={(e) => setDeviceType(e.target.value)}
427
+ size="small"
428
+ buttonStyle="outline"
429
+ >
430
+ <Radio.Button value="desktop" title="桌面">
431
+ <DesktopOutlined />
432
+ </Radio.Button>
433
+ <Radio.Button value="mobile" title="移动设备">
434
+ <MobileOutlined />
435
+ </Radio.Button>
436
+ <Radio.Button value="tablet" title="平板设备">
437
+ <TabletOutlined />
438
+ </Radio.Button>
439
+ </Radio.Group>
440
+ </Space>
441
+ }
442
+ />
443
+ <div className={["body", deviceType].join(" ")}>
444
+ <div
445
+ style={{
446
+ transform: `scale(${zoom})`,
447
+ transformOrigin: "top center",
448
+ }}
449
+ >
450
+ <PageCanvas ref={pageCanvasRef} device={deviceType} />
451
+ </div>
452
+ </div>
453
+ </div>
454
+ <div className="right" style={rightStyle as any}>
455
+ <div
456
+ style={{
457
+ flex: "1 1 auto",
458
+ display: "flex",
459
+ flexDirection: "column",
460
+ width: "calc(100% - 47px)",
461
+ }}
462
+ >
463
+ {rightPanelActiveKey === "ai" && (
464
+ <AiPanel agentList={agentList} />
465
+ )}
466
+ {rightPanelActiveKey === "props" && <PropertiesPanel />}
467
+ {rightPanelActiveKey === "cascade" && <CascadePanel />}
468
+ </div>
469
+ <div
470
+ style={{ padding: "22px 0", borderLeft: "solid 1px #e8e8e8" }}
471
+ >
472
+ <Radio.Group
473
+ value={rightPanelActiveKey}
474
+ onChange={(e) => setRightPanelActiveKey(e.target.value)}
475
+ buttonStyle="outline"
476
+ style={{
477
+ fontWeight: "normal",
478
+ display: "inline-flex",
479
+ flexDirection: "column",
480
+ gap: 14,
481
+ }}
482
+ className="right-pane-tabs"
483
+ >
484
+ <Radio.Button value="ai">
485
+ <Tooltip title="智能体" placement="right">
486
+ <IconFont type="icon-assistant" />
487
+ </Tooltip>
488
+ </Radio.Button>
489
+ <Radio.Button value="props">
490
+ <Tooltip title="属性" placement="right">
491
+ <IconFont type="icon-info" />
492
+ </Tooltip>
493
+ </Radio.Button>
494
+ <Radio.Button value="cascade">
495
+ <Tooltip title="联动" placement="right">
496
+ <IconFont type="icon-cascade" />
497
+ </Tooltip>
498
+ </Radio.Button>
499
+ </Radio.Group>
500
+ </div>
501
+ </div>
502
+ </Container>
503
+ </div>
504
+ </DesignerProvider>
505
+ );
506
+ }
507
+ );
508
+
509
+ export default PageDesigner;
@@ -0,0 +1,71 @@
1
+ import { createContext } from "react";
2
+ import { PageSchema, PluginType, SchemaItemType } from "../typing";
3
+
4
+ type DesignerContextType = {
5
+ designable: boolean;
6
+ plugins: PluginType[];
7
+ schema: PageSchema;
8
+ selectedItem?: SchemaItemType | null;
9
+ setSchema: React.Dispatch<React.SetStateAction<PageSchema>>;
10
+ setSelectedItem: React.Dispatch<React.SetStateAction<SchemaItemType | null>>;
11
+ updateSelectedItem: (selectedItem?: Partial<SchemaItemType> | null) => void;
12
+ forceUpdate: () => void;
13
+ };
14
+
15
+ export const DesignerContext = createContext<DesignerContextType>({
16
+ designable: false,
17
+ plugins: [],
18
+ schema: {
19
+ info: {},
20
+ datasources: [],
21
+ scripts: [],
22
+ variables: [],
23
+ items: [],
24
+ },
25
+ selectedItem: null,
26
+ setSchema: () => {},
27
+ setSelectedItem: () => {},
28
+ updateSelectedItem: () => {},
29
+ forceUpdate: () => {},
30
+ });
31
+
32
+ type DesignerProviderProps = React.PropsWithChildren<
33
+ Omit<
34
+ Partial<DesignerContextType>,
35
+ "updateSelectedItem" | "schema" | "forceUpdate"
36
+ > &
37
+ Pick<DesignerContextType, "schema">
38
+ >;
39
+
40
+ export const DesignerProvider: React.FC<DesignerProviderProps> = ({
41
+ designable,
42
+ plugins,
43
+ schema,
44
+ selectedItem,
45
+ setSchema,
46
+ setSelectedItem,
47
+ children,
48
+ }) => {
49
+ const updateSelectedItem = (props?: Partial<SchemaItemType> | null) => {
50
+ setSelectedItem?.(Object.assign(selectedItem!, props || {}));
51
+ setSchema?.({ ...schema });
52
+ };
53
+ return (
54
+ <DesignerContext.Provider
55
+ value={{
56
+ designable: !!designable,
57
+ plugins: plugins || [],
58
+ schema,
59
+ selectedItem,
60
+ setSchema: setSchema || (() => {}),
61
+ setSelectedItem: setSelectedItem || (() => {}),
62
+ updateSelectedItem,
63
+ forceUpdate: () => {
64
+ setSchema?.({ ...schema });
65
+ },
66
+ }}
67
+ >
68
+ {children}
69
+ </DesignerContext.Provider>
70
+ );
71
+ };
@@ -0,0 +1,42 @@
1
+ import { createContext, FC, PropsWithChildren } from "react";
2
+ import { CallbacksType, EnvType } from "../typing";
3
+
4
+ type InitCallbackParams = {
5
+ id: string;
6
+ callback: (v: any) => void;
7
+ };
8
+
9
+ type EnvContextType = {
10
+ deviceWidth: number;
11
+ env: EnvType;
12
+ callbacks: CallbacksType;
13
+ initCallback: ({ id, callback }: InitCallbackParams) => void;
14
+ };
15
+
16
+ export const EnvContext = createContext<EnvContextType>({
17
+ deviceWidth: 0,
18
+ env: { global: {}, local: {} },
19
+ callbacks: {},
20
+ initCallback: ({ id, callback }) => {},
21
+ });
22
+
23
+ export const EnvProvider: FC<PropsWithChildren<EnvContextType>> = ({
24
+ deviceWidth,
25
+ env,
26
+ callbacks,
27
+ initCallback,
28
+ children,
29
+ }) => {
30
+ return (
31
+ <EnvContext.Provider
32
+ value={{
33
+ deviceWidth,
34
+ env,
35
+ callbacks,
36
+ initCallback,
37
+ }}
38
+ >
39
+ {children}
40
+ </EnvContext.Provider>
41
+ );
42
+ };