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.
- package/dist/es/css/bi-sdk.css +1 -0
- package/dist/es/js/bi-sdk.es.js +795 -0
- package/dist/es/js/bi-sdk.es.js.LICENSE.txt +9 -0
- package/dist/types/components/PageDesigner.d.ts +10 -0
- package/dist/types/components/context/DesignerContext.d.ts +15 -0
- package/dist/types/components/context/EnvContext.d.ts +15 -0
- package/dist/types/components/dnd/DropContainer.d.ts +21 -0
- package/dist/types/components/example.d.ts +225 -0
- package/dist/types/components/hooks/datasource.d.ts +1 -0
- package/dist/types/components/hooks/useDeepCompareEffect.d.ts +1 -0
- package/dist/types/components/icon/IconFont.d.ts +6 -0
- package/dist/types/components/index.d.ts +10 -0
- package/dist/types/components/layout/PageCanvas.d.ts +6 -0
- package/dist/types/components/layout/PageItem.d.ts +27 -0
- package/dist/types/components/panel/AiPanel.d.ts +8 -0
- package/dist/types/components/panel/CascadePanel.d.ts +2 -0
- package/dist/types/components/panel/ChatInput.d.ts +28 -0
- package/dist/types/components/panel/CodePanel.d.ts +2 -0
- package/dist/types/components/panel/ComponentPanel.d.ts +2 -0
- package/dist/types/components/panel/DatasourcePanel.d.ts +2 -0
- package/dist/types/components/panel/LayerPanel.d.ts +2 -0
- package/dist/types/components/panel/PaneHeader.d.ts +6 -0
- package/dist/types/components/panel/PropertiesPanel.d.ts +2 -0
- package/dist/types/components/panel/ScriptPanel.d.ts +2 -0
- package/dist/types/components/panel/VariablesPanel.d.ts +2 -0
- package/dist/types/components/panel/index.d.ts +9 -0
- package/dist/types/components/plugins/@antd/index.d.ts +22 -0
- package/dist/types/components/plugins/@antd/item-props/ButtonProps.d.ts +8 -0
- package/dist/types/components/plugins/@antd/item-props/CapsuleProps.d.ts +13 -0
- package/dist/types/components/plugins/@antd/item-props/CardProps.d.ts +8 -0
- package/dist/types/components/plugins/@antd/item-props/CheckboxProps.d.ts +13 -0
- package/dist/types/components/plugins/@antd/item-props/ColProps.d.ts +12 -0
- package/dist/types/components/plugins/@antd/item-props/DatePickerProps.d.ts +8 -0
- package/dist/types/components/plugins/@antd/item-props/EchartsProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/HtmlProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/ImageProps.d.ts +10 -0
- package/dist/types/components/plugins/@antd/item-props/InputNumberProps.d.ts +9 -0
- package/dist/types/components/plugins/@antd/item-props/InputProps.d.ts +10 -0
- package/dist/types/components/plugins/@antd/item-props/ListProps.d.ts +10 -0
- package/dist/types/components/plugins/@antd/item-props/PageHeaderProps.d.ts +7 -0
- package/dist/types/components/plugins/@antd/item-props/RowProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/SelectProps.d.ts +16 -0
- package/dist/types/components/plugins/@antd/item-props/SpaceProps.d.ts +7 -0
- package/dist/types/components/plugins/@antd/item-props/SwitchProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/TableProps.d.ts +15 -0
- package/dist/types/components/plugins/@antd/item-props/TextProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/index.d.ts +19 -0
- package/dist/types/components/plugins/@antd/item-props/types.d.ts +5 -0
- package/dist/types/components/plugins/@antd/items/ButtonRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/CapsuleRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/CardRender.d.ts +12 -0
- package/dist/types/components/plugins/@antd/items/CheckboxRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/ColRender.d.ts +13 -0
- package/dist/types/components/plugins/@antd/items/DatePickerRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/EchartsRender.d.ts +10 -0
- package/dist/types/components/plugins/@antd/items/HtmlRender.d.ts +20 -0
- package/dist/types/components/plugins/@antd/items/ImageRender.d.ts +10 -0
- package/dist/types/components/plugins/@antd/items/InputNumberRender.d.ts +17 -0
- package/dist/types/components/plugins/@antd/items/InputRender.d.ts +17 -0
- package/dist/types/components/plugins/@antd/items/ListRender.d.ts +11 -0
- package/dist/types/components/plugins/@antd/items/PageHeaderRender.d.ts +8 -0
- package/dist/types/components/plugins/@antd/items/RowRender.d.ts +13 -0
- package/dist/types/components/plugins/@antd/items/SelectRender.d.ts +18 -0
- package/dist/types/components/plugins/@antd/items/SpaceRender.d.ts +10 -0
- package/dist/types/components/plugins/@antd/items/SwitchRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/TableRender.d.ts +12 -0
- package/dist/types/components/plugins/@antd/items/TextRender.d.ts +9 -0
- package/dist/types/components/plugins/@antd/items/index.d.ts +19 -0
- package/dist/types/components/typing.d.ts +80 -0
- package/dist/types/components/utils.d.ts +9 -0
- package/dist/types/example.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/umd/css/bi-sdk.css +1 -0
- package/dist/umd/js/bi-sdk.umd.min.js +795 -0
- package/dist/umd/js/bi-sdk.umd.min.js.LICENSE.txt +9 -0
- package/package.json +52 -0
- package/src/components/PageDesigner.tsx +509 -0
- package/src/components/context/DesignerContext.tsx +71 -0
- package/src/components/context/EnvContext.tsx +42 -0
- package/src/components/dnd/DropContainer.tsx +474 -0
- package/src/components/example.ts +577 -0
- package/src/components/hooks/datasource.ts +23 -0
- package/src/components/hooks/useDeepCompareEffect.ts +12 -0
- package/src/components/icon/IconFont.tsx +16 -0
- package/src/components/index.ts +29 -0
- package/src/components/layout/PageCanvas.tsx +145 -0
- package/src/components/layout/PageItem.tsx +182 -0
- package/src/components/panel/AiPanel.tsx +116 -0
- package/src/components/panel/CascadePanel.tsx +163 -0
- package/src/components/panel/ChatInput.tsx +550 -0
- package/src/components/panel/CodePanel.tsx +48 -0
- package/src/components/panel/ComponentPanel.tsx +119 -0
- package/src/components/panel/DatasourcePanel.tsx +419 -0
- package/src/components/panel/LayerPanel.tsx +238 -0
- package/src/components/panel/PaneHeader.tsx +34 -0
- package/src/components/panel/PropertiesPanel.tsx +394 -0
- package/src/components/panel/ScriptPanel.tsx +175 -0
- package/src/components/panel/VariablesPanel.tsx +153 -0
- package/src/components/panel/index.ts +9 -0
- package/src/components/plugins/@antd/index.ts +445 -0
- package/src/components/plugins/@antd/item-props/ButtonProps.tsx +91 -0
- package/src/components/plugins/@antd/item-props/CapsuleProps.tsx +102 -0
- package/src/components/plugins/@antd/item-props/CardProps.tsx +58 -0
- package/src/components/plugins/@antd/item-props/CheckboxProps.tsx +75 -0
- package/src/components/plugins/@antd/item-props/ColProps.tsx +43 -0
- package/src/components/plugins/@antd/item-props/DatePickerProps.tsx +72 -0
- package/src/components/plugins/@antd/item-props/EchartsProps.tsx +35 -0
- package/src/components/plugins/@antd/item-props/HtmlProps.tsx +61 -0
- package/src/components/plugins/@antd/item-props/ImageProps.tsx +43 -0
- package/src/components/plugins/@antd/item-props/InputNumberProps.tsx +18 -0
- package/src/components/plugins/@antd/item-props/InputProps.tsx +89 -0
- package/src/components/plugins/@antd/item-props/ListProps.tsx +69 -0
- package/src/components/plugins/@antd/item-props/PageHeaderProps.tsx +20 -0
- package/src/components/plugins/@antd/item-props/RowProps.tsx +21 -0
- package/src/components/plugins/@antd/item-props/SelectProps.tsx +136 -0
- package/src/components/plugins/@antd/item-props/SpaceProps.tsx +52 -0
- package/src/components/plugins/@antd/item-props/SwitchProps.tsx +17 -0
- package/src/components/plugins/@antd/item-props/TableProps.tsx +200 -0
- package/src/components/plugins/@antd/item-props/TextProps.tsx +41 -0
- package/src/components/plugins/@antd/item-props/index.ts +20 -0
- package/src/components/plugins/@antd/item-props/types.ts +6 -0
- package/src/components/plugins/@antd/items/ButtonRender.tsx +63 -0
- package/src/components/plugins/@antd/items/CapsuleRender.tsx +49 -0
- package/src/components/plugins/@antd/items/CardRender.tsx +119 -0
- package/src/components/plugins/@antd/items/CheckboxRender.tsx +56 -0
- package/src/components/plugins/@antd/items/ColRender.tsx +78 -0
- package/src/components/plugins/@antd/items/DatePickerRender.tsx +117 -0
- package/src/components/plugins/@antd/items/EchartsRender.tsx +98 -0
- package/src/components/plugins/@antd/items/HtmlRender.tsx +74 -0
- package/src/components/plugins/@antd/items/ImageRender.tsx +37 -0
- package/src/components/plugins/@antd/items/InputNumberRender.tsx +57 -0
- package/src/components/plugins/@antd/items/InputRender.tsx +75 -0
- package/src/components/plugins/@antd/items/ListRender.tsx +227 -0
- package/src/components/plugins/@antd/items/PageHeaderRender.tsx +74 -0
- package/src/components/plugins/@antd/items/RowRender.tsx +47 -0
- package/src/components/plugins/@antd/items/SelectRender.tsx +53 -0
- package/src/components/plugins/@antd/items/SpaceRender.tsx +54 -0
- package/src/components/plugins/@antd/items/SwitchRender.tsx +52 -0
- package/src/components/plugins/@antd/items/TableRender.tsx +99 -0
- package/src/components/plugins/@antd/items/TextRender.tsx +25 -0
- package/src/components/plugins/@antd/items/index.ts +20 -0
- package/src/components/styles.css +12 -0
- package/src/components/typing.ts +80 -0
- package/src/components/utils.ts +37 -0
- package/src/example.tsx +136 -0
- package/src/index.tsx +17 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useContext,
|
|
3
|
+
useEffect,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from "react";
|
|
9
|
+
import styled from "styled-components";
|
|
10
|
+
import { DropContainer } from "../dnd/DropContainer";
|
|
11
|
+
import { CallbacksType, EnvType } from "../typing";
|
|
12
|
+
import { DesignerContext } from "../context/DesignerContext";
|
|
13
|
+
import { EnvProvider } from "../context/EnvContext";
|
|
14
|
+
|
|
15
|
+
export type PageCanvasProps = {
|
|
16
|
+
device?: "desktop" | "mobile" | "tablet";
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const Wrapper = styled.div`
|
|
20
|
+
.empty-container.designable {
|
|
21
|
+
min-width: 10px;
|
|
22
|
+
min-height: 30px;
|
|
23
|
+
background-color: #f5f5f5;
|
|
24
|
+
border: 1px dashed #d9d9d9;
|
|
25
|
+
}
|
|
26
|
+
.page-canvas {
|
|
27
|
+
// display: flex;
|
|
28
|
+
// flex-direction: column;
|
|
29
|
+
// gap: 16px;
|
|
30
|
+
padding: 12px;
|
|
31
|
+
padding-bottom: 24px;
|
|
32
|
+
min-width: 0;
|
|
33
|
+
max-width: 100%;
|
|
34
|
+
overflow-x: hidden;
|
|
35
|
+
user-select: none;
|
|
36
|
+
background: #ffffff;
|
|
37
|
+
|
|
38
|
+
.page-item-component.designable {
|
|
39
|
+
position: relative;
|
|
40
|
+
}
|
|
41
|
+
.page-item-component.designable:hover {
|
|
42
|
+
outline: 1px dashed #1890ff;
|
|
43
|
+
cursor: move;
|
|
44
|
+
}
|
|
45
|
+
.page-item-component.designable.ant-row {
|
|
46
|
+
padding: 6px;
|
|
47
|
+
}
|
|
48
|
+
.page-item-component.designable.selected {
|
|
49
|
+
position: relative;
|
|
50
|
+
outline: 1px solid #1890ff;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
export const PageCanvas = React.forwardRef<any, PageCanvasProps>(
|
|
56
|
+
function PageCanvas({ device = "desktop" }, ref) {
|
|
57
|
+
const { schema, forceUpdate } = useContext(DesignerContext);
|
|
58
|
+
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
59
|
+
const [canvasWidth, setCanvasWidth] = useState(0);
|
|
60
|
+
const [callbacks, setCallbacks] = useState<CallbacksType>({});
|
|
61
|
+
const [env, setEnv] = useState<EnvType>({ global: {}, local: {} });
|
|
62
|
+
|
|
63
|
+
const items = useMemo(() => schema.items || [], [schema.items]);
|
|
64
|
+
|
|
65
|
+
const [localList, setLocalList] = useState(items);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
setLocalList(schema.items || []);
|
|
69
|
+
}, [schema.items]);
|
|
70
|
+
|
|
71
|
+
const onLocalListChange = (list: any[]) => {
|
|
72
|
+
const newList = [...list];
|
|
73
|
+
schema.items = newList;
|
|
74
|
+
setLocalList(newList);
|
|
75
|
+
forceUpdate?.();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
const nextGlobal: Record<string, any> = {};
|
|
80
|
+
(schema.variables || []).forEach((item) => {
|
|
81
|
+
nextGlobal[item.name] = item.value;
|
|
82
|
+
});
|
|
83
|
+
setEnv((e) => ({ ...e, global: nextGlobal }));
|
|
84
|
+
}, [schema.variables]);
|
|
85
|
+
|
|
86
|
+
const computeCanvasWidth = () => {
|
|
87
|
+
const parent = rootRef.current?.parentElement;
|
|
88
|
+
const rect = parent?.getBoundingClientRect();
|
|
89
|
+
const width = rect?.width || 0;
|
|
90
|
+
if (width <= 100) {
|
|
91
|
+
setTimeout(computeCanvasWidth, 10);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
setCanvasWidth(width ? width - 36 : 0);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const initCallback = ({
|
|
98
|
+
id,
|
|
99
|
+
callback,
|
|
100
|
+
}: {
|
|
101
|
+
id: string;
|
|
102
|
+
callback: (v: any) => void;
|
|
103
|
+
}) => {
|
|
104
|
+
setCallbacks((c) => ({ ...c, [id]: callback }));
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
computeCanvasWidth();
|
|
109
|
+
}, [device]);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
const onResize = () => computeCanvasWidth();
|
|
113
|
+
window.addEventListener("resize", onResize);
|
|
114
|
+
return () => window.removeEventListener("resize", onResize);
|
|
115
|
+
}, []);
|
|
116
|
+
|
|
117
|
+
useImperativeHandle(ref, () => ({
|
|
118
|
+
handleResize() {
|
|
119
|
+
computeCanvasWidth();
|
|
120
|
+
},
|
|
121
|
+
get dom() {
|
|
122
|
+
return rootRef.current;
|
|
123
|
+
},
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<EnvProvider
|
|
128
|
+
deviceWidth={canvasWidth}
|
|
129
|
+
env={env}
|
|
130
|
+
callbacks={callbacks}
|
|
131
|
+
initCallback={initCallback}
|
|
132
|
+
>
|
|
133
|
+
<Wrapper ref={rootRef}>
|
|
134
|
+
<DropContainer
|
|
135
|
+
list={localList}
|
|
136
|
+
onListChange={onLocalListChange}
|
|
137
|
+
className="page-canvas"
|
|
138
|
+
/>
|
|
139
|
+
</Wrapper>
|
|
140
|
+
</EnvProvider>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
export default PageCanvas;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
2
|
+
import React, { useContext, useEffect, useState } from "react";
|
|
3
|
+
import { DesignerContext } from "../context/DesignerContext";
|
|
4
|
+
import { SchemaItemType } from "../typing";
|
|
5
|
+
|
|
6
|
+
export type PageItemProps = {
|
|
7
|
+
id?: string;
|
|
8
|
+
item: SchemaItemType;
|
|
9
|
+
onDelete?: () => void;
|
|
10
|
+
parentList?: any[];
|
|
11
|
+
onListChange?: (list: any[]) => void;
|
|
12
|
+
index?: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* PageItem 组件
|
|
17
|
+
* 用途:渲染单个页面元素,并在设计模式下支持拖拽
|
|
18
|
+
* 参数:
|
|
19
|
+
* - deviceWidth:设备宽度
|
|
20
|
+
* - item:元素数据
|
|
21
|
+
* - selectedItem:选中元素
|
|
22
|
+
* - env:环境对象
|
|
23
|
+
* - designable:是否开启设计模式
|
|
24
|
+
* - initCallback:初始化回调注册
|
|
25
|
+
* - callbacks:回调字典
|
|
26
|
+
* - onSelect:选择回调
|
|
27
|
+
* - onDelete:删除回调
|
|
28
|
+
* - parentList:所属列表引用,用于拖拽跨容器移动
|
|
29
|
+
* - index:当前元素索引
|
|
30
|
+
*/
|
|
31
|
+
export const PageItem: React.FC<PageItemProps> = ({
|
|
32
|
+
item,
|
|
33
|
+
onDelete,
|
|
34
|
+
parentList,
|
|
35
|
+
onListChange,
|
|
36
|
+
index,
|
|
37
|
+
}) => {
|
|
38
|
+
const { designable, selectedItem, setSelectedItem: onSelect, plugins } =
|
|
39
|
+
useContext(DesignerContext);
|
|
40
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
41
|
+
|
|
42
|
+
const Comp = plugins.find((p) => p.key === item.type)?.component as
|
|
43
|
+
| React.ComponentType<any>
|
|
44
|
+
| undefined;
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const updateToolbarPosition = () => {
|
|
48
|
+
if (!toolbarEl.current) return;
|
|
49
|
+
const target = document.getElementById(`page-item-${item.id}`);
|
|
50
|
+
if (!target) {
|
|
51
|
+
removeToolbar();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const rect = target.getBoundingClientRect();
|
|
55
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
56
|
+
toolbarEl.current.style.display = "none";
|
|
57
|
+
return;
|
|
58
|
+
} else {
|
|
59
|
+
toolbarEl.current.style.display = "flex";
|
|
60
|
+
}
|
|
61
|
+
const scrollTop =
|
|
62
|
+
window.pageYOffset ||
|
|
63
|
+
document.documentElement.scrollTop ||
|
|
64
|
+
document.body.scrollTop ||
|
|
65
|
+
0;
|
|
66
|
+
const scrollLeft =
|
|
67
|
+
window.pageXOffset ||
|
|
68
|
+
document.documentElement.scrollLeft ||
|
|
69
|
+
document.body.scrollLeft ||
|
|
70
|
+
0;
|
|
71
|
+
toolbarEl.current.style.top = `${rect.top + scrollTop - 22}px`;
|
|
72
|
+
toolbarEl.current.style.left = `${rect.left + scrollLeft - 1}px`;
|
|
73
|
+
};
|
|
74
|
+
const toolbarEl = { current: null as HTMLDivElement | null };
|
|
75
|
+
const removeToolbar = () => {
|
|
76
|
+
if (toolbarEl.current) {
|
|
77
|
+
const link = toolbarEl.current.querySelector("a");
|
|
78
|
+
link && link.removeEventListener("click", handleDelete);
|
|
79
|
+
if (document.body.contains(toolbarEl.current))
|
|
80
|
+
document.body.removeChild(toolbarEl.current);
|
|
81
|
+
toolbarEl.current = null;
|
|
82
|
+
window.removeEventListener("scroll", updateToolbarPosition, true);
|
|
83
|
+
window.removeEventListener("resize", updateToolbarPosition);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const handleDelete = (e: any) => {
|
|
87
|
+
e.stopPropagation();
|
|
88
|
+
if (onDelete) onDelete();
|
|
89
|
+
};
|
|
90
|
+
if (selectedItem && selectedItem === item && designable) {
|
|
91
|
+
const div = document.createElement("div");
|
|
92
|
+
div.style.position = "absolute";
|
|
93
|
+
div.style.zIndex = "9999";
|
|
94
|
+
div.style.display = "flex";
|
|
95
|
+
div.style.gap = "4px";
|
|
96
|
+
const text = document.createElement("span");
|
|
97
|
+
text.innerText = item.name || item.type + `(${item.id})`;
|
|
98
|
+
text.style.background = "#1890ff";
|
|
99
|
+
text.style.color = "#fff";
|
|
100
|
+
text.style.fontSize = "12px";
|
|
101
|
+
text.style.borderTopLeftRadius = "4px";
|
|
102
|
+
text.style.borderTopRightRadius = "4px";
|
|
103
|
+
text.style.padding = "2px 8px";
|
|
104
|
+
text.style.cursor = "pointer";
|
|
105
|
+
text.style.userSelect = "none";
|
|
106
|
+
div.appendChild(text);
|
|
107
|
+
const link = document.createElement("a");
|
|
108
|
+
link.innerText = "X";
|
|
109
|
+
link.style.background = "#1890ff";
|
|
110
|
+
link.style.color = "#fff";
|
|
111
|
+
link.style.fontSize = "12px";
|
|
112
|
+
link.style.borderTopLeftRadius = "4px";
|
|
113
|
+
link.style.borderTopRightRadius = "4px";
|
|
114
|
+
link.style.padding = "2px 8px";
|
|
115
|
+
link.style.cursor = "pointer";
|
|
116
|
+
link.style.userSelect = "none";
|
|
117
|
+
div.appendChild(link);
|
|
118
|
+
link.addEventListener("click", handleDelete);
|
|
119
|
+
document.body.appendChild(div);
|
|
120
|
+
toolbarEl.current = div;
|
|
121
|
+
updateToolbarPosition();
|
|
122
|
+
window.addEventListener("scroll", updateToolbarPosition, true);
|
|
123
|
+
window.addEventListener("resize", updateToolbarPosition);
|
|
124
|
+
return () => removeToolbar();
|
|
125
|
+
} else {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
}, [selectedItem, designable, item, onDelete]);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 注册拖拽源:仅在设计模式下启用
|
|
133
|
+
*/
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
const el = document.getElementById(`page-item-${item.id}`);
|
|
136
|
+
if (!el || !designable) return;
|
|
137
|
+
const cleanup = draggable({
|
|
138
|
+
element: el,
|
|
139
|
+
getInitialData: () => ({
|
|
140
|
+
id: item.id,
|
|
141
|
+
index,
|
|
142
|
+
list: parentList,
|
|
143
|
+
onListChange,
|
|
144
|
+
data: item,
|
|
145
|
+
}),
|
|
146
|
+
canDrag: () => !!designable,
|
|
147
|
+
onDragStart: () => {
|
|
148
|
+
setIsDragging(true);
|
|
149
|
+
},
|
|
150
|
+
onDrop: () => {
|
|
151
|
+
setIsDragging(false);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
const handleClick = (e: MouseEvent) => {
|
|
155
|
+
e.stopPropagation();
|
|
156
|
+
onSelect && onSelect(item);
|
|
157
|
+
}
|
|
158
|
+
designable && el.addEventListener("click", handleClick);
|
|
159
|
+
return () => {
|
|
160
|
+
cleanup();
|
|
161
|
+
designable && el.removeEventListener("click", handleClick);
|
|
162
|
+
}
|
|
163
|
+
}, [designable, item, index, parentList]);
|
|
164
|
+
|
|
165
|
+
if (!Comp) return null;
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<Comp
|
|
169
|
+
id={`page-item-${item.id}`}
|
|
170
|
+
data-item-id={item.id}
|
|
171
|
+
{...(item.props || {})}
|
|
172
|
+
item={item}
|
|
173
|
+
className={`page-item-component ${designable ? "designable" : ""} ${
|
|
174
|
+
selectedItem === item ? "selected" : ""
|
|
175
|
+
}`}
|
|
176
|
+
style={{
|
|
177
|
+
...(item.style || {}),
|
|
178
|
+
opacity: isDragging ? 0.5 : 1,
|
|
179
|
+
}}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import styled from "styled-components";
|
|
3
|
+
import { Tooltip, Space, Card } from "antd";
|
|
4
|
+
import { HistoryOutlined, MessageOutlined } from "@ant-design/icons";
|
|
5
|
+
import { PaneHeader } from "./PaneHeader";
|
|
6
|
+
import { ChatInput } from "./ChatInput";
|
|
7
|
+
|
|
8
|
+
export type AiPanelProps = {
|
|
9
|
+
agentList?: { id: string; name: string }[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const Root = styled.div`
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
height: 100%;
|
|
16
|
+
.body {
|
|
17
|
+
flex: 1 1 auto;
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
gap: 12px;
|
|
21
|
+
padding: 12px;
|
|
22
|
+
}
|
|
23
|
+
.conversation-list {
|
|
24
|
+
margin: 0;
|
|
25
|
+
padding: 0;
|
|
26
|
+
list-style: none;
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
gap: 4px;
|
|
30
|
+
}
|
|
31
|
+
.conversation-list li {
|
|
32
|
+
margin: 0;
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: 6px;
|
|
36
|
+
justify-content: space-between;
|
|
37
|
+
padding: 4px 8px;
|
|
38
|
+
background: var(--link-bg-color);
|
|
39
|
+
border-radius: 2px;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
font-size: 14px;
|
|
42
|
+
}
|
|
43
|
+
.conversation-list li a {
|
|
44
|
+
color: var(--ant-color-text-secondary);
|
|
45
|
+
flex: auto;
|
|
46
|
+
overflow: hidden;
|
|
47
|
+
text-overflow: ellipsis;
|
|
48
|
+
white-space: nowrap;
|
|
49
|
+
}
|
|
50
|
+
.conversation-list li small {
|
|
51
|
+
white-space: nowrap;
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
const DEFAULT_AGENT_LIST: any[] = [];
|
|
56
|
+
|
|
57
|
+
export const AiPanel: React.FC<AiPanelProps> = ({
|
|
58
|
+
agentList = DEFAULT_AGENT_LIST,
|
|
59
|
+
}) => {
|
|
60
|
+
return (
|
|
61
|
+
<Root>
|
|
62
|
+
<PaneHeader
|
|
63
|
+
title="智能助理"
|
|
64
|
+
extra={
|
|
65
|
+
<Space>
|
|
66
|
+
<Tooltip title="新对话" placement="topRight">
|
|
67
|
+
<a>
|
|
68
|
+
<MessageOutlined />
|
|
69
|
+
</a>
|
|
70
|
+
</Tooltip>
|
|
71
|
+
<Tooltip title="历史记录" placement="topRight">
|
|
72
|
+
<a>
|
|
73
|
+
<HistoryOutlined />
|
|
74
|
+
</a>
|
|
75
|
+
</Tooltip>
|
|
76
|
+
</Space>
|
|
77
|
+
}
|
|
78
|
+
/>
|
|
79
|
+
<div className="body">
|
|
80
|
+
<div style={{ flex: "1 1 auto" }} />
|
|
81
|
+
<Card
|
|
82
|
+
title="历史记录"
|
|
83
|
+
size="small"
|
|
84
|
+
variant="borderless"
|
|
85
|
+
styles={{
|
|
86
|
+
header: {
|
|
87
|
+
padding: 0,
|
|
88
|
+
border: "none",
|
|
89
|
+
},
|
|
90
|
+
body: {
|
|
91
|
+
padding: 0,
|
|
92
|
+
},
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
<ul className="conversation-list">
|
|
96
|
+
<li>
|
|
97
|
+
<a>
|
|
98
|
+
<MessageOutlined />
|
|
99
|
+
你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好
|
|
100
|
+
</a>
|
|
101
|
+
<small>刚刚</small>
|
|
102
|
+
</li>
|
|
103
|
+
<li>
|
|
104
|
+
<a>
|
|
105
|
+
<MessageOutlined />
|
|
106
|
+
你好
|
|
107
|
+
</a>
|
|
108
|
+
<small>刚刚</small>
|
|
109
|
+
</li>
|
|
110
|
+
</ul>
|
|
111
|
+
</Card>
|
|
112
|
+
<ChatInput agentList={agentList} />
|
|
113
|
+
</div>
|
|
114
|
+
</Root>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import React, { useContext, useMemo } from "react";
|
|
2
|
+
import { Dropdown, Menu, Popconfirm, Space } from "antd";
|
|
3
|
+
import {
|
|
4
|
+
PlusOutlined,
|
|
5
|
+
CaretDownOutlined,
|
|
6
|
+
DeleteOutlined,
|
|
7
|
+
} from "@ant-design/icons";
|
|
8
|
+
import { PaneHeader } from "./PaneHeader";
|
|
9
|
+
import { IconFont } from "../icon/IconFont";
|
|
10
|
+
import styled from "styled-components";
|
|
11
|
+
import { DesignerContext } from "../context/DesignerContext";
|
|
12
|
+
|
|
13
|
+
const Root = styled.div`
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
height: 100%;
|
|
17
|
+
.body {
|
|
18
|
+
flex: 1 1 auto;
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
gap: 12px;
|
|
22
|
+
padding: 12px;
|
|
23
|
+
overflow-y: auto;
|
|
24
|
+
overflow-x: hidden;
|
|
25
|
+
}
|
|
26
|
+
ul,
|
|
27
|
+
li {
|
|
28
|
+
list-style: none;
|
|
29
|
+
padding: 0;
|
|
30
|
+
margin: 0;
|
|
31
|
+
}
|
|
32
|
+
li {
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: space-between;
|
|
36
|
+
padding: 8px;
|
|
37
|
+
border-bottom: 1px dotted #d9d9d9;
|
|
38
|
+
}
|
|
39
|
+
li > div:first-child {
|
|
40
|
+
flex: 1 1 auto;
|
|
41
|
+
white-space: nowrap;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
text-overflow: ellipsis;
|
|
44
|
+
}
|
|
45
|
+
li:last-child {
|
|
46
|
+
border-bottom: none;
|
|
47
|
+
}
|
|
48
|
+
a.toolbar {
|
|
49
|
+
font-size: 16px;
|
|
50
|
+
color: var(--ant-color-text-secondary);
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
export const CascadePanel: React.FC = ({}) => {
|
|
55
|
+
const { schema, selectedItem, setSelectedItem, plugins, forceUpdate } =
|
|
56
|
+
useContext(DesignerContext);
|
|
57
|
+
const pluginMap = useMemo(() => {
|
|
58
|
+
return (plugins || []).reduce((prev: Record<string, any>, cur: any) => {
|
|
59
|
+
prev[cur.key] = cur;
|
|
60
|
+
return prev;
|
|
61
|
+
}, {});
|
|
62
|
+
}, [plugins]);
|
|
63
|
+
const items = useMemo(() => {
|
|
64
|
+
const list: any[] = [];
|
|
65
|
+
const compute = (arr?: any[]) => {
|
|
66
|
+
if (!Array.isArray(arr)) return;
|
|
67
|
+
arr.forEach((item) => {
|
|
68
|
+
list.push(item);
|
|
69
|
+
if (Array.isArray(item.children)) {
|
|
70
|
+
compute(item.children);
|
|
71
|
+
} else if (typeof item.children === "object" && item.children) {
|
|
72
|
+
Object.keys(item.children).forEach((k) => compute(item.children[k]));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
compute(schema?.items || []);
|
|
77
|
+
return list;
|
|
78
|
+
}, [schema]);
|
|
79
|
+
const itemMap = useMemo(() => {
|
|
80
|
+
return items.reduce((prev: Record<string, any>, cur: any) => {
|
|
81
|
+
if (cur.id) prev[cur.id] = cur;
|
|
82
|
+
return prev;
|
|
83
|
+
}, {});
|
|
84
|
+
}, [items]);
|
|
85
|
+
|
|
86
|
+
const onChange = (ids: string[]) => {
|
|
87
|
+
if (!selectedItem) return;
|
|
88
|
+
setSelectedItem(Object.assign(selectedItem, { cascadeIds: ids }));
|
|
89
|
+
forceUpdate();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<Root className="cascade-panel">
|
|
94
|
+
<PaneHeader
|
|
95
|
+
title="联动"
|
|
96
|
+
extra={
|
|
97
|
+
selectedItem?.cascadeIds ? (
|
|
98
|
+
<Space>
|
|
99
|
+
<Dropdown
|
|
100
|
+
menu={{
|
|
101
|
+
onClick: ({ key }) => {
|
|
102
|
+
const ids = [...(selectedItem?.cascadeIds || [])];
|
|
103
|
+
ids.push(String(key));
|
|
104
|
+
onChange && onChange(ids);
|
|
105
|
+
},
|
|
106
|
+
items: items.map((it) => ({
|
|
107
|
+
key: it.id,
|
|
108
|
+
label: (
|
|
109
|
+
<a>
|
|
110
|
+
<IconFont type={pluginMap[it.type]?.icon} />{" "}
|
|
111
|
+
{it.name || pluginMap[it.type]?.label} ({it.id})
|
|
112
|
+
</a>
|
|
113
|
+
),
|
|
114
|
+
})),
|
|
115
|
+
}}
|
|
116
|
+
placement="bottomLeft"
|
|
117
|
+
trigger={["click"]}
|
|
118
|
+
>
|
|
119
|
+
<a className="toolbar">
|
|
120
|
+
<PlusOutlined />
|
|
121
|
+
<CaretDownOutlined
|
|
122
|
+
style={{ fontSize: 8, verticalAlign: "sub" }}
|
|
123
|
+
/>
|
|
124
|
+
</a>
|
|
125
|
+
</Dropdown>
|
|
126
|
+
</Space>
|
|
127
|
+
) : null
|
|
128
|
+
}
|
|
129
|
+
/>
|
|
130
|
+
<div className="body">
|
|
131
|
+
{selectedItem?.cascadeIds && (
|
|
132
|
+
<ul>
|
|
133
|
+
{(selectedItem.cascadeIds || []).map(
|
|
134
|
+
(id: string, index: number) => (
|
|
135
|
+
<li key={id}>
|
|
136
|
+
<div>
|
|
137
|
+
<IconFont type={pluginMap[itemMap[id]?.type]?.icon} />{" "}
|
|
138
|
+
{itemMap[id]?.name || pluginMap[itemMap[id]?.type]?.label} (
|
|
139
|
+
{id})
|
|
140
|
+
</div>
|
|
141
|
+
<Popconfirm
|
|
142
|
+
title="确认删除吗?"
|
|
143
|
+
okText="确认"
|
|
144
|
+
cancelText="取消"
|
|
145
|
+
onConfirm={() => {
|
|
146
|
+
const ids = [...(selectedItem.cascadeIds || [])];
|
|
147
|
+
ids.splice(index, 1);
|
|
148
|
+
onChange && onChange(ids);
|
|
149
|
+
}}
|
|
150
|
+
>
|
|
151
|
+
<a>
|
|
152
|
+
<DeleteOutlined />
|
|
153
|
+
</a>
|
|
154
|
+
</Popconfirm>
|
|
155
|
+
</li>
|
|
156
|
+
)
|
|
157
|
+
)}
|
|
158
|
+
</ul>
|
|
159
|
+
)}
|
|
160
|
+
</div>
|
|
161
|
+
</Root>
|
|
162
|
+
);
|
|
163
|
+
};
|