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,75 @@
1
+ import { Input, type InputProps } from "antd";
2
+ import React, { useContext } from "react";
3
+ import { HtmlBaseProps, SchemaItemType } from "../../../typing";
4
+ import { EnvContext } from "../../../context/EnvContext";
5
+ import { handleCallback, setVar } from "../../../utils";
6
+
7
+ export type InputRenderProps = {
8
+ var?: string;
9
+ placeholder?: string;
10
+ prefix?: React.ReactNode | string;
11
+ suffix?: React.ReactNode | string;
12
+ size?: InputProps['size']
13
+ allowClear?: boolean;
14
+ search?: boolean;
15
+ item?: SchemaItemType;
16
+ value?: string;
17
+ onChange?: (v: string) => void;
18
+ onSearch?: (v: string) => void;
19
+ } & HtmlBaseProps;
20
+
21
+ export const InputRender: React.FC<InputRenderProps> = ({
22
+ id,
23
+ var: varName = "",
24
+ placeholder = "",
25
+ prefix,
26
+ suffix,
27
+ size,
28
+ allowClear = false,
29
+ search = false,
30
+ item,
31
+ value,
32
+ onChange,
33
+ onSearch,
34
+ style = {},
35
+ className,
36
+ }) => {
37
+ const { env, callbacks } = useContext(EnvContext);
38
+ const change = (v: string) => {
39
+ if (onChange) onChange(v);
40
+ if (env && item && varName) setVar(env, item, varName, v);
41
+ };
42
+ const searchClick = () => {
43
+ if (onSearch) onSearch(value || "");
44
+ if (env && item && callbacks) handleCallback(env, item, callbacks);
45
+ };
46
+ if (search) {
47
+ return (
48
+ <Input.Search
49
+ id={id}
50
+ value={value}
51
+ size={size}
52
+ allowClear={allowClear}
53
+ placeholder={placeholder}
54
+ onChange={(e) => change(e.target.value)}
55
+ onSearch={searchClick}
56
+ style={{ ...style }}
57
+ className={className}
58
+ />
59
+ );
60
+ }
61
+ return (
62
+ <Input
63
+ id={id}
64
+ value={value}
65
+ size={size}
66
+ allowClear={allowClear}
67
+ placeholder={placeholder}
68
+ prefix={typeof prefix === "string" ? undefined : prefix}
69
+ suffix={typeof suffix === "string" ? undefined : suffix}
70
+ onChange={(e) => change(e.target.value)}
71
+ style={{ ...style }}
72
+ className={className}
73
+ />
74
+ );
75
+ };
@@ -0,0 +1,227 @@
1
+ import React, { MouseEventHandler, useMemo } from "react";
2
+ import { Avatar, Pagination } from "antd";
3
+ import styled, { css } from "styled-components";
4
+ import { HtmlBaseProps } from "../../../typing";
5
+ import { useDatasource } from "../../../hooks/datasource";
6
+
7
+ type DataItem = {
8
+ title?: string;
9
+ description?: string;
10
+ href?: string;
11
+ avatar?: string;
12
+ };
13
+
14
+ export type ListRenderProps = {
15
+ pageSize?: number;
16
+ bordered?: boolean;
17
+ size?: "small" | "default";
18
+ item: any;
19
+ itemLayout?: "horizontal" | "vertical";
20
+ split?: boolean;
21
+ } & HtmlBaseProps;
22
+
23
+ const ListWrapper = styled.div<{
24
+ $bordered?: boolean;
25
+ $split?: boolean;
26
+ $size?: string;
27
+ $itemLayout?: string;
28
+ }>`
29
+ box-sizing: border-box;
30
+ margin: 0;
31
+ padding: 0;
32
+ color: rgba(0, 0, 0, 0.85);
33
+ font-size: 14px;
34
+ line-height: 1.5715;
35
+ list-style: none;
36
+ display: flex;
37
+ flex-direction: column;
38
+
39
+ ${(props) =>
40
+ props.$bordered &&
41
+ css`
42
+ border: 1px solid #d9d9d9;
43
+ border-radius: 2px;
44
+ `}
45
+
46
+ ${(props) =>
47
+ props.$itemLayout === "vertical" &&
48
+ css`
49
+ flex-direction: column;
50
+ `}
51
+ `;
52
+
53
+ const ListItemWrapper = styled.div<{ $split?: boolean; $padding?: string }>`
54
+ display: flex;
55
+ align-items: center;
56
+ justify-content: space-between;
57
+ padding: ${(props) => props.$padding || "12px 0"};
58
+ color: rgba(0, 0, 0, 0.85);
59
+
60
+ ${(props) =>
61
+ props.$split &&
62
+ css`
63
+ border-bottom: 1px solid #f0f0f0;
64
+ &:last-child {
65
+ border-bottom: none;
66
+ }
67
+ `}
68
+ `;
69
+
70
+ const ItemMeta = styled.div`
71
+ display: flex;
72
+ flex: 1;
73
+ align-items: flex-start;
74
+ max-width: 100%;
75
+ `;
76
+
77
+ const ItemMetaAvatar = styled.div`
78
+ margin-right: 16px;
79
+ `;
80
+
81
+ const ItemMetaContent = styled.div`
82
+ flex: 1 0;
83
+ width: 0;
84
+ color: rgba(0, 0, 0, 0.85);
85
+ `;
86
+
87
+ const ItemTitle = styled.h4`
88
+ margin-bottom: 4px;
89
+ color: rgba(0, 0, 0, 0.85);
90
+ font-size: 14px;
91
+ line-height: 1.5715;
92
+ margin-top: 0;
93
+
94
+ > a {
95
+ color: rgba(0, 0, 0, 0.85);
96
+ transition: all 0.3s;
97
+ text-decoration: none;
98
+ cursor: pointer;
99
+ &:hover {
100
+ color: #1890ff;
101
+ }
102
+ }
103
+ `;
104
+
105
+ const ItemDescription = styled.div`
106
+ color: rgba(0, 0, 0, 0.45);
107
+ font-size: 14px;
108
+ line-height: 1.5715;
109
+ `;
110
+
111
+ const PaginationWrapper = styled.div<{ $bordered?: boolean }>`
112
+ margin-top: 16px;
113
+ text-align: right;
114
+ padding: ${(props) => (props.$bordered ? "0 24px 24px" : "0")};
115
+ `;
116
+
117
+ const Item: React.FC<{
118
+ item: DataItem;
119
+ split?: boolean;
120
+ padding?: string;
121
+ }> = ({ item, split, padding }) => {
122
+ return (
123
+ <ListItemWrapper $split={split} $padding={padding}>
124
+ <ItemMeta>
125
+ {item.avatar && (
126
+ <ItemMetaAvatar>
127
+ <Avatar src={item.avatar} />
128
+ </ItemMetaAvatar>
129
+ )}
130
+ <ItemMetaContent>
131
+ {item.title && (
132
+ <ItemTitle>
133
+ {item.href ? <a href={item.href}>{item.title}</a> : item.title}
134
+ </ItemTitle>
135
+ )}
136
+ {item.description && (
137
+ <ItemDescription>{item.description}</ItemDescription>
138
+ )}
139
+ </ItemMetaContent>
140
+ </ItemMeta>
141
+ </ListItemWrapper>
142
+ );
143
+ };
144
+
145
+ const List: React.FC<
146
+ {
147
+ list: Array<DataItem>;
148
+ split?: boolean;
149
+ bordered?: boolean;
150
+ size?: string;
151
+ itemLayout?: string;
152
+ } & HtmlBaseProps
153
+ > = ({ list = [], split, bordered, size, itemLayout, style, className }) => {
154
+ const padding = useMemo(() => {
155
+ if (size === "small") return "8px 16px";
156
+ if (bordered) return "12px 24px";
157
+ return "12px 0";
158
+ }, [size, bordered]);
159
+
160
+ return (
161
+ <ListWrapper
162
+ $bordered={bordered}
163
+ $split={split}
164
+ $size={size}
165
+ style={style}
166
+ $itemLayout={itemLayout}
167
+ className={className}
168
+ >
169
+ {list.map((item, index) => (
170
+ <Item key={String(index)} item={item} split={split} padding={padding} />
171
+ ))}
172
+ </ListWrapper>
173
+ );
174
+ };
175
+
176
+ export const ListRender: React.FC<ListRenderProps> = ({
177
+ id,
178
+ pageSize = 10,
179
+ bordered = true,
180
+ size = "default",
181
+ itemLayout = "horizontal",
182
+ item,
183
+ split = true,
184
+ style = {},
185
+ className,
186
+ }) => {
187
+ const datasource = useDatasource(id, item.datasource);
188
+ const list = datasource || [];
189
+ const pagination = useMemo(() => {
190
+ if (!pageSize || pageSize <= list.length) return false;
191
+ return {
192
+ total: list.length,
193
+ pageSize,
194
+ size: size === "default" ? undefined : size,
195
+ showSizeChanger: true,
196
+ showQuickJumper: true,
197
+ hideOnSinglePage: true,
198
+ pageSizeOptions: ["10", "20", "30", "40"],
199
+ showTotal: (total: number, range: [number, number]) =>
200
+ `共 ${total} 条记录,显示第 ${range[0]}-${range[1]} 条`,
201
+ };
202
+ }, [pageSize, list.length, size]);
203
+ const classes = [
204
+ "p-list",
205
+ itemLayout ? `p-list--${itemLayout}` : undefined,
206
+ size ? `p-list--${size}` : undefined,
207
+ split ? "p-list--split" : undefined,
208
+ bordered ? "p-list--bordered" : undefined,
209
+ className,
210
+ ];
211
+ return (
212
+ <div
213
+ id={id}
214
+ style={{ display: "flex", flexDirection: "column", ...style }}
215
+ className={classes.filter(Boolean).join(" ")}
216
+ >
217
+ <List
218
+ list={list}
219
+ split={split}
220
+ bordered={bordered}
221
+ size={size}
222
+ itemLayout={itemLayout}
223
+ />
224
+ {pagination && <Pagination {...pagination} />}
225
+ </div>
226
+ );
227
+ };
@@ -0,0 +1,74 @@
1
+ import React, { useMemo, useState } from "react";
2
+ import styled from "styled-components";
3
+ import { DropContainer } from "../../../dnd/DropContainer";
4
+ import { HtmlBaseProps } from "../../../typing";
5
+
6
+ export type PageHeaderRenderProps = {
7
+ title?: string;
8
+ subTitle?: string;
9
+ item: any;
10
+ } & HtmlBaseProps;
11
+
12
+ const Header = styled.div`
13
+ width: 100%;
14
+ padding: 0 12px;
15
+ border-bottom: solid 1px #e8e8e8;
16
+ background: #ffffff;
17
+ height: 40px;
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: space-between;
21
+ .title {
22
+ display: flex;
23
+ flex-direction: column;
24
+ }
25
+ .title .main {
26
+ font-size: 14px;
27
+ }
28
+ .title .sub {
29
+ color: #999;
30
+ font-size: 12px;
31
+ }
32
+ `;
33
+
34
+ export const PageHeaderRender: React.FC<PageHeaderRenderProps> = ({
35
+ id,
36
+ title,
37
+ subTitle,
38
+ item,
39
+ style = {},
40
+ className,
41
+ }) => {
42
+ const extraSlot = useMemo(() => {
43
+ if (!item.children || Array.isArray(item.children)) return null;
44
+ if (typeof item.children !== "object") return null;
45
+ return item.children.extra || [];
46
+ }, [item]);
47
+
48
+ const [extraList, setExtraList] = useState(extraSlot || []);
49
+
50
+ const onExtraListChange = (list: any[]) => {
51
+ const newList = [...list];
52
+ item.children.extra = newList;
53
+ setExtraList(newList);
54
+ };
55
+
56
+ return (
57
+ <Header
58
+ id={id}
59
+ style={{ ...style }}
60
+ className={className}
61
+ >
62
+ <div className="title">
63
+ <span className="main">{title}</span>
64
+ {subTitle && <span className="sub">{subTitle}</span>}
65
+ </div>
66
+ <div>
67
+ <DropContainer
68
+ list={extraList}
69
+ onListChange={onExtraListChange}
70
+ />
71
+ </div>
72
+ </Header>
73
+ );
74
+ };
@@ -0,0 +1,47 @@
1
+ import { Row } from "antd";
2
+ import React, { useContext, useState } from "react";
3
+ import { DropContainer } from "../../../dnd/DropContainer";
4
+ import { HtmlBaseProps } from "../../../typing";
5
+ import { DesignerContext } from "../../../context/DesignerContext";
6
+
7
+ export type RowRenderProps = {
8
+ gutter?: number | [number, number];
9
+ item: any;
10
+ } & HtmlBaseProps;
11
+
12
+ /**
13
+ * RowRender 组件
14
+ * 翻译自 RowRender.vue
15
+ * 功能:渲染行布局,支持拖拽排序(designable模式下)
16
+ * 不使用 DragContainer 组件
17
+ */
18
+ export const RowRender: React.FC<RowRenderProps> = ({
19
+ id,
20
+ gutter,
21
+ item,
22
+ style,
23
+ className,
24
+ }) => {
25
+ const { designable } = useContext(DesignerContext);
26
+ const [localChildren, setLocalChildren] = useState(item.children || []);
27
+
28
+ const onLocalChildrenChange = (list: any[]) => {
29
+ item.children = list;
30
+ setLocalChildren(list);
31
+ };
32
+
33
+ return (
34
+ <DropContainer
35
+ rootComponent={Row}
36
+ rootData={{
37
+ id,
38
+ gutter,
39
+ style: item.style || style,
40
+ className: item.className || className,
41
+ }}
42
+ list={localChildren}
43
+ item={item}
44
+ onListChange={onLocalChildrenChange}
45
+ />
46
+ );
47
+ };
@@ -0,0 +1,53 @@
1
+ import { Select, type SelectProps } from "antd";
2
+ import React, { useContext } from "react";
3
+ import { HtmlBaseProps, SchemaItemType } from "../../../typing";
4
+ import { EnvContext } from "../../../context/EnvContext";
5
+ import { handleCallback, setVar } from "../../../utils";
6
+
7
+ export type SelectRenderProps = {
8
+ var?: string;
9
+ size?: SelectProps['size'];
10
+ placeholder?: string;
11
+ allowClear?: boolean;
12
+ multiple?: boolean;
13
+ options?: { label: string; value: any }[];
14
+ item?: SchemaItemType;
15
+ value?: any;
16
+ onChange?: (v: any) => void;
17
+ } & HtmlBaseProps;
18
+
19
+ export const SelectRender: React.FC<SelectRenderProps> = ({
20
+ id,
21
+ var: varName = "",
22
+ size,
23
+ placeholder = "请选择",
24
+ allowClear = false,
25
+ multiple = false,
26
+ options = [],
27
+ item,
28
+ value,
29
+ onChange,
30
+ style = {},
31
+ className,
32
+ }) => {
33
+ const { env, callbacks } = useContext(EnvContext);
34
+ const change = (v: any) => {
35
+ if (onChange) onChange(v);
36
+ if (env && item && varName) setVar(env, item, varName, v);
37
+ if (env && item && callbacks) handleCallback(env, item, callbacks);
38
+ };
39
+ return (
40
+ <Select
41
+ id={id}
42
+ value={value}
43
+ size={size}
44
+ placeholder={placeholder}
45
+ allowClear={allowClear}
46
+ mode={multiple ? "multiple" : undefined}
47
+ options={options}
48
+ onChange={change}
49
+ style={{ width: "100%", ...style }}
50
+ className={className}
51
+ />
52
+ );
53
+ };
@@ -0,0 +1,54 @@
1
+ import { Space } from "antd";
2
+ import React, { useContext, useMemo, useState } from "react";
3
+ import { DropContainer } from "../../../dnd/DropContainer";
4
+ import { HtmlBaseProps } from "../../../typing";
5
+ import { DesignerContext } from "../../../context/DesignerContext";
6
+ import { type SizeType } from "antd/es/config-provider/SizeContext";
7
+
8
+ export type SpaceRenderProps = {
9
+ align?: "start" | "end" | "center" | "baseline";
10
+ size?: SizeType;
11
+ direction?: "horizontal" | "vertical";
12
+ item: any;
13
+ } & HtmlBaseProps;
14
+
15
+ export const SpaceRender: React.FC<SpaceRenderProps> = ({
16
+ id,
17
+ align = "start",
18
+ size = "small",
19
+ direction = "horizontal",
20
+ item,
21
+ style = {},
22
+ className,
23
+ }) => {
24
+ const { designable } = useContext(DesignerContext);
25
+ const [localChildren, setLocalChildren] = useState(item.children || []);
26
+
27
+ const onLocalChildrenChange = (list: any[]) => {
28
+ item.children = list;
29
+ setLocalChildren(list);
30
+ };
31
+ const realStyle = useMemo(
32
+ () => ({
33
+ ...style,
34
+ ...(item.style || {}),
35
+ alignItems: align,
36
+ flexDirection: direction,
37
+ gap: size,
38
+ }),
39
+ [item, align, size, direction]
40
+ );
41
+ return (
42
+ <DropContainer
43
+ rootComponent={Space}
44
+ rootData={{
45
+ id,
46
+ style: realStyle,
47
+ className,
48
+ }}
49
+ list={localChildren}
50
+ item={item}
51
+ onListChange={onLocalChildrenChange}
52
+ />
53
+ );
54
+ };
@@ -0,0 +1,52 @@
1
+ import { Switch, type SwitchProps } from "antd";
2
+ import React, { useContext } from "react";
3
+ import { HtmlBaseProps, SchemaItemType } from "../../../typing";
4
+ import { EnvContext } from "../../../context/EnvContext";
5
+ import { handleCallback, setVar } from "../../../utils";
6
+
7
+ export type SwitchRenderProps = {
8
+ var?: string;
9
+ checked?: boolean;
10
+ disabled?: boolean;
11
+ size?: SwitchProps["size"];
12
+ checkedChildren?: string;
13
+ unCheckedChildren?: string;
14
+ item?: SchemaItemType;
15
+ onChange?: (checked: boolean) => void;
16
+ } & HtmlBaseProps;
17
+
18
+ export const SwitchRender: React.FC<SwitchRenderProps> = ({
19
+ id,
20
+ var: varName = "",
21
+ checked,
22
+ disabled,
23
+ size = "default",
24
+ checkedChildren,
25
+ unCheckedChildren,
26
+ item,
27
+ onChange,
28
+ style = {},
29
+ className,
30
+ }) => {
31
+ const { env, callbacks } = useContext(EnvContext);
32
+ const change = (v: boolean) => {
33
+ if (onChange) onChange(v);
34
+ if (env && item && varName) setVar(env, item, varName, v);
35
+ if (env && item && callbacks) handleCallback(env, item, callbacks);
36
+ };
37
+ return (
38
+ <span>
39
+ <Switch
40
+ id={id}
41
+ checked={checked}
42
+ disabled={disabled}
43
+ size={size === "small" ? "small" : undefined}
44
+ checkedChildren={checkedChildren}
45
+ unCheckedChildren={unCheckedChildren}
46
+ onChange={(v) => change(v)}
47
+ style={style}
48
+ className={className}
49
+ />
50
+ </span>
51
+ );
52
+ };
@@ -0,0 +1,99 @@
1
+ import React from "react";
2
+ import { Table, type TableProps } from "antd";
3
+ import { HtmlBaseProps } from "../../../typing";
4
+
5
+ export type TableRenderProps = {
6
+ dataSource?: any[];
7
+ columns?: any[];
8
+ pageSize?: number;
9
+ bordered?: boolean;
10
+ size?: TableProps["size"];
11
+ showHeader?: boolean;
12
+ } & HtmlBaseProps;
13
+
14
+ export const TableRender: React.FC<TableRenderProps> = ({
15
+ id,
16
+ dataSource = [],
17
+ columns = [],
18
+ pageSize = 10,
19
+ bordered = true,
20
+ size,
21
+ showHeader = true,
22
+ style = {},
23
+ className,
24
+ }) => {
25
+ const pagination =
26
+ !pageSize || pageSize <= dataSource.length
27
+ ? false
28
+ : {
29
+ total: dataSource.length,
30
+ pageSize,
31
+ size,
32
+ showSizeChanger: true,
33
+ showQuickJumper: true,
34
+ hideOnSinglePage: true,
35
+ pageSizeOptions: ["10", "20", "30", "40"],
36
+ showTotal: (total: number, range: [number, number]) =>
37
+ `共 ${total} 条记录,显示第 ${range[0]}-${range[1]} 条`,
38
+ };
39
+ const realColumns = columns.map((item: any) => ({
40
+ ...item,
41
+ render:
42
+ !item.customRender ||
43
+ (typeof item.customRender === "string" && item.customRender.trim() === "")
44
+ ? item.render
45
+ : (text: any, record: any, index: number) => {
46
+ const safeEval = new Function(
47
+ "console",
48
+ "Math",
49
+ "Date",
50
+ "Array",
51
+ "Object",
52
+ "String",
53
+ "Number",
54
+ "Boolean",
55
+ "text",
56
+ "record",
57
+ "index",
58
+ `
59
+ "use strict";
60
+ const window = undefined;
61
+ const document = undefined;
62
+ const global = undefined;
63
+ const process = undefined;
64
+ const require = undefined;
65
+ const module = undefined;
66
+ const exports = undefined;
67
+ ${item.customRender}
68
+ `
69
+ );
70
+ return (safeEval as any)(
71
+ console,
72
+ Math,
73
+ Date,
74
+ Array,
75
+ Object,
76
+ String,
77
+ Number,
78
+ Boolean,
79
+ text,
80
+ record,
81
+ index
82
+ );
83
+ },
84
+ }));
85
+ return (
86
+ <Table
87
+ id={id}
88
+ dataSource={dataSource}
89
+ columns={realColumns as any}
90
+ pagination={pagination as any}
91
+ bordered={bordered}
92
+ size={size}
93
+ showHeader={typeof showHeader === "boolean" ? showHeader : true}
94
+ rowKey={(_, index) => String(index)}
95
+ style={{ padding: 1, ...style }}
96
+ className={className}
97
+ />
98
+ );
99
+ };
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import { HtmlBaseProps } from "../../../typing";
3
+
4
+ export type TextRenderProps = {
5
+ text?: string;
6
+ item?: { style?: React.CSSProperties };
7
+ } & HtmlBaseProps;
8
+
9
+ export const TextRender: React.FC<TextRenderProps> = ({
10
+ id,
11
+ text,
12
+ item,
13
+ style = {},
14
+ className,
15
+ }) => {
16
+ return (
17
+ <span
18
+ id={id}
19
+ style={{ ...(item?.style || {}), ...style }}
20
+ className={className}
21
+ >
22
+ {text}
23
+ </span>
24
+ );
25
+ };